41d6a721cb17c5a71d8ccf2b87bb49022cdaf790
[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(SYMBOL_FILE <TARGET_PDB>)
194 else()
195 set(SYMBOL_FILE <TARGET>.gdb)
196 endif()
197 set(OBJCOPY ${CMAKE_OBJCOPY})
198 set(CMAKE_C_LINK_EXECUTABLE
199 "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
200 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
201 "${OBJCOPY} --strip-debug <TARGET>")
202 set(CMAKE_CXX_LINK_EXECUTABLE
203 "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
204 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
205 "${OBJCOPY} --strip-debug <TARGET>")
206 set(CMAKE_C_CREATE_SHARED_LIBRARY
207 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
208 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
209 "${OBJCOPY} --strip-debug <TARGET>")
210 set(CMAKE_CXX_CREATE_SHARED_LIBRARY
211 "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
212 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
213 "${OBJCOPY} --strip-debug <TARGET>")
214 set(CMAKE_RC_CREATE_SHARED_LIBRARY
215 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
216 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
217 "${OBJCOPY} --strip-debug <TARGET>")
218 elseif(NO_ROSSYM)
219 # Dwarf-based build
220 message(STATUS "Generating a dwarf-based build (no rsym)")
221 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
222 set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
223 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>")
224 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>")
225 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>")
226 else()
227 # Normal rsym build
228 if(NEW_STYLE_BUILD)
229 string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
230 get_target_property(RSYM native-rsym IMPORTED_LOCATION_${_build_type})
231 else()
232 get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG)
233 endif()
234
235 set(CMAKE_C_LINK_EXECUTABLE
236 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
237 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
238 set(CMAKE_CXX_LINK_EXECUTABLE
239 "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
240 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
241 set(CMAKE_C_CREATE_SHARED_LIBRARY
242 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
243 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
244 set(CMAKE_CXX_CREATE_SHARED_LIBRARY
245 "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
246 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
247 set(CMAKE_RC_CREATE_SHARED_LIBRARY
248 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
249 endif()
250
251 set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import,--disable-stdcall-fixup")
252 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
253
254 if((NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Release"))
255 # FIXME: Set this once Clang toolchain works with it
256 set(_compress_debug_sections_flag "-Wa,--compress-debug-sections")
257 endif()
258
259 if(CMAKE_VERSION VERSION_LESS 3.4.0)
260 set(CMAKE_C_COMPILE_OBJECT "${CCACHE} <CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <FLAGS> -o <OBJECT> -c <SOURCE>")
261 # FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
262 set(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} <CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
263 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>")
264
265 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <FLAGS> -DRC_INVOKED -D__WIN32__=1 -D__FLAT__=1 ${I18N_DEFS} <DEFINES> <SOURCE> <OBJECT>")
266 else()
267 set(CMAKE_C_COMPILE_OBJECT "${CCACHE} <CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
268 # FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
269 set(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} <CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
270 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>")
271
272 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>")
273 endif()
274 set(CMAKE_DEPFILE_FLAGS_RC "--preprocessor \"${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX} -E -xc-header -MMD -MF <DEPFILE> -MT <OBJECT>\" ")
275
276 # Optional 3rd parameter: stdcall stack bytes
277 function(set_entrypoint MODULE ENTRYPOINT)
278 if(${ENTRYPOINT} STREQUAL "0")
279 add_target_link_flags(${MODULE} "-Wl,-entry,0")
280 elseif(ARCH STREQUAL "i386")
281 set(_entrysymbol _${ENTRYPOINT})
282 if(${ARGC} GREATER 2)
283 set(_entrysymbol ${_entrysymbol}@${ARGV2})
284 endif()
285 add_target_link_flags(${MODULE} "-Wl,-entry,${_entrysymbol}")
286 else()
287 add_target_link_flags(${MODULE} "-Wl,-entry,${ENTRYPOINT}")
288 endif()
289 endfunction()
290
291 function(set_subsystem MODULE SUBSYSTEM)
292 add_target_link_flags(${MODULE} "-Wl,--subsystem,${SUBSYSTEM}:5.01")
293 endfunction()
294
295 function(set_image_base MODULE IMAGE_BASE)
296 add_target_link_flags(${MODULE} "-Wl,--image-base,${IMAGE_BASE}")
297 endfunction()
298
299 function(set_module_type_toolchain MODULE TYPE)
300 if(CPP_USE_STL)
301 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
302 message(FATAL_ERROR "Use of STL in kernelmodedriver or wdmdriver type module prohibited")
303 endif()
304 target_link_libraries(${MODULE} -lstdc++ -lsupc++ -lgcc -lmingwex)
305 elseif(CPP_USE_RT)
306 target_link_libraries(${MODULE} -lsupc++ -lgcc)
307 elseif(IS_CPP)
308 target_link_libraries(${MODULE} -lgcc)
309 endif()
310
311 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
312 add_target_link_flags(${MODULE} "-Wl,--exclude-all-symbols,-file-alignment=0x1000,-section-alignment=0x1000")
313 if(${TYPE} STREQUAL "wdmdriver")
314 add_target_link_flags(${MODULE} "-Wl,--wdmdriver")
315 endif()
316 endif()
317
318 if(STACK_PROTECTOR)
319 target_link_libraries(${MODULE} gcc_ssp)
320 endif()
321 endfunction()
322
323 function(add_delay_importlibs _module)
324 get_target_property(_module_type ${_module} TYPE)
325 if(_module_type STREQUAL "STATIC_LIBRARY")
326 message(FATAL_ERROR "Cannot add delay imports to a static library")
327 endif()
328 foreach(_lib ${ARGN})
329 target_link_libraries(${_module} lib${_lib}_delayed)
330 endforeach()
331 target_link_libraries(${_module} delayimp)
332 endfunction()
333
334 if(NOT ARCH STREQUAL "i386")
335 set(DECO_OPTION "-@")
336 endif()
337
338 function(generate_import_lib _libname _dllname _spec_file)
339 # Generate the def for the import lib
340 add_custom_command(
341 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
342 COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
343 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
344 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
345
346 # Create normal importlib
347 _add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
348 set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
349
350 # Create delayed importlib
351 _add_library(${_libname}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
352 set_target_properties(${_libname}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB_DELAYED" PREFIX "")
353 endfunction()
354
355 # Cute little hack to produce import libs
356 set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-lib=<TARGET>")
357 set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-delaylib=<TARGET>")
358 function(spec2def _dllname _spec_file)
359
360 cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "" "" ${ARGN})
361
362 # Get library basename
363 get_filename_component(_file ${_dllname} NAME_WE)
364
365 # Error out on anything else than spec
366 if(NOT ${_spec_file} MATCHES ".*\\.spec")
367 message(FATAL_ERROR "spec2def only takes spec files as input.")
368 endif()
369
370 if (__spec2def_WITH_RELAY)
371 set(__with_relay_arg "--with-tracing")
372 endif()
373
374 # Generate exports def and C stubs file for the DLL
375 add_custom_command(
376 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
377 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} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
378 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
379
380 if(__spec2def_ADD_IMPORTLIB)
381 set(_extraflags)
382 if(__spec2def_NO_PRIVATE_WARNINGS)
383 set(_extraflags --no-private-warnings)
384 endif()
385
386 generate_import_lib(lib${_file} ${_dllname} ${_spec_file} ${_extraflags})
387 endif()
388 endfunction()
389
390 macro(macro_mc FLAG FILE)
391 set(COMMAND_MC ${CMAKE_MC_COMPILER} -u ${FLAG} -b -h ${CMAKE_CURRENT_BINARY_DIR}/ -r ${CMAKE_CURRENT_BINARY_DIR}/ ${FILE})
392 endmacro()
393
394 # PSEH lib, needed with mingw
395 set(PSEH_LIB "pseh")
396
397 # Macros
398 if(PCH AND (NOT ENABLE_CCACHE) AND (NOT CMAKE_HOST_APPLE))
399 add_compile_flags("-Winvalid-pch -Werror=invalid-pch")
400 macro(add_pch _target _pch _sources)
401 # When including x.h GCC looks for x.h.gch first
402 set(_pch_final_name "${_target}_pch.h")
403 set(_gch ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}.gch)
404
405 if(IS_CPP)
406 set(_pch_language CXX)
407 else()
408 set(_pch_language C)
409 endif()
410
411 # Build the precompiled header
412 # HEADER_FILE_ONLY FALSE: force compiling the header
413 # EXTERNAL_SOURCE TRUE: don't use the .gch file when linking
414 set_source_files_properties(${_pch} PROPERTIES
415 HEADER_FILE_ONLY FALSE
416 LANGUAGE ${_pch_language}
417 EXTERNAL_SOURCE TRUE
418 OBJECT_LOCATION ${_gch})
419
420 # Include the gch in the specified source files, skipping the pch file itself
421 list(REMOVE_ITEM ${_sources} ${_pch})
422 foreach(_src ${${_sources}})
423 set_property(SOURCE ${_src} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_ccache_flag} -include ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}")
424 set_property(SOURCE ${_src} APPEND PROPERTY OBJECT_DEPENDS ${_gch})
425 endforeach()
426 endmacro()
427 else()
428 macro(add_pch _target _pch _sources)
429 endmacro()
430 endif()
431
432 function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_address)
433 set(_object_file ${_binary_file}.o)
434
435 add_custom_command(
436 OUTPUT ${_object_file}
437 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}
438 DEPENDS ${_asm_file})
439
440 add_custom_command(
441 OUTPUT ${_binary_file}
442 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
443 # COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
444 DEPENDS ${_object_file} native-obj2bin)
445
446 set_source_files_properties(${_object_file} ${_binary_file} PROPERTIES GENERATED TRUE)
447
448 add_custom_target(${_target_name} ALL DEPENDS ${_binary_file})
449
450 endfunction()
451
452 function(allow_warnings __module)
453 # We don't allow warnings in trunk, this needs to be reworked. See CORE-6959.
454 #add_target_compile_flags(${__module} "-Wno-error")
455 endfunction()
456
457 macro(add_asm_files _target)
458 list(APPEND ${_target} ${ARGN})
459 endmacro()