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