[CMAKE] Disable --compress-debug-sections on GCC >= 7.0
[reactos.git] / sdk / cmake / gcc.cmake
1
2 # Show a note about ccache build
3 if(ENABLE_CCACHE)
4 message("-- Enabling ccache build - done")
5 set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
6 set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
7 endif()
8
9 # PDB style debug info
10 if(NOT DEFINED SEPARATE_DBG)
11 set(SEPARATE_DBG FALSE)
12 endif()
13
14 # Dwarf based builds (no rsym)
15 if(CMAKE_BUILD_TYPE STREQUAL "Release")
16 set(NO_ROSSYM TRUE)
17 elseif(NOT DEFINED NO_ROSSYM)
18 set(NO_ROSSYM FALSE)
19 endif()
20
21 if(NOT DEFINED USE_PSEH3)
22 set(USE_PSEH3 1)
23 endif()
24
25 if(USE_PSEH3)
26 add_definitions(-D_USE_PSEH3=1)
27 endif()
28
29 if(NOT DEFINED USE_DUMMY_PSEH)
30 set(USE_DUMMY_PSEH 0)
31 endif()
32
33 if(USE_DUMMY_PSEH)
34 add_definitions(-D_USE_DUMMY_PSEH=1)
35 endif()
36
37 if(STACK_PROTECTOR)
38 add_compile_flags(${MODULE} "-fstack-protector-all")
39 endif()
40
41 # Compiler Core
42 add_compile_flags("-pipe -fms-extensions -fno-strict-aliasing")
43
44 # Prevent GCC from searching any of the default directories
45 add_compile_flags("-nostdinc")
46
47 if(GCC_VERSION VERSION_GREATER 4.7)
48 add_compile_flags("-mstackrealign")
49 endif()
50 if(NOT GCC_VERSION VERSION_LESS 4.8)
51 add_compile_flags("-fno-aggressive-loop-optimizations")
52 endif()
53
54 if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
55 add_compile_flags_language("-std=gnu89 -Wno-microsoft" "C")
56 set(CMAKE_LINK_DEF_FILE_FLAG "")
57 set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
58 set(CMAKE_LINK_LIBRARY_SUFFIX "")
59 set(CMAKE_CREATE_WIN32_EXE "")
60 set(CMAKE_C_COMPILE_OPTIONS_PIC "")
61 set(CMAKE_CXX_COMPILE_OPTIONS_PIC "")
62 set(CMAKE_C_COMPILE_OPTIONS_PIE "")
63 set(CMAKE_CXX_COMPILE_OPTIONS_PIE "")
64 set(CMAKE_ASM_FLAGS_DEBUG "")
65 set(CMAKE_C_FLAGS_DEBUG "")
66 set(CMAKE_CXX_FLAGS_DEBUG "")
67 endif()
68
69 if(DBG)
70 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
71 add_compile_flags_language("-Wold-style-declaration" "C")
72 endif()
73 add_compile_flags_language("-Wdeclaration-after-statement" "C")
74 endif()
75
76 add_compile_flags_language("-fno-rtti -fno-exceptions" "CXX")
77
78 #bug
79 #file(TO_NATIVE_PATH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_NATIVE)
80 #workaround
81 set(REACTOS_SOURCE_DIR_NATIVE ${REACTOS_SOURCE_DIR})
82 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
83 string(REPLACE "/" "\\" REACTOS_SOURCE_DIR_NATIVE ${REACTOS_SOURCE_DIR})
84 endif()
85
86 if((NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (NOT SEPARATE_DBG))
87 add_compile_flags("-fdebug-prefix-map=\"${REACTOS_SOURCE_DIR_NATIVE}\"=ReactOS")
88 endif()
89
90 # Debugging
91 if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
92 if(SEPARATE_DBG)
93 add_compile_flags("-gdwarf-2 -ggdb")
94 else()
95 add_compile_flags("-gdwarf-2 -gstrict-dwarf")
96 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
97 add_compile_flags("-femit-struct-debug-detailed=none -feliminate-unused-debug-symbols")
98 endif()
99 endif()
100 endif()
101
102 # Tuning
103 if(ARCH STREQUAL "i386")
104 add_compile_flags("-march=${OARCH} -mtune=${TUNE}")
105 else()
106 add_compile_flags("-march=${OARCH}")
107 endif()
108
109 # Warnings, errors
110 if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang"))
111 add_compile_flags("-Werror")
112 endif()
113
114 add_compile_flags("-Wall -Wpointer-arith")
115 add_compile_flags("-Wno-char-subscripts -Wno-multichar -Wno-unused-value")
116
117 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
118 add_compile_flags("-Wno-maybe-uninitialized")
119 endif()
120
121 if(ARCH STREQUAL "amd64")
122 add_compile_flags("-Wno-format")
123 elseif(ARCH STREQUAL "arm")
124 add_compile_flags("-Wno-attributes")
125 endif()
126
127 # Optimizations
128 # FIXME: Revisit this to see if we even need these levels
129 if(CMAKE_BUILD_TYPE STREQUAL "Release")
130 add_compile_flags("-O2 -DNDEBUG")
131 else()
132 if(OPTIMIZE STREQUAL "1")
133 add_compile_flags("-Os -ftracer")
134 elseif(OPTIMIZE STREQUAL "2")
135 add_compile_flags("-Os")
136 elseif(OPTIMIZE STREQUAL "3")
137 add_compile_flags("-Og")
138 elseif(OPTIMIZE STREQUAL "4")
139 add_compile_flags("-O1")
140 elseif(OPTIMIZE STREQUAL "5")
141 add_compile_flags("-O2")
142 elseif(OPTIMIZE STREQUAL "6")
143 add_compile_flags("-O3")
144 elseif(OPTIMIZE STREQUAL "7")
145 add_compile_flags("-Ofast")
146 endif()
147 endif()
148
149 # Link-time code generation
150 if(LTCG)
151 add_compile_flags("-flto -fno-fat-lto-objects")
152 endif()
153
154 if(ARCH STREQUAL "i386")
155 add_compile_flags("-fno-optimize-sibling-calls -fno-omit-frame-pointer")
156 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
157 add_compile_flags("-mpreferred-stack-boundary=3 -fno-set-stack-executable")
158 endif()
159 # FIXME: this doesn't work. CMAKE_BUILD_TYPE is always "Debug"
160 if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
161 add_compile_flags("-momit-leaf-frame-pointer")
162 endif()
163 elseif(ARCH STREQUAL "amd64")
164 add_compile_flags("-mpreferred-stack-boundary=4")
165 endif()
166
167 # Other
168 if(ARCH STREQUAL "amd64")
169 add_definitions(-U_X86_ -UWIN32)
170 elseif(ARCH STREQUAL "arm")
171 add_definitions(-U_UNICODE -UUNICODE)
172 add_definitions(-D__MSVCRT__) # DUBIOUS
173 endif()
174
175 add_definitions(-D_inline=__inline)
176
177 # Alternative arch name
178 if(ARCH STREQUAL "amd64")
179 set(ARCH2 x86_64)
180 else()
181 set(ARCH2 ${ARCH})
182 endif()
183
184 if(SEPARATE_DBG)
185 # PDB style debug puts all dwarf debug info in a separate dbg file
186 message(STATUS "Building separate debug symbols")
187 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/symbols)
188 if(CMAKE_GENERATOR STREQUAL "Ninja")
189 set(CMAKE_DEBUG_SYMBOL_SUFFIX "")
190 set(SYMBOL_FILE <TARGET_PDB>)
191 else()
192 set(SYMBOL_FILE <TARGET>)
193 endif()
194 set(OBJCOPY ${CMAKE_OBJCOPY})
195 set(CMAKE_C_LINK_EXECUTABLE
196 "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
197 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
198 "${OBJCOPY} --strip-debug <TARGET>")
199 set(CMAKE_CXX_LINK_EXECUTABLE
200 "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
201 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
202 "${OBJCOPY} --strip-debug <TARGET>")
203 set(CMAKE_C_CREATE_SHARED_LIBRARY
204 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
205 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
206 "${OBJCOPY} --strip-debug <TARGET>")
207 set(CMAKE_CXX_CREATE_SHARED_LIBRARY
208 "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
209 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
210 "${OBJCOPY} --strip-debug <TARGET>")
211 set(CMAKE_RC_CREATE_SHARED_LIBRARY
212 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
213 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
214 "${OBJCOPY} --strip-debug <TARGET>")
215 elseif(NO_ROSSYM)
216 # Dwarf-based build
217 message(STATUS "Generating a dwarf-based build (no rsym)")
218 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
219 set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
220 set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
221 set(CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
222 set(CMAKE_RC_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
223 else()
224 # Normal rsym build
225 if(NEW_STYLE_BUILD)
226 string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
227 get_target_property(RSYM native-rsym IMPORTED_LOCATION_${_build_type})
228 else()
229 get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG)
230 endif()
231
232 set(CMAKE_C_LINK_EXECUTABLE
233 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
234 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
235 set(CMAKE_CXX_LINK_EXECUTABLE
236 "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
237 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
238 set(CMAKE_C_CREATE_SHARED_LIBRARY
239 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
240 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
241 set(CMAKE_CXX_CREATE_SHARED_LIBRARY
242 "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
243 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
244 set(CMAKE_RC_CREATE_SHARED_LIBRARY
245 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
246 endif()
247
248 set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
249 set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
250 set(CMAKE_RC_CREATE_SHARED_MODULE ${CMAKE_RC_CREATE_SHARED_LIBRARY})
251
252 set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import,--disable-stdcall-fixup")
253 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
254 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
255
256 if((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND
257 (NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND
258 (NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0))
259 # FIXME: Set this once Clang toolchain works with it
260 set(_compress_debug_sections_flag "-Wa,--compress-debug-sections")
261 endif()
262
263 if(CMAKE_VERSION VERSION_LESS 3.4.0)
264 set(CMAKE_C_COMPILE_OBJECT "${CCACHE} <CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <FLAGS> -o <OBJECT> -c <SOURCE>")
265 # FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
266 set(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} <CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
267 set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> ${_compress_debug_sections_flag} -x assembler-with-cpp -o <OBJECT> -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm <FLAGS> <DEFINES> -D__ASM__ -c <SOURCE>")
268
269 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <FLAGS> -DRC_INVOKED -D__WIN32__=1 -D__FLAT__=1 ${I18N_DEFS} <DEFINES> <SOURCE> <OBJECT>")
270 else()
271 set(CMAKE_C_COMPILE_OBJECT "${CCACHE} <CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
272 # FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
273 set(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} <CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
274 set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> ${_compress_debug_sections_flag} -x assembler-with-cpp -o <OBJECT> -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm <INCLUDES> <FLAGS> <DEFINES> -D__ASM__ -c <SOURCE>")
275
276 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <INCLUDES> <FLAGS> -DRC_INVOKED -D__WIN32__=1 -D__FLAT__=1 ${I18N_DEFS} <DEFINES> <SOURCE> <OBJECT>")
277 endif()
278 set(CMAKE_DEPFILE_FLAGS_RC "--preprocessor \"${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX} -E -xc-header -MMD -MF <DEPFILE> -MT <OBJECT>\" ")
279
280 # Optional 3rd parameter: stdcall stack bytes
281 function(set_entrypoint MODULE ENTRYPOINT)
282 if(${ENTRYPOINT} STREQUAL "0")
283 add_target_link_flags(${MODULE} "-Wl,-entry,0")
284 elseif(ARCH STREQUAL "i386")
285 set(_entrysymbol _${ENTRYPOINT})
286 if(${ARGC} GREATER 2)
287 set(_entrysymbol ${_entrysymbol}@${ARGV2})
288 endif()
289 add_target_link_flags(${MODULE} "-Wl,-entry,${_entrysymbol}")
290 else()
291 add_target_link_flags(${MODULE} "-Wl,-entry,${ENTRYPOINT}")
292 endif()
293 endfunction()
294
295 function(set_subsystem MODULE SUBSYSTEM)
296 add_target_link_flags(${MODULE} "-Wl,--subsystem,${SUBSYSTEM}:5.01")
297 endfunction()
298
299 function(set_image_base MODULE IMAGE_BASE)
300 add_target_link_flags(${MODULE} "-Wl,--image-base,${IMAGE_BASE}")
301 endfunction()
302
303 function(set_module_type_toolchain MODULE TYPE)
304 if(CPP_USE_STL)
305 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
306 message(FATAL_ERROR "Use of STL in kernelmodedriver or wdmdriver type module prohibited")
307 endif()
308 target_link_libraries(${MODULE} -lstdc++ -lsupc++ -lgcc -lmingwex)
309 elseif(CPP_USE_RT)
310 target_link_libraries(${MODULE} -lsupc++ -lgcc)
311 elseif(IS_CPP)
312 target_link_libraries(${MODULE} -lgcc)
313 endif()
314
315 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
316 add_target_link_flags(${MODULE} "-Wl,--exclude-all-symbols,-file-alignment=0x1000,-section-alignment=0x1000")
317 if(${TYPE} STREQUAL "wdmdriver")
318 add_target_link_flags(${MODULE} "-Wl,--wdmdriver")
319 endif()
320 endif()
321
322 if(STACK_PROTECTOR)
323 target_link_libraries(${MODULE} gcc_ssp)
324 endif()
325 endfunction()
326
327 function(add_delay_importlibs _module)
328 get_target_property(_module_type ${_module} TYPE)
329 if(_module_type STREQUAL "STATIC_LIBRARY")
330 message(FATAL_ERROR "Cannot add delay imports to a static library")
331 endif()
332 foreach(_lib ${ARGN})
333 get_filename_component(_basename "${_lib}" NAME_WE)
334 target_link_libraries(${_module} lib${_basename}_delayed)
335 endforeach()
336 target_link_libraries(${_module} delayimp)
337 endfunction()
338
339 if(NOT ARCH STREQUAL "i386")
340 set(DECO_OPTION "-@")
341 endif()
342
343 function(generate_import_lib _libname _dllname _spec_file)
344 # Generate the def for the import lib
345 add_custom_command(
346 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
347 COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
348 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
349 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
350
351 # Create normal importlib
352 _add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
353 set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
354
355 # Create delayed importlib
356 _add_library(${_libname}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
357 set_target_properties(${_libname}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB_DELAYED" PREFIX "")
358 endfunction()
359
360 # Cute little hack to produce import libs
361 set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-lib=<TARGET>")
362 set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-delaylib=<TARGET>")
363 function(spec2def _dllname _spec_file)
364
365 cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
366
367 # Get library basename
368 get_filename_component(_file ${_dllname} NAME_WE)
369
370 # Error out on anything else than spec
371 if(NOT ${_spec_file} MATCHES ".*\\.spec")
372 message(FATAL_ERROR "spec2def only takes spec files as input.")
373 endif()
374
375 if (__spec2def_WITH_RELAY)
376 set(__with_relay_arg "--with-tracing")
377 endif()
378
379 if(__spec2def_VERSION)
380 set(__version_arg "--version=0x${__spec2def_VERSION}")
381 endif()
382
383 # Generate exports def and C stubs file for the DLL
384 add_custom_command(
385 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
386 COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${__with_relay_arg} ${__version_arg} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
387 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
388
389 if(__spec2def_ADD_IMPORTLIB)
390 set(_extraflags)
391 if(__spec2def_NO_PRIVATE_WARNINGS)
392 set(_extraflags --no-private-warnings)
393 endif()
394
395 generate_import_lib(lib${_file} ${_dllname} ${_spec_file} ${_extraflags})
396 endif()
397 endfunction()
398
399 macro(macro_mc FLAG FILE)
400 set(COMMAND_MC ${CMAKE_MC_COMPILER} -u ${FLAG} -b -h ${CMAKE_CURRENT_BINARY_DIR}/ -r ${CMAKE_CURRENT_BINARY_DIR}/ ${FILE})
401 endmacro()
402
403 # PSEH lib, needed with mingw
404 set(PSEH_LIB "pseh")
405
406 # Macros
407 if(PCH AND (NOT ENABLE_CCACHE) AND (NOT CMAKE_HOST_APPLE))
408 add_compile_flags("-Winvalid-pch -Werror=invalid-pch")
409 macro(add_pch _target _pch _sources)
410 # When including x.h GCC looks for x.h.gch first
411 set(_pch_final_name "${_target}_pch.h")
412 set(_gch ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}.gch)
413
414 if(IS_CPP)
415 set(_pch_language CXX)
416 else()
417 set(_pch_language C)
418 endif()
419
420 # Build the precompiled header
421 # HEADER_FILE_ONLY FALSE: force compiling the header
422 # EXTERNAL_SOURCE TRUE: don't use the .gch file when linking
423 set_source_files_properties(${_pch} PROPERTIES
424 HEADER_FILE_ONLY FALSE
425 LANGUAGE ${_pch_language}
426 EXTERNAL_SOURCE TRUE
427 OBJECT_LOCATION ${_gch})
428
429 # Include the gch in the specified source files, skipping the pch file itself
430 list(REMOVE_ITEM ${_sources} ${_pch})
431 foreach(_src ${${_sources}})
432 set_property(SOURCE ${_src} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_ccache_flag} -include ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}")
433 set_property(SOURCE ${_src} APPEND PROPERTY OBJECT_DEPENDS ${_gch})
434 endforeach()
435 endmacro()
436 else()
437 macro(add_pch _target _pch _sources)
438 endmacro()
439 endif()
440
441 function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_address)
442 set(_object_file ${_binary_file}.o)
443
444 add_custom_command(
445 OUTPUT ${_object_file}
446 COMMAND ${CMAKE_ASM_COMPILER} -x assembler-with-cpp -o ${_object_file} -I${REACTOS_SOURCE_DIR}/sdk/include/asm -I${REACTOS_BINARY_DIR}/sdk/include/asm -I${REACTOS_SOURCE_DIR}/boot/freeldr -D__ASM__ -c ${_asm_file}
447 DEPENDS ${_asm_file})
448
449 add_custom_command(
450 OUTPUT ${_binary_file}
451 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
452 # COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
453 DEPENDS ${_object_file} native-obj2bin)
454
455 set_source_files_properties(${_object_file} ${_binary_file} PROPERTIES GENERATED TRUE)
456
457 add_custom_target(${_target_name} ALL DEPENDS ${_binary_file})
458 endfunction()
459
460 function(allow_warnings __module)
461 # We don't allow warnings in trunk, this needs to be reworked. See CORE-6959.
462 #add_target_compile_flags(${__module} "-Wno-error")
463 endfunction()
464
465 macro(add_asm_files _target)
466 list(APPEND ${_target} ${ARGN})
467 endmacro()
468
469 function(add_linker_script _target _linker_script_file)
470 get_filename_component(_file_full_path ${_linker_script_file} ABSOLUTE)
471 add_target_link_flags(${_target} "-Wl,-T,${_file_full_path}")
472 add_target_property(${_target} LINK_DEPENDS ${_file_full_path})
473 endfunction()