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