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