Rework host tools
[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 add_compile_flags("-Wno-unused-const-variable")
117 add_compile_flags("-Wno-unused-local-typedefs")
118 add_compile_flags("-Wno-deprecated")
119
120 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
121 add_compile_flags("-Wno-maybe-uninitialized")
122 endif()
123
124 if(ARCH STREQUAL "amd64")
125 add_compile_flags("-Wno-format")
126 elseif(ARCH STREQUAL "arm")
127 add_compile_flags("-Wno-attributes")
128 endif()
129
130 # Optimizations
131 # FIXME: Revisit this to see if we even need these levels
132 if(CMAKE_BUILD_TYPE STREQUAL "Release")
133 add_compile_flags("-O2 -DNDEBUG")
134 else()
135 if(OPTIMIZE STREQUAL "1")
136 add_compile_flags("-Os -ftracer")
137 elseif(OPTIMIZE STREQUAL "2")
138 add_compile_flags("-Os")
139 elseif(OPTIMIZE STREQUAL "3")
140 add_compile_flags("-Og")
141 elseif(OPTIMIZE STREQUAL "4")
142 add_compile_flags("-O1")
143 elseif(OPTIMIZE STREQUAL "5")
144 add_compile_flags("-O2")
145 elseif(OPTIMIZE STREQUAL "6")
146 add_compile_flags("-O3")
147 elseif(OPTIMIZE STREQUAL "7")
148 add_compile_flags("-Ofast")
149 endif()
150 endif()
151
152 # Link-time code generation
153 if(LTCG)
154 add_compile_flags("-flto -fno-fat-lto-objects")
155 endif()
156
157 if(ARCH STREQUAL "i386")
158 add_compile_flags("-fno-optimize-sibling-calls -fno-omit-frame-pointer")
159 if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
160 add_compile_flags("-mpreferred-stack-boundary=3 -fno-set-stack-executable")
161 endif()
162 # FIXME: this doesn't work. CMAKE_BUILD_TYPE is always "Debug"
163 if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
164 add_compile_flags("-momit-leaf-frame-pointer")
165 endif()
166 elseif(ARCH STREQUAL "amd64")
167 add_compile_flags("-mpreferred-stack-boundary=4")
168 endif()
169
170 # Other
171 if(ARCH STREQUAL "amd64")
172 add_definitions(-U_X86_ -UWIN32)
173 elseif(ARCH STREQUAL "arm")
174 add_definitions(-U_UNICODE -UUNICODE)
175 add_definitions(-D__MSVCRT__) # DUBIOUS
176 endif()
177
178 add_definitions(-D_inline=__inline)
179
180 # Fix build with GLIBCXX + our c++ headers
181 add_definitions(-D_GLIBCXX_HAVE_BROKEN_VSWPRINTF)
182
183 # Alternative arch name
184 if(ARCH STREQUAL "amd64")
185 set(ARCH2 x86_64)
186 else()
187 set(ARCH2 ${ARCH})
188 endif()
189
190 if(SEPARATE_DBG)
191 # PDB style debug puts all dwarf debug info in a separate dbg file
192 message(STATUS "Building separate debug symbols")
193 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/symbols)
194 if(CMAKE_GENERATOR STREQUAL "Ninja")
195 set(CMAKE_DEBUG_SYMBOL_SUFFIX "")
196 set(SYMBOL_FILE <TARGET_PDB>)
197 else()
198 set(SYMBOL_FILE <TARGET>)
199 endif()
200 set(OBJCOPY ${CMAKE_OBJCOPY})
201 set(CMAKE_C_LINK_EXECUTABLE
202 "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
203 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
204 "${OBJCOPY} --strip-debug <TARGET>")
205 set(CMAKE_CXX_LINK_EXECUTABLE
206 "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
207 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
208 "${OBJCOPY} --strip-debug <TARGET>")
209 set(CMAKE_C_CREATE_SHARED_LIBRARY
210 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
211 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
212 "${OBJCOPY} --strip-debug <TARGET>")
213 set(CMAKE_CXX_CREATE_SHARED_LIBRARY
214 "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
215 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
216 "${OBJCOPY} --strip-debug <TARGET>")
217 set(CMAKE_RC_CREATE_SHARED_LIBRARY
218 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
219 "${OBJCOPY} --only-keep-debug <TARGET> ${REACTOS_BINARY_DIR}/symbols/${SYMBOL_FILE}"
220 "${OBJCOPY} --strip-debug <TARGET>")
221 elseif(NO_ROSSYM)
222 # Dwarf-based build
223 message(STATUS "Generating a dwarf-based build (no rsym)")
224 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
225 set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
226 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>")
227 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>")
228 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>")
229 else()
230 # Normal rsym build
231 get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG)
232
233 set(CMAKE_C_LINK_EXECUTABLE
234 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
235 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
236 set(CMAKE_CXX_LINK_EXECUTABLE
237 "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
238 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
239 set(CMAKE_C_CREATE_SHARED_LIBRARY
240 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
241 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
242 set(CMAKE_CXX_CREATE_SHARED_LIBRARY
243 "<CMAKE_CXX_COMPILER> ${CMAKE_CXX_FLAGS} <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
244 "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
245 set(CMAKE_RC_CREATE_SHARED_LIBRARY
246 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
247 endif()
248
249 set(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
250 set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
251 set(CMAKE_RC_CREATE_SHARED_MODULE ${CMAKE_RC_CREATE_SHARED_LIBRARY})
252
253 set(CMAKE_EXE_LINKER_FLAGS "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import,--disable-stdcall-fixup")
254 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
255 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
256
257 if((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND
258 (NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND
259 (NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0))
260 # FIXME: Set this once Clang toolchain works with it
261 set(_compress_debug_sections_flag "-Wa,--compress-debug-sections")
262 endif()
263
264 if(CMAKE_VERSION VERSION_LESS 3.4.0)
265 set(CMAKE_C_COMPILE_OBJECT "${CCACHE} <CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <FLAGS> -o <OBJECT> -c <SOURCE>")
266 # FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
267 set(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} <CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
268 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>")
269
270 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <FLAGS> -DRC_INVOKED -D__WIN32__=1 -D__FLAT__=1 ${I18N_DEFS} <DEFINES> <SOURCE> <OBJECT>")
271 else()
272 set(CMAKE_C_COMPILE_OBJECT "${CCACHE} <CMAKE_C_COMPILER> <DEFINES> ${_compress_debug_sections_flag} <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
273 # FIXME: Once the GCC toolchain bugs are fixed, add _compress_debug_sections_flag to CXX too
274 set(CMAKE_CXX_COMPILE_OBJECT "${CCACHE} <CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
275 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>")
276
277 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>")
278 endif()
279 set(CMAKE_DEPFILE_FLAGS_RC "--preprocessor \"${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX} -E -xc-header -MMD -MF <DEPFILE> -MT <OBJECT>\" ")
280
281 # Optional 3rd parameter: stdcall stack bytes
282 function(set_entrypoint MODULE ENTRYPOINT)
283 if(${ENTRYPOINT} STREQUAL "0")
284 add_target_link_flags(${MODULE} "-Wl,-entry,0")
285 elseif(ARCH STREQUAL "i386")
286 set(_entrysymbol _${ENTRYPOINT})
287 if(${ARGC} GREATER 2)
288 set(_entrysymbol ${_entrysymbol}@${ARGV2})
289 endif()
290 add_target_link_flags(${MODULE} "-Wl,-entry,${_entrysymbol}")
291 else()
292 add_target_link_flags(${MODULE} "-Wl,-entry,${ENTRYPOINT}")
293 endif()
294 endfunction()
295
296 function(set_subsystem MODULE SUBSYSTEM)
297 add_target_link_flags(${MODULE} "-Wl,--subsystem,${SUBSYSTEM}:5.01")
298 endfunction()
299
300 function(set_image_base MODULE IMAGE_BASE)
301 add_target_link_flags(${MODULE} "-Wl,--image-base,${IMAGE_BASE}")
302 endfunction()
303
304 function(set_module_type_toolchain MODULE TYPE)
305 if(CPP_USE_STL)
306 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
307 message(FATAL_ERROR "Use of STL in kernelmodedriver or wdmdriver type module prohibited")
308 endif()
309 target_link_libraries(${MODULE} -lstdc++ -lsupc++ -lgcc -lmingwex)
310 elseif(CPP_USE_RT)
311 target_link_libraries(${MODULE} -lsupc++ -lgcc)
312 elseif(IS_CPP)
313 target_link_libraries(${MODULE} -lgcc)
314 endif()
315
316 if((${TYPE} STREQUAL "kernelmodedriver") OR (${TYPE} STREQUAL "wdmdriver"))
317 add_target_link_flags(${MODULE} "-Wl,--exclude-all-symbols,-file-alignment=0x1000,-section-alignment=0x1000")
318 if(${TYPE} STREQUAL "wdmdriver")
319 add_target_link_flags(${MODULE} "-Wl,--wdmdriver")
320 endif()
321 #Disabled due to LD bug: ROSBE-154
322 #add_linker_script(${MODULE} ${REACTOS_SOURCE_DIR}/sdk/cmake/init-section.lds)
323 endif()
324
325 if(STACK_PROTECTOR)
326 target_link_libraries(${MODULE} gcc_ssp)
327 endif()
328 endfunction()
329
330 function(add_delay_importlibs _module)
331 get_target_property(_module_type ${_module} TYPE)
332 if(_module_type STREQUAL "STATIC_LIBRARY")
333 message(FATAL_ERROR "Cannot add delay imports to a static library")
334 endif()
335 foreach(_lib ${ARGN})
336 get_filename_component(_basename "${_lib}" NAME_WE)
337 target_link_libraries(${_module} lib${_basename}_delayed)
338 endforeach()
339 target_link_libraries(${_module} delayimp)
340 endfunction()
341
342 if(NOT ARCH STREQUAL "i386")
343 set(DECO_OPTION "-@")
344 endif()
345
346 function(generate_import_lib _libname _dllname _spec_file)
347 # Generate the def for the import lib
348 add_custom_command(
349 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
350 COMMAND native-spec2def -n=${_dllname} -a=${ARCH2} ${ARGN} --implib -d=${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}
351 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
352 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def PROPERTIES EXTERNAL_OBJECT TRUE)
353
354 # Create normal importlib
355 _add_library(${_libname} STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
356 set_target_properties(${_libname} PROPERTIES LINKER_LANGUAGE "IMPLIB" PREFIX "")
357
358 # Create delayed importlib
359 _add_library(${_libname}_delayed STATIC EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def)
360 set_target_properties(${_libname}_delayed PROPERTIES LINKER_LANGUAGE "IMPLIB_DELAYED" PREFIX "")
361 endfunction()
362
363 # Cute little hack to produce import libs
364 set(CMAKE_IMPLIB_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-lib=<TARGET>")
365 set(CMAKE_IMPLIB_DELAYED_CREATE_STATIC_LIBRARY "${CMAKE_DLLTOOL} --def <OBJECTS> --kill-at --output-delaylib=<TARGET>")
366 function(spec2def _dllname _spec_file)
367
368 cmake_parse_arguments(__spec2def "ADD_IMPORTLIB;NO_PRIVATE_WARNINGS;WITH_RELAY" "VERSION" "" ${ARGN})
369
370 # Get library basename
371 get_filename_component(_file ${_dllname} NAME_WE)
372
373 # Error out on anything else than spec
374 if(NOT ${_spec_file} MATCHES ".*\\.spec")
375 message(FATAL_ERROR "spec2def only takes spec files as input.")
376 endif()
377
378 if (__spec2def_WITH_RELAY)
379 set(__with_relay_arg "--with-tracing")
380 endif()
381
382 if(__spec2def_VERSION)
383 set(__version_arg "--version=0x${__spec2def_VERSION}")
384 endif()
385
386 # Generate exports def and C stubs file for the DLL
387 add_custom_command(
388 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c
389 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}
390 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
391
392 if(__spec2def_ADD_IMPORTLIB)
393 set(_extraflags)
394 if(__spec2def_NO_PRIVATE_WARNINGS)
395 set(_extraflags --no-private-warnings)
396 endif()
397
398 generate_import_lib(lib${_file} ${_dllname} ${_spec_file} ${_extraflags})
399 endif()
400 endfunction()
401
402 macro(macro_mc FLAG FILE)
403 set(COMMAND_MC ${CMAKE_MC_COMPILER} -u ${FLAG} -b -h ${CMAKE_CURRENT_BINARY_DIR}/ -r ${CMAKE_CURRENT_BINARY_DIR}/ ${FILE})
404 endmacro()
405
406 # PSEH lib, needed with mingw
407 set(PSEH_LIB "pseh")
408
409 # Macros
410 if(PCH AND (NOT ENABLE_CCACHE) AND (NOT CMAKE_HOST_APPLE))
411 add_compile_flags("-Winvalid-pch -Werror=invalid-pch")
412 macro(add_pch _target _pch _sources)
413 # When including x.h GCC looks for x.h.gch first
414 set(_pch_final_name "${_target}_pch.h")
415 set(_gch ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}.gch)
416
417 if(IS_CPP)
418 set(_pch_language CXX)
419 else()
420 set(_pch_language C)
421 endif()
422
423 # Build the precompiled header
424 # HEADER_FILE_ONLY FALSE: force compiling the header
425 # EXTERNAL_SOURCE TRUE: don't use the .gch file when linking
426 set_source_files_properties(${_pch} PROPERTIES
427 HEADER_FILE_ONLY FALSE
428 LANGUAGE ${_pch_language}
429 EXTERNAL_SOURCE TRUE
430 OBJECT_LOCATION ${_gch})
431
432 # Include the gch in the specified source files, skipping the pch file itself
433 list(REMOVE_ITEM ${_sources} ${_pch})
434 foreach(_src ${${_sources}})
435 set_property(SOURCE ${_src} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_ccache_flag} -include ${CMAKE_CURRENT_BINARY_DIR}/${_pch_final_name}")
436 set_property(SOURCE ${_src} APPEND PROPERTY OBJECT_DEPENDS ${_gch})
437 endforeach()
438 endmacro()
439 else()
440 macro(add_pch _target _pch _sources)
441 endmacro()
442 endif()
443
444 function(CreateBootSectorTarget _target_name _asm_file _binary_file _base_address)
445 set(_object_file ${_binary_file}.o)
446
447 add_custom_command(
448 OUTPUT ${_object_file}
449 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}
450 DEPENDS ${_asm_file})
451
452 add_custom_command(
453 OUTPUT ${_binary_file}
454 COMMAND native-obj2bin ${_object_file} ${_binary_file} ${_base_address}
455 # COMMAND objcopy --output-target binary --image-base 0x${_base_address} ${_object_file} ${_binary_file}
456 DEPENDS ${_object_file} native-obj2bin)
457
458 set_source_files_properties(${_object_file} ${_binary_file} PROPERTIES GENERATED TRUE)
459
460 add_custom_target(${_target_name} ALL DEPENDS ${_binary_file})
461 endfunction()
462
463 function(allow_warnings __module)
464 # We don't allow warnings in trunk, this needs to be reworked. See CORE-6959.
465 #add_target_compile_flags(${__module} "-Wno-error")
466 endfunction()
467
468 macro(add_asm_files _target)
469 list(APPEND ${_target} ${ARGN})
470 endmacro()
471
472 function(add_linker_script _target _linker_script_file)
473 get_filename_component(_file_full_path ${_linker_script_file} ABSOLUTE)
474 add_target_link_flags(${_target} "-Wl,-T,${_file_full_path}")
475 add_target_property(${_target} LINK_DEPENDS ${_file_full_path})
476 endfunction()