e86b63952993f1171826f7c6862db1b5194c9dfa
[reactos.git] / sdk / cmake / CMakeMacros.cmake
1
2 # set_cpp
3 # Marks the current folder as containing C++ modules, additionally enabling
4 # specific C++ language features as specified (all of these default to off):
5 #
6 # WITH_RUNTIME
7 # Links with the C++ runtime. Enable this for modules which use new/delete or
8 # RTTI, but do not require STL. This is the right choice if you see undefined
9 # references to operator new/delete, vector constructor/destructor iterator,
10 # type_info::vtable, ...
11 # Note: this only affects linking, so cannot be used for static libraries.
12 # WITH_RTTI
13 # Enables run-time type information. Enable this if the module uses typeid or
14 # dynamic_cast. You will probably need to enable WITH_RUNTIME as well, if
15 # you're not already using STL.
16 # WITH_EXCEPTIONS
17 # Enables C++ exception handling. Enable this if the module uses try/catch or
18 # throw. You might also need this if you use a standard operator new (the one
19 # without nothrow).
20 # WITH_STL
21 # Enables standard C++ headers and links to the Standard Template Library.
22 # Use this for modules using anything from the std:: namespace, e.g. maps,
23 # strings, vectors, etc.
24 # Note: this affects both compiling (via include directories) and
25 # linking (by adding STL). Implies WITH_RUNTIME.
26 # FIXME: WITH_STL is currently also required for runtime headers such as
27 # <new> and <exception>. This is not a big issue because in stl-less
28 # environments you usually don't want those anyway; but we might want
29 # to have modules like this in the future.
30 #
31 # Examples:
32 # set_cpp()
33 # Enables the C++ language, but will cause errors if any runtime or standard
34 # library features are used. This should be the default for C++ in kernel
35 # mode or otherwise restricted environments.
36 # Note: this is required to get libgcc (for multiplication/division) linked
37 # in for C++ modules, and to set the correct language for precompiled
38 # header files, so it IS required even with no features specified.
39 # set_cpp(WITH_RUNTIME)
40 # Links with the C++ runtime, so that e.g. custom operator new implementations
41 # can be used in a restricted environment. This is also required for linking
42 # with libraries (such as ATL) which have RTTI enabled, even if the module in
43 # question does not use WITH_RTTI.
44 # set_cpp(WITH_RTTI WITH_EXCEPTIONS WITH_STL)
45 # The full package. This will adjust compiler and linker so that all C++
46 # features can be used.
47 macro(set_cpp)
48 cmake_parse_arguments(__cppopts "WITH_RUNTIME;WITH_RTTI;WITH_EXCEPTIONS;WITH_STL" "" "" ${ARGN})
49 if(__cppopts_UNPARSED_ARGUMENTS)
50 message(FATAL_ERROR "set_cpp: unparsed arguments ${__cppopts_UNPARSED_ARGUMENTS}")
51 endif()
52
53 if(__cppopts_WITH_RUNTIME)
54 set(CPP_USE_RT 1)
55 endif()
56 if(__cppopts_WITH_RTTI)
57 if(MSVC)
58 replace_compile_flags("/GR-" "/GR")
59 else()
60 replace_compile_flags_language("-fno-rtti" "-frtti" "CXX")
61 endif()
62 endif()
63 if(__cppopts_WITH_EXCEPTIONS)
64 if(MSVC)
65 replace_compile_flags("/EHs-c-" "/EHsc")
66 else()
67 replace_compile_flags_language("-fno-exceptions" "-fexceptions" "CXX")
68 endif()
69 endif()
70 if(__cppopts_WITH_STL)
71 set(CPP_USE_STL 1)
72 if(MSVC)
73 add_definitions(-DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/sdk/include/c++)
74 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/c++/stlport)
75 else()
76 replace_compile_flags("-nostdinc" " ")
77 endif()
78 endif()
79
80 set(IS_CPP 1)
81 endmacro()
82
83 function(add_dependency_node _node)
84 if(GENERATE_DEPENDENCY_GRAPH)
85 get_target_property(_type ${_node} TYPE)
86 if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl)
87 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
88 endif()
89 endif()
90 endfunction()
91
92 function(add_dependency_edge _source _target)
93 if(GENERATE_DEPENDENCY_GRAPH)
94 get_target_property(_type ${_source} TYPE)
95 if(_type MATCHES SHARED_LIBRARY)
96 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
97 endif()
98 endif()
99 endfunction()
100
101 function(add_dependency_header)
102 file(WRITE ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
103 endfunction()
104
105 function(add_dependency_footer)
106 add_dependency_node(ntdll)
107 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
108 endfunction()
109
110 function(add_message_headers _type)
111 if(${_type} STREQUAL UNICODE)
112 set(_flag "-U")
113 else()
114 set(_flag "-A")
115 endif()
116 foreach(_file ${ARGN})
117 get_filename_component(_file_name ${_file} NAME_WE)
118 set(_converted_file ${CMAKE_CURRENT_BINARY_DIR}/${_file}) ## ${_file_name}.mc
119 set(_source_file ${CMAKE_CURRENT_SOURCE_DIR}/${_file}) ## ${_file_name}.mc
120 add_custom_command(
121 OUTPUT "${_converted_file}"
122 COMMAND native-utf16le "${_source_file}" "${_converted_file}" nobom
123 DEPENDS native-utf16le "${_source_file}")
124 macro_mc(${_flag} ${_converted_file})
125 add_custom_command(
126 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.rc
127 COMMAND ${COMMAND_MC}
128 DEPENDS "${_converted_file}")
129 set_source_files_properties(
130 ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.rc
131 PROPERTIES GENERATED TRUE)
132 add_custom_target(${_file_name} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.rc)
133 endforeach()
134 endfunction()
135
136 function(add_link)
137 cmake_parse_arguments(_LINK "MINIMIZE" "NAME;PATH;CMD_LINE_ARGS;ICON;GUID" "" ${ARGN})
138 if(NOT _LINK_NAME OR NOT _LINK_PATH)
139 message(FATAL_ERROR "You must provide name and path")
140 endif()
141
142 if(_LINK_CMD_LINE_ARGS)
143 set(_LINK_CMD_LINE_ARGS -c ${_LINK_CMD_LINE_ARGS})
144 endif()
145
146 if(_LINK_ICON)
147 set(_LINK_ICON -i ${_LINK_ICON})
148 endif()
149
150 if(_LINK_GUID)
151 set(_LINK_GUID -g ${_LINK_GUID})
152 endif()
153
154 if(_LINK_MINIMIZE)
155 set(_LINK_MINIMIZE "-m")
156 endif()
157
158 add_custom_command(
159 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk
160 COMMAND native-mkshelllink -o ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk ${_LINK_CMD_LINE_ARGS} ${_LINK_ICON} ${_LINK_GUID} ${_LINK_MINIMIZE} ${_LINK_PATH}
161 DEPENDS native-mkshelllink)
162 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk PROPERTIES GENERATED TRUE)
163 endfunction()
164
165 #
166 # WARNING!
167 # Please keep the numbering in this list in sync with
168 # boot/bootdata/packages/reactos.dff.in
169 #
170 macro(dir_to_num dir var)
171 if(${dir} STREQUAL reactos)
172 set(${var} 1)
173 elseif(${dir} STREQUAL reactos/system32)
174 set(${var} 2)
175 elseif(${dir} STREQUAL reactos/system32/drivers)
176 set(${var} 3)
177 elseif(${dir} STREQUAL reactos/Fonts)
178 set(${var} 4)
179 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
180 set(${var} 5)
181 elseif(${dir} STREQUAL reactos/inf)
182 set(${var} 6)
183 elseif(${dir} STREQUAL reactos/bin)
184 set(${var} 7)
185 elseif(${dir} STREQUAL reactos/bin/testdata)
186 set(${var} 8)
187 elseif(${dir} STREQUAL reactos/bin/suppl)
188 set(${var} 80)
189 elseif(${dir} STREQUAL reactos/media)
190 set(${var} 9)
191 elseif(${dir} STREQUAL reactos/Microsoft.NET)
192 set(${var} 10)
193 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
194 set(${var} 11)
195 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
196 set(${var} 12)
197 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
198 set(${var} 13)
199 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
200 set(${var} 14)
201 elseif(${dir} STREQUAL reactos/Resources)
202 set(${var} 15)
203 elseif(${dir} STREQUAL reactos/Resources/Themes)
204 set(${var} 16)
205 elseif(${dir} STREQUAL reactos/system32/wbem)
206 set(${var} 17)
207 elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
208 set(${var} 18)
209 elseif(${dir} STREQUAL reactos/Help)
210 set(${var} 19)
211 elseif(${dir} STREQUAL reactos/Config)
212 set(${var} 20)
213 elseif(${dir} STREQUAL reactos/Cursors)
214 set(${var} 21)
215 elseif(${dir} STREQUAL reactos/system32/ShellExt)
216 set(${var} 22)
217 elseif(${dir} STREQUAL reactos/Temp)
218 set(${var} 23)
219 elseif(${dir} STREQUAL reactos/system32/spool)
220 set(${var} 24)
221 elseif(${dir} STREQUAL reactos/system32/spool/drivers)
222 set(${var} 25)
223 elseif(${dir} STREQUAL reactos/system32/spool/drivers/color)
224 set(${var} 26)
225 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86)
226 set(${var} 27)
227 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86/3)
228 set(${var} 28)
229 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs)
230 set(${var} 29)
231 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs/w32x86)
232 set(${var} 30)
233 elseif(${dir} STREQUAL reactos/system32/spool/PRINTERS)
234 set(${var} 31)
235 elseif(${dir} STREQUAL reactos/system32/wbem/Repository)
236 set(${var} 32)
237 elseif(${dir} STREQUAL reactos/system32/wbem/Repository/FS)
238 set(${var} 33)
239 elseif(${dir} STREQUAL reactos/system32/wbem/mof/good)
240 set(${var} 34)
241 elseif(${dir} STREQUAL reactos/system32/wbem/mof/bad)
242 set(${var} 35)
243 elseif(${dir} STREQUAL reactos/system32/wbem/AdStatus)
244 set(${var} 36)
245 elseif(${dir} STREQUAL reactos/system32/wbem/xml)
246 set(${var} 37)
247 elseif(${dir} STREQUAL reactos/system32/wbem/Logs)
248 set(${var} 38)
249 elseif(${dir} STREQUAL reactos/system32/wbem/AutoRecover)
250 set(${var} 39)
251 elseif(${dir} STREQUAL reactos/system32/wbem/snmp)
252 set(${var} 40)
253 elseif(${dir} STREQUAL reactos/system32/wbem/Performance)
254 set(${var} 41)
255 elseif(${dir} STREQUAL reactos/twain_32)
256 set(${var} 42)
257 elseif(${dir} STREQUAL reactos/repair)
258 set(${var} 43)
259 elseif(${dir} STREQUAL reactos/Web)
260 set(${var} 44)
261 elseif(${dir} STREQUAL reactos/Web/Wallpaper)
262 set(${var} 45)
263 elseif(${dir} STREQUAL reactos/Prefetch)
264 set(${var} 46)
265 elseif(${dir} STREQUAL reactos/security)
266 set(${var} 47)
267 elseif(${dir} STREQUAL reactos/security/Database)
268 set(${var} 48)
269 elseif(${dir} STREQUAL reactos/security/logs)
270 set(${var} 49)
271 elseif(${dir} STREQUAL reactos/security/templates)
272 set(${var} 50)
273 elseif(${dir} STREQUAL reactos/system32/CatRoot)
274 set(${var} 51)
275 elseif(${dir} STREQUAL reactos/system32/CatRoot2)
276 set(${var} 52)
277 elseif(${dir} STREQUAL reactos/AppPatch)
278 set(${var} 53)
279 elseif(${dir} STREQUAL reactos/winsxs)
280 set(${var} 54)
281 elseif(${dir} STREQUAL reactos/winsxs/manifests)
282 set(${var} 55)
283 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.2600.2982_none_deadbeef)
284 set(${var} 56)
285 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef)
286 set(${var} 57)
287 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.23038_none_deadbeef)
288 set(${var} 58)
289 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.apisets_6595b64144ccf1df_1.0.0.0_none_deadbeef)
290 set(${var} 59)
291 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.newapi_6595b64144ccf1df_1.0.0.0_none_deadbeef)
292 set(${var} 60)
293 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.14393.0_none_deadbeef)
294 set(${var} 61)
295 elseif(${dir} STREQUAL reactos/Resources/Themes/Modern)
296 set(${var} 62)
297 else()
298 message(FATAL_ERROR "Wrong destination: ${dir}")
299 endif()
300 endmacro()
301
302 function(add_cd_file)
303 cmake_parse_arguments(_CD "NO_CAB;NOT_IN_HYBRIDCD" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
304 if(NOT (_CD_TARGET OR _CD_FILE))
305 message(FATAL_ERROR "You must provide a target or a file to install!")
306 endif()
307
308 if(NOT _CD_DESTINATION)
309 message(FATAL_ERROR "You must provide a destination")
310 elseif(${_CD_DESTINATION} STREQUAL root)
311 set(_CD_DESTINATION "")
312 endif()
313
314 if(NOT _CD_FOR)
315 message(FATAL_ERROR "You must provide a cd name (or \"all\" for all of them) to install the file on!")
316 endif()
317
318 # get file if we need to
319 if(NOT _CD_FILE)
320 set(_CD_FILE "$<TARGET_FILE:${_CD_TARGET}>")
321 if(NOT _CD_NAME_ON_CD)
322 set(_CD_NAME_ON_CD "$<TARGET_FILE_NAME:${_CD_TARGET}>")
323 endif()
324 endif()
325
326 # do we add it to all CDs?
327 list(FIND _CD_FOR all __cd)
328 if(NOT __cd EQUAL -1)
329 list(REMOVE_AT _CD_FOR __cd)
330 list(INSERT _CD_FOR __cd "bootcd;livecd;regtest")
331 endif()
332
333 # do we add it to bootcd?
334 list(FIND _CD_FOR bootcd __cd)
335 if(NOT __cd EQUAL -1)
336 # whether or not we should put it in reactos.cab or directly on cd
337 if(_CD_NO_CAB)
338 # directly on cd
339 foreach(item ${_CD_FILE})
340 if(_CD_NAME_ON_CD)
341 # rename it in the cd tree
342 set(__file ${_CD_NAME_ON_CD})
343 else()
344 get_filename_component(__file ${item} NAME)
345 endif()
346 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
347 # add it also into the hybridcd if not specified otherwise
348 if(NOT _CD_NOT_IN_HYBRIDCD)
349 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "bootcd/${_CD_DESTINATION}/${__file}=${item}")
350 endif()
351 endforeach()
352 # manage dependency
353 if(_CD_TARGET)
354 add_dependencies(bootcd ${_CD_TARGET} registry_inf)
355 endif()
356 else()
357 # add it in reactos.cab
358 dir_to_num(${_CD_DESTINATION} _num)
359 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.cmake "\"${_CD_FILE}\" ${_num}\n")
360 # manage dependency - target level
361 if(_CD_TARGET)
362 add_dependencies(reactos_cab_inf ${_CD_TARGET})
363 endif()
364 # manage dependency - file level
365 set_property(GLOBAL APPEND PROPERTY REACTOS_CAB_DEPENDS ${_CD_FILE})
366 endif()
367 endif() #end bootcd
368
369 # do we add it to livecd?
370 list(FIND _CD_FOR livecd __cd)
371 if(NOT __cd EQUAL -1)
372 # manage dependency
373 if(_CD_TARGET)
374 add_dependencies(livecd ${_CD_TARGET} registry_inf)
375 endif()
376 foreach(item ${_CD_FILE})
377 if(_CD_NAME_ON_CD)
378 # rename it in the cd tree
379 set(__file ${_CD_NAME_ON_CD})
380 else()
381 get_filename_component(__file ${item} NAME)
382 endif()
383 set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
384 # add it also into the hybridcd if not specified otherwise
385 if(NOT _CD_NOT_IN_HYBRIDCD)
386 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "livecd/${_CD_DESTINATION}/${__file}=${item}")
387 endif()
388 endforeach()
389 endif() #end livecd
390
391 # do we need also to add it to hybridcd?
392 list(FIND _CD_FOR hybridcd __cd)
393 if(NOT __cd EQUAL -1)
394 # manage dependency
395 if(_CD_TARGET)
396 add_dependencies(hybridcd ${_CD_TARGET})
397 endif()
398 foreach(item ${_CD_FILE})
399 if(_CD_NAME_ON_CD)
400 # rename it in the cd tree
401 set(__file ${_CD_NAME_ON_CD})
402 else()
403 get_filename_component(__file ${item} NAME)
404 endif()
405 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
406 endforeach()
407 endif() #end hybridcd
408
409 # do we add it to regtest?
410 list(FIND _CD_FOR regtest __cd)
411 if(NOT __cd EQUAL -1)
412 # whether or not we should put it in reactos.cab or directly on cd
413 if(_CD_NO_CAB)
414 # directly on cd
415 foreach(item ${_CD_FILE})
416 if(_CD_NAME_ON_CD)
417 # rename it in the cd tree
418 set(__file ${_CD_NAME_ON_CD})
419 else()
420 get_filename_component(__file ${item} NAME)
421 endif()
422 set_property(GLOBAL APPEND PROPERTY BOOTCDREGTEST_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
423 endforeach()
424 # manage dependency
425 if(_CD_TARGET)
426 add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
427 endif()
428 else()
429 #add it in reactos.cab
430 #dir_to_num(${_CD_DESTINATION} _num)
431 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
432 #if(_CD_TARGET)
433 # #manage dependency
434 # add_dependencies(reactos_cab ${_CD_TARGET})
435 #endif()
436 endif()
437 endif() #end bootcd
438 endfunction()
439
440 function(create_iso_lists)
441 # generate reactos.cab before anything else
442 get_property(_filelist GLOBAL PROPERTY REACTOS_CAB_DEPENDS)
443
444 # begin with reactos.inf. We want this command to be always executed, so we pretend it generates another file although it will never do.
445 add_custom_command(
446 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/__some_non_existent_file
447 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf
448 DEPENDS ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf reactos_cab_inf)
449
450 add_custom_command(
451 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
452 COMMAND native-cabman -C ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff -RC ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf -N -P ${REACTOS_SOURCE_DIR}
453 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf native-cabman ${_filelist})
454
455 add_custom_target(reactos_cab DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab)
456 add_dependencies(reactos_cab reactos_cab_inf)
457
458 add_cd_file(
459 TARGET reactos_cab
460 FILE ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
461 DESTINATION reactos
462 NO_CAB FOR bootcd regtest)
463
464 add_cd_file(
465 FILE ${CMAKE_CURRENT_BINARY_DIR}/livecd.iso
466 DESTINATION livecd
467 FOR hybridcd)
468
469 get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
470 string(REPLACE ";" "\n" _filelist "${_filelist}")
471 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst "${_filelist}")
472 unset(_filelist)
473 file(GENERATE
474 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcd.$<CONFIG>.lst
475 INPUT ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst)
476
477 get_property(_filelist GLOBAL PROPERTY LIVECD_FILE_LIST)
478 string(REPLACE ";" "\n" _filelist "${_filelist}")
479 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst "${_filelist}")
480 unset(_filelist)
481 file(GENERATE
482 OUTPUT ${REACTOS_BINARY_DIR}/boot/livecd.$<CONFIG>.lst
483 INPUT ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst)
484
485 get_property(_filelist GLOBAL PROPERTY HYBRIDCD_FILE_LIST)
486 string(REPLACE ";" "\n" _filelist "${_filelist}")
487 file(APPEND ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst "${_filelist}")
488 unset(_filelist)
489 file(GENERATE
490 OUTPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.$<CONFIG>.lst
491 INPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst)
492
493 get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
494 string(REPLACE ";" "\n" _filelist "${_filelist}")
495 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst "${_filelist}")
496 unset(_filelist)
497 file(GENERATE
498 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.$<CONFIG>.lst
499 INPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst)
500 endfunction()
501
502 # Create module_clean targets
503 function(add_clean_target _target)
504 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
505 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
506 set(_clean_command make clean)
507 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
508 set(_clean_command nmake /nologo clean)
509 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
510 set(_clean_command ninja -t clean ${_target})
511 set(_clean_working_directory ${REACTOS_BINARY_DIR})
512 endif()
513 add_custom_target(${_target}_clean
514 COMMAND ${_clean_command}
515 WORKING_DIRECTORY ${_clean_working_directory}
516 COMMENT "Cleaning ${_target}")
517 endfunction()
518
519 if(NOT MSVC_IDE)
520 function(add_library name)
521 _add_library(${name} ${ARGN})
522 add_clean_target(${name})
523 endfunction()
524
525 function(add_executable name)
526 _add_executable(${name} ${ARGN})
527 add_clean_target(${name})
528 endfunction()
529 elseif(USE_FOLDER_STRUCTURE)
530 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
531 string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
532
533 function(add_custom_target name)
534 _add_custom_target(${name} ${ARGN})
535 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
536 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
537 endfunction()
538
539 function(add_library name)
540 _add_library(${name} ${ARGN})
541 get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
542 if(_target_excluded AND ${name} MATCHES "^lib.*")
543 set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
544 else()
545 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
546 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
547 endif()
548 endfunction()
549
550 function(add_executable name)
551 _add_executable(${name} ${ARGN})
552 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
553 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
554 endfunction()
555 endif()
556
557 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
558 function(concatenate_files _output _file1)
559 file(TO_NATIVE_PATH "${_output}" _real_output)
560 file(TO_NATIVE_PATH "${_file1}" _file_list)
561 foreach(_file ${ARGN})
562 file(TO_NATIVE_PATH "${_file}" _real_file)
563 set(_file_list "${_file_list} + ${_real_file}")
564 endforeach()
565 add_custom_command(
566 OUTPUT ${_output}
567 COMMAND cmd.exe /C "copy /Y /B ${_file_list} ${_real_output} > nul"
568 DEPENDS ${_file1} ${ARGN})
569 endfunction()
570 else()
571 macro(concatenate_files _output)
572 add_custom_command(
573 OUTPUT ${_output}
574 COMMAND cat ${ARGN} > ${_output}
575 DEPENDS ${ARGN})
576 endmacro()
577 endif()
578
579 function(add_importlibs _module)
580 add_dependency_node(${_module})
581 foreach(LIB ${ARGN})
582 if("${LIB}" MATCHES "msvcrt")
583 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
584 target_link_libraries(${_module} msvcrtex)
585 endif()
586 target_link_libraries(${_module} lib${LIB})
587 add_dependencies(${_module} lib${LIB})
588 add_dependency_edge(${_module} ${LIB})
589 endforeach()
590 endfunction()
591
592 function(set_module_type MODULE TYPE)
593 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
594
595 if(__module_UNPARSED_ARGUMENTS)
596 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
597 endif()
598
599 # Add the module to the module group list, if it is defined
600 if(DEFINED CURRENT_MODULE_GROUP)
601 set_property(GLOBAL APPEND PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST "${MODULE}")
602 endif()
603
604 # Set subsystem. Also take this as an occasion
605 # to error out if someone gave a non existing type
606 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll)
607 OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
608 set(__subsystem native)
609 elseif(${TYPE} STREQUAL win32cui)
610 set(__subsystem console)
611 elseif(${TYPE} STREQUAL win32gui)
612 set(__subsystem windows)
613 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
614 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
615 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
616 endif()
617
618 if(DEFINED __subsystem)
619 set_subsystem(${MODULE} ${__subsystem})
620 endif()
621
622 # Set the PE image version numbers from the NT OS version ReactOS is based on
623 if (MSVC)
624 add_target_link_flags(${MODULE} "/VERSION:5.01")
625 else()
626 add_target_link_flags(${MODULE} "-Wl,--major-image-version,5 -Wl,--minor-image-version,01")
627 add_target_link_flags(${MODULE} "-Wl,--major-os-version,5 -Wl,--minor-os-version,01")
628 endif()
629
630 # Set unicode definitions
631 if(__module_UNICODE)
632 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
633 endif()
634
635 # Set entry point
636 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
637 list(GET __module_ENTRYPOINT 0 __entrypoint)
638 list(LENGTH __module_ENTRYPOINT __length)
639 if(${__length} EQUAL 2)
640 list(GET __module_ENTRYPOINT 1 __entrystack)
641 elseif(NOT ${__length} EQUAL 1)
642 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
643 endif()
644 unset(__length)
645 elseif(${TYPE} STREQUAL nativecui)
646 set(__entrypoint NtProcessStartup)
647 set(__entrystack 4)
648 elseif(${TYPE} STREQUAL win32cui)
649 if(__module_UNICODE)
650 set(__entrypoint wmainCRTStartup)
651 else()
652 set(__entrypoint mainCRTStartup)
653 endif()
654 elseif(${TYPE} STREQUAL win32gui)
655 if(__module_UNICODE)
656 set(__entrypoint wWinMainCRTStartup)
657 else()
658 set(__entrypoint WinMainCRTStartup)
659 endif()
660 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
661 OR (${TYPE} STREQUAL cpl))
662 set(__entrypoint DllMainCRTStartup)
663 set(__entrystack 12)
664 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
665 set(__entrypoint DriverEntry)
666 set(__entrystack 8)
667 elseif(${TYPE} STREQUAL nativedll)
668 set(__entrypoint DllMain)
669 set(__entrystack 12)
670 elseif(${TYPE} STREQUAL module)
671 set(__entrypoint 0)
672 endif()
673
674 if(DEFINED __entrypoint)
675 if(DEFINED __entrystack)
676 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
677 else()
678 set_entrypoint(${MODULE} ${__entrypoint})
679 endif()
680 endif()
681
682 # Set base address
683 if(__module_IMAGEBASE)
684 set_image_base(${MODULE} ${__module_IMAGEBASE})
685 elseif(${TYPE} STREQUAL win32dll)
686 if(DEFINED baseaddress_${MODULE})
687 set_image_base(${MODULE} ${baseaddress_${MODULE}})
688 else()
689 message(STATUS "${MODULE} has no base address")
690 endif()
691 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
692 set_image_base(${MODULE} 0x00010000)
693 endif()
694
695 # Now do some stuff which is specific to each type
696 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
697 add_dependencies(${MODULE} bugcodes xdk)
698 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
699 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
700 endif()
701 endif()
702
703 if(${TYPE} STREQUAL win32ocx)
704 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
705 endif()
706
707 if(${TYPE} STREQUAL cpl)
708 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
709 endif()
710
711 # Do compiler specific stuff
712 set_module_type_toolchain(${MODULE} ${TYPE})
713 endfunction()
714
715 function(start_module_group __name)
716 if(DEFINED CURRENT_MODULE_GROUP)
717 message(FATAL_ERROR "CURRENT_MODULE_GROUP is already set ('${CURRENT_MODULE_GROUP}')")
718 endif()
719 set(CURRENT_MODULE_GROUP ${__name} PARENT_SCOPE)
720 endfunction()
721
722 function(end_module_group)
723 get_property(__modulelist GLOBAL PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST)
724 add_custom_target(${CURRENT_MODULE_GROUP})
725 foreach(__module ${__modulelist})
726 add_dependencies(${CURRENT_MODULE_GROUP} ${__module})
727 endforeach()
728 set(CURRENT_MODULE_GROUP PARENT_SCOPE)
729 endfunction()
730
731 function(preprocess_file __in __out)
732 set(__arg ${__in})
733 foreach(__def ${ARGN})
734 list(APPEND __arg -D${__def})
735 endforeach()
736 if(MSVC)
737 add_custom_command(OUTPUT ${_out}
738 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
739 DEPENDS ${__in})
740 else()
741 add_custom_command(OUTPUT ${_out}
742 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
743 DEPENDS ${__in})
744 endif()
745 endfunction()
746
747 function(get_includes OUTPUT_VAR)
748 get_directory_property(_includes INCLUDE_DIRECTORIES)
749 foreach(arg ${_includes})
750 list(APPEND __tmp_var -I${arg})
751 endforeach()
752 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
753 endfunction()
754
755 function(get_defines OUTPUT_VAR)
756 get_directory_property(_defines COMPILE_DEFINITIONS)
757 foreach(arg ${_defines})
758 list(APPEND __tmp_var -D${arg})
759 endforeach()
760 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
761 endfunction()
762
763 if(NOT MSVC)
764 function(add_object_library _target)
765 add_library(${_target} OBJECT ${ARGN})
766 endfunction()
767 else()
768 function(add_object_library _target)
769 add_library(${_target} ${ARGN})
770 endfunction()
771 endif()
772
773 function(add_registry_inf)
774 # Add to the inf files list
775 foreach(_file ${ARGN})
776 set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
777 set_property(GLOBAL APPEND PROPERTY REGISTRY_INF_LIST ${_source_file})
778 endforeach()
779 endfunction()
780
781 function(create_registry_hives)
782
783 # Shortcut to the registry.inf file
784 set(_registry_inf "${CMAKE_BINARY_DIR}/boot/bootdata/registry.inf")
785
786 # Get the list of inf files
787 get_property(_inf_files GLOBAL PROPERTY REGISTRY_INF_LIST)
788
789 # Convert files to utf16le
790 foreach(_file ${_inf_files})
791 get_filename_component(_file_name ${_file} NAME_WE)
792 string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _converted_file "${_file}")
793 string(REPLACE ${_file_name} "${_file_name}_utf16" _converted_file ${_converted_file})
794 add_custom_command(OUTPUT ${_converted_file}
795 COMMAND native-utf16le ${_file} ${_converted_file}
796 DEPENDS native-utf16le ${_file})
797 list(APPEND _converted_files ${_converted_file})
798 endforeach()
799
800 # Concatenate all registry files to registry.inf
801 concatenate_files(${_registry_inf} ${_converted_files})
802
803 # Add registry.inf to bootcd
804 add_custom_target(registry_inf DEPENDS ${_registry_inf})
805 add_cd_file(TARGET registry_inf
806 FILE ${_registry_inf}
807 DESTINATION reactos
808 NO_CAB
809 FOR bootcd regtest)
810
811 # BootCD setup system hive
812 add_custom_command(
813 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV
814 COMMAND native-mkhive -h:SETUPREG -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf
815 DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf)
816
817 add_custom_target(bootcd_hives
818 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV)
819
820 add_cd_file(
821 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV
822 TARGET bootcd_hives
823 DESTINATION reactos
824 NO_CAB
825 FOR bootcd regtest)
826
827 # LiveCD hives
828 list(APPEND _livecd_inf_files
829 ${_registry_inf}
830 ${CMAKE_SOURCE_DIR}/boot/bootdata/livecd.inf
831 ${CMAKE_SOURCE_DIR}/boot/bootdata/hiveinst.inf)
832
833 add_custom_command(
834 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/system
835 ${CMAKE_BINARY_DIR}/boot/bootdata/software
836 ${CMAKE_BINARY_DIR}/boot/bootdata/default
837 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
838 ${CMAKE_BINARY_DIR}/boot/bootdata/security
839 COMMAND native-mkhive -h:SYSTEM,SOFTWARE,DEFAULT,SAM,SECURITY -d:${CMAKE_BINARY_DIR}/boot/bootdata ${_livecd_inf_files}
840 DEPENDS native-mkhive ${_livecd_inf_files})
841
842 add_custom_target(livecd_hives
843 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/system
844 ${CMAKE_BINARY_DIR}/boot/bootdata/software
845 ${CMAKE_BINARY_DIR}/boot/bootdata/default
846 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
847 ${CMAKE_BINARY_DIR}/boot/bootdata/security)
848
849 add_cd_file(
850 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/system
851 ${CMAKE_BINARY_DIR}/boot/bootdata/software
852 ${CMAKE_BINARY_DIR}/boot/bootdata/default
853 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
854 ${CMAKE_BINARY_DIR}/boot/bootdata/security
855 TARGET livecd_hives
856 DESTINATION reactos/system32/config
857 FOR livecd)
858
859 # BCD Hive
860 add_custom_command(
861 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
862 COMMAND native-mkhive -h:BCD -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf
863 DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf)
864
865 add_custom_target(bcd_hive
866 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/BCD)
867
868 add_cd_file(
869 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
870 TARGET bcd_hive
871 DESTINATION efi/boot
872 NO_CAB
873 FOR bootcd regtest livecd)
874
875 endfunction()
876
877 if(KDBG)
878 set(ROSSYM_LIB "rossym")
879 else()
880 set(ROSSYM_LIB "")
881 endif()
882
883 function(add_rc_deps _target_rc)
884 set_source_files_properties(${_target_rc} PROPERTIES OBJECT_DEPENDS "${ARGN}")
885 endfunction()
886
887 add_custom_target(rostests_install COMMAND ${CMAKE_COMMAND} -DCOMPONENT=rostests -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
888 function(add_rostests_file)
889 cmake_parse_arguments(_ROSTESTS "" "RENAME;SUBDIR;TARGET" "FILE" ${ARGN})
890 if(NOT (_ROSTESTS_TARGET OR _ROSTESTS_FILE))
891 message(FATAL_ERROR "You must provide a target or a file to install!")
892 endif()
893
894 set(_ROSTESTS_NAME_ON_CD "${_ROSTESTS_RENAME}")
895 if(NOT _ROSTESTS_FILE)
896 set(_ROSTESTS_FILE "$<TARGET_FILE:${_ROSTESTS_TARGET}>")
897 if(NOT _ROSTESTS_RENAME)
898 set(_ROSTESTS_NAME_ON_CD "$<TARGET_FILE_NAME:${_ROSTESTS_TARGET}>")
899 endif()
900 else()
901 if(NOT _ROSTESTS_RENAME)
902 get_filename_component(_ROSTESTS_NAME_ON_CD ${_ROSTESTS_FILE} NAME)
903 endif()
904 endif()
905
906 if(_ROSTESTS_SUBDIR)
907 set(_ROSTESTS_SUBDIR "/${_ROSTESTS_SUBDIR}")
908 endif()
909
910 if(_ROSTESTS_TARGET)
911 add_cd_file(TARGET ${_ROSTESTS_TARGET} FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
912 else()
913 add_cd_file(FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
914 endif()
915
916 if(DEFINED ENV{ROSTESTS_INSTALL})
917 if(_ROSTESTS_RENAME)
918 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests RENAME ${_ROSTESTS_RENAME})
919 else()
920 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests)
921 endif()
922 endif()
923 endfunction()