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