3 # Marks the current folder as containing C++ modules, additionally enabling
4 # specific C++ language features as specified (all of these default to off):
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.
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.
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
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.
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.
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}")
53 if(__cppopts_WITH_RUNTIME)
56 if(__cppopts_WITH_RTTI)
58 replace_compile_flags("/GR-" "/GR")
60 replace_compile_flags_language("-fno-rtti" "-frtti" "CXX")
63 if(__cppopts_WITH_EXCEPTIONS)
65 replace_compile_flags("/EHs-c-" "/EHsc")
67 replace_compile_flags_language("-fno-exceptions" "-fexceptions" "CXX")
70 if(__cppopts_WITH_STL)
73 add_definitions(-DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/sdk/include/c++)
74 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/c++/stlport)
76 replace_compile_flags("-nostdinc" " ")
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")
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")
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")
105 function(add_dependency_footer)
106 add_dependency_node(ntdll)
107 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
110 function(add_message_headers _type)
111 if(${_type} STREQUAL UNICODE)
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
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})
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)
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")
142 if(_LINK_CMD_LINE_ARGS)
143 set(_LINK_CMD_LINE_ARGS -c ${_LINK_CMD_LINE_ARGS})
147 set(_LINK_ICON -i ${_LINK_ICON})
151 set(_LINK_GUID -g ${_LINK_GUID})
155 set(_LINK_MINIMIZE "-m")
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)
165 macro(dir_to_num dir var)
166 if(${dir} STREQUAL reactos/system32)
168 elseif(${dir} STREQUAL reactos/system32/drivers)
170 elseif(${dir} STREQUAL reactos/Fonts)
172 elseif(${dir} STREQUAL reactos)
174 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
176 elseif(${dir} STREQUAL reactos/inf)
178 elseif(${dir} STREQUAL reactos/bin)
180 elseif(${dir} STREQUAL reactos/bin/testdata)
182 elseif(${dir} STREQUAL reactos/bin/suppl)
184 elseif(${dir} STREQUAL reactos/media)
186 elseif(${dir} STREQUAL reactos/Microsoft.NET)
188 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
190 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
192 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
194 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
196 elseif(${dir} STREQUAL reactos/Resources)
198 elseif(${dir} STREQUAL reactos/Resources/Themes)
200 elseif(${dir} STREQUAL reactos/system32/wbem)
202 elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
204 elseif(${dir} STREQUAL reactos/Help)
206 elseif(${dir} STREQUAL reactos/Config)
208 elseif(${dir} STREQUAL reactos/Cursors)
210 elseif(${dir} STREQUAL reactos/system32/ShellExt)
212 elseif(${dir} STREQUAL reactos/Temp)
214 elseif(${dir} STREQUAL reactos/system32/spool)
216 elseif(${dir} STREQUAL reactos/system32/spool/drivers)
218 elseif(${dir} STREQUAL reactos/system32/spool/drivers/color)
220 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86)
222 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86/3)
224 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs)
226 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs/w32x86)
228 elseif(${dir} STREQUAL reactos/system32/spool/PRINTERS)
230 elseif(${dir} STREQUAL reactos/system32/wbem/Repository)
232 elseif(${dir} STREQUAL reactos/system32/wbem/Repository/FS)
234 elseif(${dir} STREQUAL reactos/system32/wbem/mof/good)
236 elseif(${dir} STREQUAL reactos/system32/wbem/mof/bad)
238 elseif(${dir} STREQUAL reactos/system32/wbem/AdStatus)
240 elseif(${dir} STREQUAL reactos/system32/wbem/xml)
242 elseif(${dir} STREQUAL reactos/system32/wbem/Logs)
244 elseif(${dir} STREQUAL reactos/system32/wbem/AutoRecover)
246 elseif(${dir} STREQUAL reactos/system32/wbem/snmp)
248 elseif(${dir} STREQUAL reactos/system32/wbem/Performance)
250 elseif(${dir} STREQUAL reactos/twain_32)
252 elseif(${dir} STREQUAL reactos/repair)
254 elseif(${dir} STREQUAL reactos/Web)
256 elseif(${dir} STREQUAL reactos/Web/Wallpaper)
258 elseif(${dir} STREQUAL reactos/Prefetch)
260 elseif(${dir} STREQUAL reactos/security)
262 elseif(${dir} STREQUAL reactos/security/Database)
264 elseif(${dir} STREQUAL reactos/security/logs)
266 elseif(${dir} STREQUAL reactos/security/templates)
268 elseif(${dir} STREQUAL reactos/system32/CatRoot)
270 elseif(${dir} STREQUAL reactos/system32/CatRoot2)
272 elseif(${dir} STREQUAL reactos/AppPatch)
274 elseif(${dir} STREQUAL reactos/winsxs)
276 elseif(${dir} STREQUAL reactos/winsxs/manifests)
278 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.2600.2982_none_deadbeef)
280 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef)
282 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.23038_none_deadbeef)
285 message(FATAL_ERROR "Wrong destination: ${dir}")
289 function(add_cd_file)
290 cmake_parse_arguments(_CD "NO_CAB;NOT_IN_HYBRIDCD" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
291 if(NOT (_CD_TARGET OR _CD_FILE))
292 message(FATAL_ERROR "You must provide a target or a file to install!")
295 if(NOT _CD_DESTINATION)
296 message(FATAL_ERROR "You must provide a destination")
297 elseif(${_CD_DESTINATION} STREQUAL root)
298 set(_CD_DESTINATION "")
302 message(FATAL_ERROR "You must provide a cd name (or \"all\" for all of them) to install the file on!")
305 # get file if we need to
307 set(_CD_FILE "$<TARGET_FILE:${_CD_TARGET}>")
308 if(NOT _CD_NAME_ON_CD)
309 set(_CD_NAME_ON_CD "$<TARGET_FILE_NAME:${_CD_TARGET}>")
313 # do we add it to all CDs?
314 list(FIND _CD_FOR all __cd)
315 if(NOT __cd EQUAL -1)
316 list(REMOVE_AT _CD_FOR __cd)
317 list(INSERT _CD_FOR __cd "bootcd;livecd;regtest")
320 # do we add it to bootcd?
321 list(FIND _CD_FOR bootcd __cd)
322 if(NOT __cd EQUAL -1)
323 # whether or not we should put it in reactos.cab or directly on cd
326 foreach(item ${_CD_FILE})
328 # rename it in the cd tree
329 set(__file ${_CD_NAME_ON_CD})
331 get_filename_component(__file ${item} NAME)
333 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
334 # add it also into the hybridcd if not specified otherwise
335 if(NOT _CD_NOT_IN_HYBRIDCD)
336 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "bootcd/${_CD_DESTINATION}/${__file}=${item}")
341 add_dependencies(bootcd ${_CD_TARGET} registry_inf)
344 # add it in reactos.cab
345 dir_to_num(${_CD_DESTINATION} _num)
346 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.cmake "\"${_CD_FILE}\" ${_num}\n")
347 # manage dependency - target level
349 add_dependencies(reactos_cab_inf ${_CD_TARGET})
351 # manage dependency - file level
352 set_property(GLOBAL APPEND PROPERTY REACTOS_CAB_DEPENDS ${_CD_FILE})
356 # do we add it to livecd?
357 list(FIND _CD_FOR livecd __cd)
358 if(NOT __cd EQUAL -1)
361 add_dependencies(livecd ${_CD_TARGET} registry_inf)
363 foreach(item ${_CD_FILE})
365 # rename it in the cd tree
366 set(__file ${_CD_NAME_ON_CD})
368 get_filename_component(__file ${item} NAME)
370 set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
371 # add it also into the hybridcd if not specified otherwise
372 if(NOT _CD_NOT_IN_HYBRIDCD)
373 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "livecd/${_CD_DESTINATION}/${__file}=${item}")
378 # do we need also to add it to hybridcd?
379 list(FIND _CD_FOR hybridcd __cd)
380 if(NOT __cd EQUAL -1)
383 add_dependencies(hybridcd ${_CD_TARGET})
385 foreach(item ${_CD_FILE})
387 # rename it in the cd tree
388 set(__file ${_CD_NAME_ON_CD})
390 get_filename_component(__file ${item} NAME)
392 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
394 endif() #end hybridcd
396 # do we add it to regtest?
397 list(FIND _CD_FOR regtest __cd)
398 if(NOT __cd EQUAL -1)
399 # whether or not we should put it in reactos.cab or directly on cd
402 foreach(item ${_CD_FILE})
404 # rename it in the cd tree
405 set(__file ${_CD_NAME_ON_CD})
407 get_filename_component(__file ${item} NAME)
409 set_property(GLOBAL APPEND PROPERTY BOOTCDREGTEST_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
413 add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
416 #add it in reactos.cab
417 #dir_to_num(${_CD_DESTINATION} _num)
418 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
421 # add_dependencies(reactos_cab ${_CD_TARGET})
427 function(create_iso_lists)
428 # generate reactos.cab before anything else
429 get_property(_filelist GLOBAL PROPERTY REACTOS_CAB_DEPENDS)
431 # begin with reactos.inf. We want this command to be always executed, so we pretend it generates another file although it will never do.
433 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/__some_non_existent_file
434 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf
435 DEPENDS ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf reactos_cab_inf)
438 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
439 COMMAND native-cabman -C ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff -RC ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf -N -P ${REACTOS_SOURCE_DIR}
440 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf native-cabman ${_filelist})
442 add_custom_target(reactos_cab DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab)
443 add_dependencies(reactos_cab reactos_cab_inf)
447 FILE ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
449 NO_CAB FOR bootcd regtest)
452 FILE ${CMAKE_CURRENT_BINARY_DIR}/livecd.iso
456 get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
457 string(REPLACE ";" "\n" _filelist "${_filelist}")
458 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst "${_filelist}")
461 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcd.lst
462 INPUT ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst)
464 get_property(_filelist GLOBAL PROPERTY LIVECD_FILE_LIST)
465 string(REPLACE ";" "\n" _filelist "${_filelist}")
466 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst "${_filelist}")
469 OUTPUT ${REACTOS_BINARY_DIR}/boot/livecd.lst
470 INPUT ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst)
472 get_property(_filelist GLOBAL PROPERTY HYBRIDCD_FILE_LIST)
473 string(REPLACE ";" "\n" _filelist "${_filelist}")
474 file(APPEND ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst "${_filelist}")
477 OUTPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.lst
478 INPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst)
480 get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
481 string(REPLACE ";" "\n" _filelist "${_filelist}")
482 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst "${_filelist}")
485 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.lst
486 INPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst)
489 # Create module_clean targets
490 function(add_clean_target _target)
491 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
492 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
493 set(_clean_command make clean)
494 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
495 set(_clean_command nmake /nologo clean)
496 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
497 set(_clean_command ninja -t clean ${_target})
498 set(_clean_working_directory ${REACTOS_BINARY_DIR})
500 add_custom_target(${_target}_clean
501 COMMAND ${_clean_command}
502 WORKING_DIRECTORY ${_clean_working_directory}
503 COMMENT "Cleaning ${_target}")
507 function(add_library name)
508 _add_library(${name} ${ARGN})
509 add_clean_target(${name})
512 function(add_executable name)
513 _add_executable(${name} ${ARGN})
514 add_clean_target(${name})
516 elseif(USE_FOLDER_STRUCTURE)
517 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
518 string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
520 function(add_custom_target name)
521 _add_custom_target(${name} ${ARGN})
522 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
523 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
526 function(add_library name)
527 _add_library(${name} ${ARGN})
528 get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
529 if(_target_excluded AND ${name} MATCHES "^lib.*")
530 set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
532 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
533 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
537 function(add_executable name)
538 _add_executable(${name} ${ARGN})
539 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
540 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
544 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
545 function(concatenate_files _output _file1)
546 file(TO_NATIVE_PATH "${_output}" _real_output)
547 file(TO_NATIVE_PATH "${_file1}" _file_list)
548 foreach(_file ${ARGN})
549 file(TO_NATIVE_PATH "${_file}" _real_file)
550 set(_file_list "${_file_list} + ${_real_file}")
554 COMMAND cmd.exe /C "copy /Y /B ${_file_list} ${_real_output} > nul"
555 DEPENDS ${_file1} ${ARGN})
558 macro(concatenate_files _output)
561 COMMAND cat ${ARGN} > ${_output}
566 function(add_importlibs _module)
567 add_dependency_node(${_module})
569 if("${LIB}" MATCHES "msvcrt")
570 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
571 target_link_libraries(${_module} msvcrtex)
573 target_link_libraries(${_module} lib${LIB})
574 add_dependencies(${_module} lib${LIB})
575 add_dependency_edge(${_module} ${LIB})
579 function(set_module_type MODULE TYPE)
580 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
582 if(__module_UNPARSED_ARGUMENTS)
583 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
586 # Add the module to the module group list, if it is defined
587 if(DEFINED CURRENT_MODULE_GROUP)
588 set_property(GLOBAL APPEND PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST "${MODULE}")
591 # Set subsystem. Also take this as an occasion
592 # to error out if someone gave a non existing type
593 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll)
594 OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
595 set(__subsystem native)
596 elseif(${TYPE} STREQUAL win32cui)
597 set(__subsystem console)
598 elseif(${TYPE} STREQUAL win32gui)
599 set(__subsystem windows)
600 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
601 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
602 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
605 if(DEFINED __subsystem)
606 set_subsystem(${MODULE} ${__subsystem})
609 # Set the PE image version numbers from the NT OS version ReactOS is based on
611 add_target_link_flags(${MODULE} "/VERSION:5.01")
613 add_target_link_flags(${MODULE} "-Wl,--major-image-version,5 -Wl,--minor-image-version,01")
614 add_target_link_flags(${MODULE} "-Wl,--major-os-version,5 -Wl,--minor-os-version,01")
617 # Set unicode definitions
619 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
623 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
624 list(GET __module_ENTRYPOINT 0 __entrypoint)
625 list(LENGTH __module_ENTRYPOINT __length)
626 if(${__length} EQUAL 2)
627 list(GET __module_ENTRYPOINT 1 __entrystack)
628 elseif(NOT ${__length} EQUAL 1)
629 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
632 elseif(${TYPE} STREQUAL nativecui)
633 set(__entrypoint NtProcessStartup)
635 elseif(${TYPE} STREQUAL win32cui)
637 set(__entrypoint wmainCRTStartup)
639 set(__entrypoint mainCRTStartup)
641 elseif(${TYPE} STREQUAL win32gui)
643 set(__entrypoint wWinMainCRTStartup)
645 set(__entrypoint WinMainCRTStartup)
647 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
648 OR (${TYPE} STREQUAL cpl))
649 set(__entrypoint DllMainCRTStartup)
651 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
652 set(__entrypoint DriverEntry)
654 elseif(${TYPE} STREQUAL nativedll)
655 set(__entrypoint DllMain)
657 elseif(${TYPE} STREQUAL module)
661 if(DEFINED __entrypoint)
662 if(DEFINED __entrystack)
663 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
665 set_entrypoint(${MODULE} ${__entrypoint})
670 if(__module_IMAGEBASE)
671 set_image_base(${MODULE} ${__module_IMAGEBASE})
672 elseif(${TYPE} STREQUAL win32dll)
673 if(DEFINED baseaddress_${MODULE})
674 set_image_base(${MODULE} ${baseaddress_${MODULE}})
676 message(STATUS "${MODULE} has no base address")
678 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
679 set_image_base(${MODULE} 0x00010000)
682 # Now do some stuff which is specific to each type
683 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
684 add_dependencies(${MODULE} bugcodes xdk)
685 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
686 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
690 if(${TYPE} STREQUAL win32ocx)
691 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
694 if(${TYPE} STREQUAL cpl)
695 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
698 # Do compiler specific stuff
699 set_module_type_toolchain(${MODULE} ${TYPE})
702 function(start_module_group __name)
703 if(DEFINED CURRENT_MODULE_GROUP)
704 message(FATAL_ERROR "CURRENT_MODULE_GROUP is already set ('${CURRENT_MODULE_GROUP}')")
706 set(CURRENT_MODULE_GROUP ${__name} PARENT_SCOPE)
709 function(end_module_group)
710 get_property(__modulelist GLOBAL PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST)
711 add_custom_target(${CURRENT_MODULE_GROUP})
712 foreach(__module ${__modulelist})
713 add_dependencies(${CURRENT_MODULE_GROUP} ${__module})
715 set(CURRENT_MODULE_GROUP PARENT_SCOPE)
718 function(preprocess_file __in __out)
720 foreach(__def ${ARGN})
721 list(APPEND __arg -D${__def})
724 add_custom_command(OUTPUT ${_out}
725 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
728 add_custom_command(OUTPUT ${_out}
729 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
734 function(get_includes OUTPUT_VAR)
735 get_directory_property(_includes INCLUDE_DIRECTORIES)
736 foreach(arg ${_includes})
737 list(APPEND __tmp_var -I${arg})
739 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
742 function(get_defines OUTPUT_VAR)
743 get_directory_property(_defines COMPILE_DEFINITIONS)
744 foreach(arg ${_defines})
745 list(APPEND __tmp_var -D${arg})
747 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
751 function(add_object_library _target)
752 add_library(${_target} OBJECT ${ARGN})
755 function(add_object_library _target)
756 add_library(${_target} ${ARGN})
760 function(add_registry_inf)
761 # Add to the inf files list
762 foreach(_file ${ARGN})
763 set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
764 set_property(GLOBAL APPEND PROPERTY REGISTRY_INF_LIST ${_source_file})
768 function(create_registry_hives)
770 # Shortcut to the registry.inf file
771 set(_registry_inf "${CMAKE_BINARY_DIR}/boot/bootdata/registry.inf")
773 # Get the list of inf files
774 get_property(_inf_files GLOBAL PROPERTY REGISTRY_INF_LIST)
776 # Convert files to utf16le
777 foreach(_file ${_inf_files})
778 get_filename_component(_file_name ${_file} NAME_WE)
779 string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _converted_file "${_file}")
780 string(REPLACE ${_file_name} "${_file_name}_utf16" _converted_file ${_converted_file})
781 add_custom_command(OUTPUT ${_converted_file}
782 COMMAND native-utf16le ${_file} ${_converted_file}
783 DEPENDS native-utf16le ${_file})
784 list(APPEND _converted_files ${_converted_file})
787 # Concatenate all registry files to registry.inf
788 concatenate_files(${_registry_inf} ${_converted_files})
790 # Add registry.inf to bootcd
791 add_custom_target(registry_inf DEPENDS ${_registry_inf})
792 add_cd_file(TARGET registry_inf
793 FILE ${_registry_inf}
799 list(APPEND _livecd_inf_files
801 ${CMAKE_SOURCE_DIR}/boot/bootdata/livecd.inf
802 ${CMAKE_SOURCE_DIR}/boot/bootdata/hiveinst.inf)
805 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/sam
806 ${CMAKE_BINARY_DIR}/boot/bootdata/default
807 ${CMAKE_BINARY_DIR}/boot/bootdata/security
808 ${CMAKE_BINARY_DIR}/boot/bootdata/software
809 ${CMAKE_BINARY_DIR}/boot/bootdata/system
810 ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
811 COMMAND native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata ${_livecd_inf_files}
812 DEPENDS native-mkhive ${_livecd_inf_files})
814 add_custom_target(livecd_hives
815 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/sam
816 ${CMAKE_BINARY_DIR}/boot/bootdata/default
817 ${CMAKE_BINARY_DIR}/boot/bootdata/security
818 ${CMAKE_BINARY_DIR}/boot/bootdata/software
819 ${CMAKE_BINARY_DIR}/boot/bootdata/system
820 ${CMAKE_BINARY_DIR}/boot/bootdata/BCD)
823 FILE ${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
829 DESTINATION reactos/system32/config
833 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
837 FOR bootcd regtest livecd)
842 set(ROSSYM_LIB "rossym")
847 function(add_rc_deps _target_rc)
848 set_source_files_properties(${_target_rc} PROPERTIES OBJECT_DEPENDS "${ARGN}")
851 add_custom_target(rostests_install COMMAND ${CMAKE_COMMAND} -DCOMPONENT=rostests -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
852 function(add_rostests_file)
853 cmake_parse_arguments(_ROSTESTS "" "RENAME;SUBDIR;TARGET" "FILE" ${ARGN})
854 if(NOT (_ROSTESTS_TARGET OR _ROSTESTS_FILE))
855 message(FATAL_ERROR "You must provide a target or a file to install!")
858 set(_ROSTESTS_NAME_ON_CD "${_ROSTESTS_RENAME}")
859 if(NOT _ROSTESTS_FILE)
860 set(_ROSTESTS_FILE "$<TARGET_FILE:${_ROSTESTS_TARGET}>")
861 if(NOT _ROSTESTS_RENAME)
862 set(_ROSTESTS_NAME_ON_CD "$<TARGET_FILE_NAME:${_ROSTESTS_TARGET}>")
865 if(NOT _ROSTESTS_RENAME)
866 get_filename_component(_ROSTESTS_NAME_ON_CD ${_ROSTESTS_FILE} NAME)
871 set(_ROSTESTS_SUBDIR "/${_ROSTESTS_SUBDIR}")
875 add_cd_file(TARGET ${_ROSTESTS_TARGET} FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
877 add_cd_file(FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
880 if(DEFINED ENV{ROSTESTS_INSTALL})
882 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests RENAME ${_ROSTESTS_RENAME})
884 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests)