[MODERN.MSSTYLES] Add the initial version of the modern theme.
[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 macro(dir_to_num dir var)
166 if(${dir} STREQUAL reactos/system32)
167 set(${var} 1)
168 elseif(${dir} STREQUAL reactos/system32/drivers)
169 set(${var} 2)
170 elseif(${dir} STREQUAL reactos/Fonts)
171 set(${var} 3)
172 elseif(${dir} STREQUAL reactos)
173 set(${var} 4)
174 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
175 set(${var} 5)
176 elseif(${dir} STREQUAL reactos/inf)
177 set(${var} 6)
178 elseif(${dir} STREQUAL reactos/bin)
179 set(${var} 7)
180 elseif(${dir} STREQUAL reactos/bin/testdata)
181 set(${var} 8)
182 elseif(${dir} STREQUAL reactos/bin/suppl)
183 set(${var} 80)
184 elseif(${dir} STREQUAL reactos/media)
185 set(${var} 9)
186 elseif(${dir} STREQUAL reactos/Microsoft.NET)
187 set(${var} 10)
188 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
189 set(${var} 11)
190 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
191 set(${var} 12)
192 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
193 set(${var} 13)
194 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
195 set(${var} 14)
196 elseif(${dir} STREQUAL reactos/Resources)
197 set(${var} 15)
198 elseif(${dir} STREQUAL reactos/Resources/Themes)
199 set(${var} 16)
200 elseif(${dir} STREQUAL reactos/system32/wbem)
201 set(${var} 17)
202 elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
203 set(${var} 18)
204 elseif(${dir} STREQUAL reactos/Help)
205 set(${var} 19)
206 elseif(${dir} STREQUAL reactos/Config)
207 set(${var} 20)
208 elseif(${dir} STREQUAL reactos/Cursors)
209 set(${var} 21)
210 elseif(${dir} STREQUAL reactos/system32/ShellExt)
211 set(${var} 22)
212 elseif(${dir} STREQUAL reactos/Temp)
213 set(${var} 23)
214 elseif(${dir} STREQUAL reactos/system32/spool)
215 set(${var} 24)
216 elseif(${dir} STREQUAL reactos/system32/spool/drivers)
217 set(${var} 25)
218 elseif(${dir} STREQUAL reactos/system32/spool/drivers/color)
219 set(${var} 26)
220 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86)
221 set(${var} 27)
222 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86/3)
223 set(${var} 28)
224 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs)
225 set(${var} 29)
226 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs/w32x86)
227 set(${var} 30)
228 elseif(${dir} STREQUAL reactos/system32/spool/PRINTERS)
229 set(${var} 31)
230 elseif(${dir} STREQUAL reactos/system32/wbem/Repository)
231 set(${var} 32)
232 elseif(${dir} STREQUAL reactos/system32/wbem/Repository/FS)
233 set(${var} 33)
234 elseif(${dir} STREQUAL reactos/system32/wbem/mof/good)
235 set(${var} 34)
236 elseif(${dir} STREQUAL reactos/system32/wbem/mof/bad)
237 set(${var} 35)
238 elseif(${dir} STREQUAL reactos/system32/wbem/AdStatus)
239 set(${var} 36)
240 elseif(${dir} STREQUAL reactos/system32/wbem/xml)
241 set(${var} 37)
242 elseif(${dir} STREQUAL reactos/system32/wbem/Logs)
243 set(${var} 38)
244 elseif(${dir} STREQUAL reactos/system32/wbem/AutoRecover)
245 set(${var} 39)
246 elseif(${dir} STREQUAL reactos/system32/wbem/snmp)
247 set(${var} 40)
248 elseif(${dir} STREQUAL reactos/system32/wbem/Performance)
249 set(${var} 41)
250 elseif(${dir} STREQUAL reactos/twain_32)
251 set(${var} 42)
252 elseif(${dir} STREQUAL reactos/repair)
253 set(${var} 43)
254 elseif(${dir} STREQUAL reactos/Web)
255 set(${var} 44)
256 elseif(${dir} STREQUAL reactos/Web/Wallpaper)
257 set(${var} 45)
258 elseif(${dir} STREQUAL reactos/Prefetch)
259 set(${var} 46)
260 elseif(${dir} STREQUAL reactos/security)
261 set(${var} 47)
262 elseif(${dir} STREQUAL reactos/security/Database)
263 set(${var} 48)
264 elseif(${dir} STREQUAL reactos/security/logs)
265 set(${var} 49)
266 elseif(${dir} STREQUAL reactos/security/templates)
267 set(${var} 50)
268 elseif(${dir} STREQUAL reactos/system32/CatRoot)
269 set(${var} 51)
270 elseif(${dir} STREQUAL reactos/system32/CatRoot2)
271 set(${var} 52)
272 elseif(${dir} STREQUAL reactos/AppPatch)
273 set(${var} 53)
274 elseif(${dir} STREQUAL reactos/winsxs)
275 set(${var} 54)
276 elseif(${dir} STREQUAL reactos/winsxs/manifests)
277 set(${var} 55)
278 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.2600.2982_none_deadbeef)
279 set(${var} 56)
280 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef)
281 set(${var} 57)
282 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.23038_none_deadbeef)
283 set(${var} 58)
284 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.apisets_6595b64144ccf1df_1.0.0.0_none_deadbeef)
285 set(${var} 59)
286 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.newapi_6595b64144ccf1df_1.0.0.0_none_deadbeef)
287 set(${var} 60)
288 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.14393.0_none_deadbeef)
289 set(${var} 61)
290 elseif(${dir} STREQUAL reactos/Resources/Themes/Modern)
291 set(${var} 62)
292 else()
293 message(FATAL_ERROR "Wrong destination: ${dir}")
294 endif()
295 endmacro()
296
297 function(add_cd_file)
298 cmake_parse_arguments(_CD "NO_CAB;NOT_IN_HYBRIDCD" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
299 if(NOT (_CD_TARGET OR _CD_FILE))
300 message(FATAL_ERROR "You must provide a target or a file to install!")
301 endif()
302
303 if(NOT _CD_DESTINATION)
304 message(FATAL_ERROR "You must provide a destination")
305 elseif(${_CD_DESTINATION} STREQUAL root)
306 set(_CD_DESTINATION "")
307 endif()
308
309 if(NOT _CD_FOR)
310 message(FATAL_ERROR "You must provide a cd name (or \"all\" for all of them) to install the file on!")
311 endif()
312
313 # get file if we need to
314 if(NOT _CD_FILE)
315 set(_CD_FILE "$<TARGET_FILE:${_CD_TARGET}>")
316 if(NOT _CD_NAME_ON_CD)
317 set(_CD_NAME_ON_CD "$<TARGET_FILE_NAME:${_CD_TARGET}>")
318 endif()
319 endif()
320
321 # do we add it to all CDs?
322 list(FIND _CD_FOR all __cd)
323 if(NOT __cd EQUAL -1)
324 list(REMOVE_AT _CD_FOR __cd)
325 list(INSERT _CD_FOR __cd "bootcd;livecd;regtest")
326 endif()
327
328 # do we add it to bootcd?
329 list(FIND _CD_FOR bootcd __cd)
330 if(NOT __cd EQUAL -1)
331 # whether or not we should put it in reactos.cab or directly on cd
332 if(_CD_NO_CAB)
333 # directly on cd
334 foreach(item ${_CD_FILE})
335 if(_CD_NAME_ON_CD)
336 # rename it in the cd tree
337 set(__file ${_CD_NAME_ON_CD})
338 else()
339 get_filename_component(__file ${item} NAME)
340 endif()
341 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
342 # add it also into the hybridcd if not specified otherwise
343 if(NOT _CD_NOT_IN_HYBRIDCD)
344 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "bootcd/${_CD_DESTINATION}/${__file}=${item}")
345 endif()
346 endforeach()
347 # manage dependency
348 if(_CD_TARGET)
349 add_dependencies(bootcd ${_CD_TARGET} registry_inf)
350 endif()
351 else()
352 # add it in reactos.cab
353 dir_to_num(${_CD_DESTINATION} _num)
354 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.cmake "\"${_CD_FILE}\" ${_num}\n")
355 # manage dependency - target level
356 if(_CD_TARGET)
357 add_dependencies(reactos_cab_inf ${_CD_TARGET})
358 endif()
359 # manage dependency - file level
360 set_property(GLOBAL APPEND PROPERTY REACTOS_CAB_DEPENDS ${_CD_FILE})
361 endif()
362 endif() #end bootcd
363
364 # do we add it to livecd?
365 list(FIND _CD_FOR livecd __cd)
366 if(NOT __cd EQUAL -1)
367 # manage dependency
368 if(_CD_TARGET)
369 add_dependencies(livecd ${_CD_TARGET} registry_inf)
370 endif()
371 foreach(item ${_CD_FILE})
372 if(_CD_NAME_ON_CD)
373 # rename it in the cd tree
374 set(__file ${_CD_NAME_ON_CD})
375 else()
376 get_filename_component(__file ${item} NAME)
377 endif()
378 set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
379 # add it also into the hybridcd if not specified otherwise
380 if(NOT _CD_NOT_IN_HYBRIDCD)
381 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "livecd/${_CD_DESTINATION}/${__file}=${item}")
382 endif()
383 endforeach()
384 endif() #end livecd
385
386 # do we need also to add it to hybridcd?
387 list(FIND _CD_FOR hybridcd __cd)
388 if(NOT __cd EQUAL -1)
389 # manage dependency
390 if(_CD_TARGET)
391 add_dependencies(hybridcd ${_CD_TARGET})
392 endif()
393 foreach(item ${_CD_FILE})
394 if(_CD_NAME_ON_CD)
395 # rename it in the cd tree
396 set(__file ${_CD_NAME_ON_CD})
397 else()
398 get_filename_component(__file ${item} NAME)
399 endif()
400 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
401 endforeach()
402 endif() #end hybridcd
403
404 # do we add it to regtest?
405 list(FIND _CD_FOR regtest __cd)
406 if(NOT __cd EQUAL -1)
407 # whether or not we should put it in reactos.cab or directly on cd
408 if(_CD_NO_CAB)
409 # directly on cd
410 foreach(item ${_CD_FILE})
411 if(_CD_NAME_ON_CD)
412 # rename it in the cd tree
413 set(__file ${_CD_NAME_ON_CD})
414 else()
415 get_filename_component(__file ${item} NAME)
416 endif()
417 set_property(GLOBAL APPEND PROPERTY BOOTCDREGTEST_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
418 endforeach()
419 # manage dependency
420 if(_CD_TARGET)
421 add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
422 endif()
423 else()
424 #add it in reactos.cab
425 #dir_to_num(${_CD_DESTINATION} _num)
426 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
427 #if(_CD_TARGET)
428 # #manage dependency
429 # add_dependencies(reactos_cab ${_CD_TARGET})
430 #endif()
431 endif()
432 endif() #end bootcd
433 endfunction()
434
435 function(create_iso_lists)
436 # generate reactos.cab before anything else
437 get_property(_filelist GLOBAL PROPERTY REACTOS_CAB_DEPENDS)
438
439 # begin with reactos.inf. We want this command to be always executed, so we pretend it generates another file although it will never do.
440 add_custom_command(
441 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/__some_non_existent_file
442 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf
443 DEPENDS ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf reactos_cab_inf)
444
445 add_custom_command(
446 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
447 COMMAND native-cabman -C ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff -RC ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf -N -P ${REACTOS_SOURCE_DIR}
448 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf native-cabman ${_filelist})
449
450 add_custom_target(reactos_cab DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab)
451 add_dependencies(reactos_cab reactos_cab_inf)
452
453 add_cd_file(
454 TARGET reactos_cab
455 FILE ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
456 DESTINATION reactos
457 NO_CAB FOR bootcd regtest)
458
459 add_cd_file(
460 FILE ${CMAKE_CURRENT_BINARY_DIR}/livecd.iso
461 DESTINATION livecd
462 FOR hybridcd)
463
464 get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
465 string(REPLACE ";" "\n" _filelist "${_filelist}")
466 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst "${_filelist}")
467 unset(_filelist)
468 file(GENERATE
469 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcd.$<CONFIG>.lst
470 INPUT ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst)
471
472 get_property(_filelist GLOBAL PROPERTY LIVECD_FILE_LIST)
473 string(REPLACE ";" "\n" _filelist "${_filelist}")
474 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst "${_filelist}")
475 unset(_filelist)
476 file(GENERATE
477 OUTPUT ${REACTOS_BINARY_DIR}/boot/livecd.$<CONFIG>.lst
478 INPUT ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst)
479
480 get_property(_filelist GLOBAL PROPERTY HYBRIDCD_FILE_LIST)
481 string(REPLACE ";" "\n" _filelist "${_filelist}")
482 file(APPEND ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst "${_filelist}")
483 unset(_filelist)
484 file(GENERATE
485 OUTPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.$<CONFIG>.lst
486 INPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst)
487
488 get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
489 string(REPLACE ";" "\n" _filelist "${_filelist}")
490 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst "${_filelist}")
491 unset(_filelist)
492 file(GENERATE
493 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.$<CONFIG>.lst
494 INPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst)
495 endfunction()
496
497 # Create module_clean targets
498 function(add_clean_target _target)
499 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
500 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
501 set(_clean_command make clean)
502 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
503 set(_clean_command nmake /nologo clean)
504 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
505 set(_clean_command ninja -t clean ${_target})
506 set(_clean_working_directory ${REACTOS_BINARY_DIR})
507 endif()
508 add_custom_target(${_target}_clean
509 COMMAND ${_clean_command}
510 WORKING_DIRECTORY ${_clean_working_directory}
511 COMMENT "Cleaning ${_target}")
512 endfunction()
513
514 if(NOT MSVC_IDE)
515 function(add_library name)
516 _add_library(${name} ${ARGN})
517 add_clean_target(${name})
518 endfunction()
519
520 function(add_executable name)
521 _add_executable(${name} ${ARGN})
522 add_clean_target(${name})
523 endfunction()
524 elseif(USE_FOLDER_STRUCTURE)
525 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
526 string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
527
528 function(add_custom_target name)
529 _add_custom_target(${name} ${ARGN})
530 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
531 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
532 endfunction()
533
534 function(add_library name)
535 _add_library(${name} ${ARGN})
536 get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
537 if(_target_excluded AND ${name} MATCHES "^lib.*")
538 set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
539 else()
540 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
541 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
542 endif()
543 endfunction()
544
545 function(add_executable name)
546 _add_executable(${name} ${ARGN})
547 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
548 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
549 endfunction()
550 endif()
551
552 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
553 function(concatenate_files _output _file1)
554 file(TO_NATIVE_PATH "${_output}" _real_output)
555 file(TO_NATIVE_PATH "${_file1}" _file_list)
556 foreach(_file ${ARGN})
557 file(TO_NATIVE_PATH "${_file}" _real_file)
558 set(_file_list "${_file_list} + ${_real_file}")
559 endforeach()
560 add_custom_command(
561 OUTPUT ${_output}
562 COMMAND cmd.exe /C "copy /Y /B ${_file_list} ${_real_output} > nul"
563 DEPENDS ${_file1} ${ARGN})
564 endfunction()
565 else()
566 macro(concatenate_files _output)
567 add_custom_command(
568 OUTPUT ${_output}
569 COMMAND cat ${ARGN} > ${_output}
570 DEPENDS ${ARGN})
571 endmacro()
572 endif()
573
574 function(add_importlibs _module)
575 add_dependency_node(${_module})
576 foreach(LIB ${ARGN})
577 if("${LIB}" MATCHES "msvcrt")
578 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
579 target_link_libraries(${_module} msvcrtex)
580 endif()
581 target_link_libraries(${_module} lib${LIB})
582 add_dependencies(${_module} lib${LIB})
583 add_dependency_edge(${_module} ${LIB})
584 endforeach()
585 endfunction()
586
587 function(set_module_type MODULE TYPE)
588 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
589
590 if(__module_UNPARSED_ARGUMENTS)
591 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
592 endif()
593
594 # Add the module to the module group list, if it is defined
595 if(DEFINED CURRENT_MODULE_GROUP)
596 set_property(GLOBAL APPEND PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST "${MODULE}")
597 endif()
598
599 # Set subsystem. Also take this as an occasion
600 # to error out if someone gave a non existing type
601 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll)
602 OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
603 set(__subsystem native)
604 elseif(${TYPE} STREQUAL win32cui)
605 set(__subsystem console)
606 elseif(${TYPE} STREQUAL win32gui)
607 set(__subsystem windows)
608 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
609 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
610 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
611 endif()
612
613 if(DEFINED __subsystem)
614 set_subsystem(${MODULE} ${__subsystem})
615 endif()
616
617 # Set the PE image version numbers from the NT OS version ReactOS is based on
618 if (MSVC)
619 add_target_link_flags(${MODULE} "/VERSION:5.01")
620 else()
621 add_target_link_flags(${MODULE} "-Wl,--major-image-version,5 -Wl,--minor-image-version,01")
622 add_target_link_flags(${MODULE} "-Wl,--major-os-version,5 -Wl,--minor-os-version,01")
623 endif()
624
625 # Set unicode definitions
626 if(__module_UNICODE)
627 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
628 endif()
629
630 # Set entry point
631 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
632 list(GET __module_ENTRYPOINT 0 __entrypoint)
633 list(LENGTH __module_ENTRYPOINT __length)
634 if(${__length} EQUAL 2)
635 list(GET __module_ENTRYPOINT 1 __entrystack)
636 elseif(NOT ${__length} EQUAL 1)
637 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
638 endif()
639 unset(__length)
640 elseif(${TYPE} STREQUAL nativecui)
641 set(__entrypoint NtProcessStartup)
642 set(__entrystack 4)
643 elseif(${TYPE} STREQUAL win32cui)
644 if(__module_UNICODE)
645 set(__entrypoint wmainCRTStartup)
646 else()
647 set(__entrypoint mainCRTStartup)
648 endif()
649 elseif(${TYPE} STREQUAL win32gui)
650 if(__module_UNICODE)
651 set(__entrypoint wWinMainCRTStartup)
652 else()
653 set(__entrypoint WinMainCRTStartup)
654 endif()
655 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
656 OR (${TYPE} STREQUAL cpl))
657 set(__entrypoint DllMainCRTStartup)
658 set(__entrystack 12)
659 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
660 set(__entrypoint DriverEntry)
661 set(__entrystack 8)
662 elseif(${TYPE} STREQUAL nativedll)
663 set(__entrypoint DllMain)
664 set(__entrystack 12)
665 elseif(${TYPE} STREQUAL module)
666 set(__entrypoint 0)
667 endif()
668
669 if(DEFINED __entrypoint)
670 if(DEFINED __entrystack)
671 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
672 else()
673 set_entrypoint(${MODULE} ${__entrypoint})
674 endif()
675 endif()
676
677 # Set base address
678 if(__module_IMAGEBASE)
679 set_image_base(${MODULE} ${__module_IMAGEBASE})
680 elseif(${TYPE} STREQUAL win32dll)
681 if(DEFINED baseaddress_${MODULE})
682 set_image_base(${MODULE} ${baseaddress_${MODULE}})
683 else()
684 message(STATUS "${MODULE} has no base address")
685 endif()
686 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
687 set_image_base(${MODULE} 0x00010000)
688 endif()
689
690 # Now do some stuff which is specific to each type
691 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
692 add_dependencies(${MODULE} bugcodes xdk)
693 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
694 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
695 endif()
696 endif()
697
698 if(${TYPE} STREQUAL win32ocx)
699 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
700 endif()
701
702 if(${TYPE} STREQUAL cpl)
703 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
704 endif()
705
706 # Do compiler specific stuff
707 set_module_type_toolchain(${MODULE} ${TYPE})
708 endfunction()
709
710 function(start_module_group __name)
711 if(DEFINED CURRENT_MODULE_GROUP)
712 message(FATAL_ERROR "CURRENT_MODULE_GROUP is already set ('${CURRENT_MODULE_GROUP}')")
713 endif()
714 set(CURRENT_MODULE_GROUP ${__name} PARENT_SCOPE)
715 endfunction()
716
717 function(end_module_group)
718 get_property(__modulelist GLOBAL PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST)
719 add_custom_target(${CURRENT_MODULE_GROUP})
720 foreach(__module ${__modulelist})
721 add_dependencies(${CURRENT_MODULE_GROUP} ${__module})
722 endforeach()
723 set(CURRENT_MODULE_GROUP PARENT_SCOPE)
724 endfunction()
725
726 function(preprocess_file __in __out)
727 set(__arg ${__in})
728 foreach(__def ${ARGN})
729 list(APPEND __arg -D${__def})
730 endforeach()
731 if(MSVC)
732 add_custom_command(OUTPUT ${_out}
733 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
734 DEPENDS ${__in})
735 else()
736 add_custom_command(OUTPUT ${_out}
737 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
738 DEPENDS ${__in})
739 endif()
740 endfunction()
741
742 function(get_includes OUTPUT_VAR)
743 get_directory_property(_includes INCLUDE_DIRECTORIES)
744 foreach(arg ${_includes})
745 list(APPEND __tmp_var -I${arg})
746 endforeach()
747 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
748 endfunction()
749
750 function(get_defines OUTPUT_VAR)
751 get_directory_property(_defines COMPILE_DEFINITIONS)
752 foreach(arg ${_defines})
753 list(APPEND __tmp_var -D${arg})
754 endforeach()
755 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
756 endfunction()
757
758 if(NOT MSVC)
759 function(add_object_library _target)
760 add_library(${_target} OBJECT ${ARGN})
761 endfunction()
762 else()
763 function(add_object_library _target)
764 add_library(${_target} ${ARGN})
765 endfunction()
766 endif()
767
768 function(add_registry_inf)
769 # Add to the inf files list
770 foreach(_file ${ARGN})
771 set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
772 set_property(GLOBAL APPEND PROPERTY REGISTRY_INF_LIST ${_source_file})
773 endforeach()
774 endfunction()
775
776 function(create_registry_hives)
777
778 # Shortcut to the registry.inf file
779 set(_registry_inf "${CMAKE_BINARY_DIR}/boot/bootdata/registry.inf")
780
781 # Get the list of inf files
782 get_property(_inf_files GLOBAL PROPERTY REGISTRY_INF_LIST)
783
784 # Convert files to utf16le
785 foreach(_file ${_inf_files})
786 get_filename_component(_file_name ${_file} NAME_WE)
787 string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _converted_file "${_file}")
788 string(REPLACE ${_file_name} "${_file_name}_utf16" _converted_file ${_converted_file})
789 add_custom_command(OUTPUT ${_converted_file}
790 COMMAND native-utf16le ${_file} ${_converted_file}
791 DEPENDS native-utf16le ${_file})
792 list(APPEND _converted_files ${_converted_file})
793 endforeach()
794
795 # Concatenate all registry files to registry.inf
796 concatenate_files(${_registry_inf} ${_converted_files})
797
798 # Add registry.inf to bootcd
799 add_custom_target(registry_inf DEPENDS ${_registry_inf})
800 add_cd_file(TARGET registry_inf
801 FILE ${_registry_inf}
802 DESTINATION reactos
803 NO_CAB
804 FOR bootcd regtest)
805
806 # livecd hives
807 list(APPEND _livecd_inf_files
808 ${_registry_inf}
809 ${CMAKE_SOURCE_DIR}/boot/bootdata/livecd.inf
810 ${CMAKE_SOURCE_DIR}/boot/bootdata/hiveinst.inf)
811
812 add_custom_command(
813 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/sam
814 ${CMAKE_BINARY_DIR}/boot/bootdata/default
815 ${CMAKE_BINARY_DIR}/boot/bootdata/security
816 ${CMAKE_BINARY_DIR}/boot/bootdata/software
817 ${CMAKE_BINARY_DIR}/boot/bootdata/system
818 ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
819 COMMAND native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata ${_livecd_inf_files}
820 DEPENDS native-mkhive ${_livecd_inf_files})
821
822 add_custom_target(livecd_hives
823 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/sam
824 ${CMAKE_BINARY_DIR}/boot/bootdata/default
825 ${CMAKE_BINARY_DIR}/boot/bootdata/security
826 ${CMAKE_BINARY_DIR}/boot/bootdata/software
827 ${CMAKE_BINARY_DIR}/boot/bootdata/system
828 ${CMAKE_BINARY_DIR}/boot/bootdata/BCD)
829
830 add_cd_file(
831 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/sam
832 ${CMAKE_BINARY_DIR}/boot/bootdata/default
833 ${CMAKE_BINARY_DIR}/boot/bootdata/security
834 ${CMAKE_BINARY_DIR}/boot/bootdata/software
835 ${CMAKE_BINARY_DIR}/boot/bootdata/system
836 TARGET livecd_hives
837 DESTINATION reactos/system32/config
838 FOR livecd)
839
840 add_cd_file(
841 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
842 TARGET livecd_hives
843 DESTINATION efi/boot
844 NO_CAB
845 FOR bootcd regtest livecd)
846
847 endfunction()
848
849 if(KDBG)
850 set(ROSSYM_LIB "rossym")
851 else()
852 set(ROSSYM_LIB "")
853 endif()
854
855 function(add_rc_deps _target_rc)
856 set_source_files_properties(${_target_rc} PROPERTIES OBJECT_DEPENDS "${ARGN}")
857 endfunction()
858
859 add_custom_target(rostests_install COMMAND ${CMAKE_COMMAND} -DCOMPONENT=rostests -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
860 function(add_rostests_file)
861 cmake_parse_arguments(_ROSTESTS "" "RENAME;SUBDIR;TARGET" "FILE" ${ARGN})
862 if(NOT (_ROSTESTS_TARGET OR _ROSTESTS_FILE))
863 message(FATAL_ERROR "You must provide a target or a file to install!")
864 endif()
865
866 set(_ROSTESTS_NAME_ON_CD "${_ROSTESTS_RENAME}")
867 if(NOT _ROSTESTS_FILE)
868 set(_ROSTESTS_FILE "$<TARGET_FILE:${_ROSTESTS_TARGET}>")
869 if(NOT _ROSTESTS_RENAME)
870 set(_ROSTESTS_NAME_ON_CD "$<TARGET_FILE_NAME:${_ROSTESTS_TARGET}>")
871 endif()
872 else()
873 if(NOT _ROSTESTS_RENAME)
874 get_filename_component(_ROSTESTS_NAME_ON_CD ${_ROSTESTS_FILE} NAME)
875 endif()
876 endif()
877
878 if(_ROSTESTS_SUBDIR)
879 set(_ROSTESTS_SUBDIR "/${_ROSTESTS_SUBDIR}")
880 endif()
881
882 if(_ROSTESTS_TARGET)
883 add_cd_file(TARGET ${_ROSTESTS_TARGET} FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
884 else()
885 add_cd_file(FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
886 endif()
887
888 if(DEFINED ENV{ROSTESTS_INSTALL})
889 if(_ROSTESTS_RENAME)
890 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests RENAME ${_ROSTESTS_RENAME})
891 else()
892 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests)
893 endif()
894 endif()
895 endfunction()