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|MODULE_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|MODULE_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)
167 # Please keep the numbering in this list in sync with
168 # boot/bootdata/packages/reactos.dff.in
170 macro(dir_to_num dir var)
171 if(${dir} STREQUAL reactos)
173 elseif(${dir} STREQUAL reactos/system32)
175 elseif(${dir} STREQUAL reactos/system32/drivers)
177 elseif(${dir} STREQUAL reactos/Fonts)
179 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
181 elseif(${dir} STREQUAL reactos/inf)
183 elseif(${dir} STREQUAL reactos/bin)
185 elseif(${dir} STREQUAL reactos/bin/testdata)
187 elseif(${dir} STREQUAL reactos/bin/suppl)
189 elseif(${dir} STREQUAL reactos/media)
191 elseif(${dir} STREQUAL reactos/Microsoft.NET)
193 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
195 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
197 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
199 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
201 elseif(${dir} STREQUAL reactos/Resources)
203 elseif(${dir} STREQUAL reactos/Resources/Themes)
205 elseif(${dir} STREQUAL reactos/system32/wbem)
207 elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
209 elseif(${dir} STREQUAL reactos/Help)
211 elseif(${dir} STREQUAL reactos/Config)
213 elseif(${dir} STREQUAL reactos/Cursors)
215 elseif(${dir} STREQUAL reactos/system32/ShellExt)
217 elseif(${dir} STREQUAL reactos/Temp)
219 elseif(${dir} STREQUAL reactos/system32/spool)
221 elseif(${dir} STREQUAL reactos/system32/spool/drivers)
223 elseif(${dir} STREQUAL reactos/system32/spool/drivers/color)
225 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86)
227 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86/3)
229 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs)
231 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs/w32x86)
233 elseif(${dir} STREQUAL reactos/system32/spool/PRINTERS)
235 elseif(${dir} STREQUAL reactos/system32/wbem/Repository)
237 elseif(${dir} STREQUAL reactos/system32/wbem/Repository/FS)
239 elseif(${dir} STREQUAL reactos/system32/wbem/mof/good)
241 elseif(${dir} STREQUAL reactos/system32/wbem/mof/bad)
243 elseif(${dir} STREQUAL reactos/system32/wbem/AdStatus)
245 elseif(${dir} STREQUAL reactos/system32/wbem/xml)
247 elseif(${dir} STREQUAL reactos/system32/wbem/Logs)
249 elseif(${dir} STREQUAL reactos/system32/wbem/AutoRecover)
251 elseif(${dir} STREQUAL reactos/system32/wbem/snmp)
253 elseif(${dir} STREQUAL reactos/system32/wbem/Performance)
255 elseif(${dir} STREQUAL reactos/twain_32)
257 elseif(${dir} STREQUAL reactos/repair)
259 elseif(${dir} STREQUAL reactos/Web)
261 elseif(${dir} STREQUAL reactos/Web/Wallpaper)
263 elseif(${dir} STREQUAL reactos/Prefetch)
265 elseif(${dir} STREQUAL reactos/security)
267 elseif(${dir} STREQUAL reactos/security/Database)
269 elseif(${dir} STREQUAL reactos/security/logs)
271 elseif(${dir} STREQUAL reactos/security/templates)
273 elseif(${dir} STREQUAL reactos/system32/CatRoot)
275 elseif(${dir} STREQUAL reactos/system32/CatRoot2)
277 elseif(${dir} STREQUAL reactos/AppPatch)
279 elseif(${dir} STREQUAL reactos/winsxs)
281 elseif(${dir} STREQUAL reactos/winsxs/manifests)
283 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.2600.2982_none_deadbeef)
285 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef)
287 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.23038_none_deadbeef)
289 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.apisets_6595b64144ccf1df_1.0.0.0_none_deadbeef)
291 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.newapi_6595b64144ccf1df_1.0.0.0_none_deadbeef)
293 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.14393.0_none_deadbeef)
295 elseif(${dir} STREQUAL reactos/Resources/Themes/Modern)
297 elseif(${dir} STREQUAL reactos/3rdParty)
299 elseif(${dir} STREQUAL reactos/Resources/Themes/Lunar)
301 elseif(${dir} STREQUAL reactos/Resources/Themes/Mizu)
304 message(FATAL_ERROR "Wrong destination: ${dir}")
308 function(add_cd_file)
309 cmake_parse_arguments(_CD "NO_CAB;NOT_IN_HYBRIDCD" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
310 if(NOT (_CD_TARGET OR _CD_FILE))
311 message(FATAL_ERROR "You must provide a target or a file to install!")
314 if(NOT _CD_DESTINATION)
315 message(FATAL_ERROR "You must provide a destination")
316 elseif(${_CD_DESTINATION} STREQUAL root)
317 set(_CD_DESTINATION "")
321 message(FATAL_ERROR "You must provide a cd name (or \"all\" for all of them) to install the file on!")
324 # get file if we need to
326 set(_CD_FILE "$<TARGET_FILE:${_CD_TARGET}>")
327 if(NOT _CD_NAME_ON_CD)
328 set(_CD_NAME_ON_CD "$<TARGET_FILE_NAME:${_CD_TARGET}>")
332 # do we add it to all CDs?
333 list(FIND _CD_FOR all __cd)
334 if(NOT __cd EQUAL -1)
335 list(REMOVE_AT _CD_FOR __cd)
336 list(INSERT _CD_FOR __cd "bootcd;livecd;regtest")
339 # do we add it to bootcd?
340 list(FIND _CD_FOR bootcd __cd)
341 if(NOT __cd EQUAL -1)
342 # whether or not we should put it in reactos.cab or directly on cd
345 foreach(item ${_CD_FILE})
347 # rename it in the cd tree
348 set(__file ${_CD_NAME_ON_CD})
350 get_filename_component(__file ${item} NAME)
352 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
353 # add it also into the hybridcd if not specified otherwise
354 if(NOT _CD_NOT_IN_HYBRIDCD)
355 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "bootcd/${_CD_DESTINATION}/${__file}=${item}")
360 add_dependencies(bootcd ${_CD_TARGET} registry_inf)
363 # add it in reactos.cab
364 dir_to_num(${_CD_DESTINATION} _num)
365 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.cmake "\"${_CD_FILE}\" ${_num}\n")
366 # manage dependency - target level
368 add_dependencies(reactos_cab_inf ${_CD_TARGET})
370 # manage dependency - file level
371 set_property(GLOBAL APPEND PROPERTY REACTOS_CAB_DEPENDS ${_CD_FILE})
375 # do we add it to livecd?
376 list(FIND _CD_FOR livecd __cd)
377 if(NOT __cd EQUAL -1)
380 add_dependencies(livecd ${_CD_TARGET} registry_inf)
382 foreach(item ${_CD_FILE})
384 # rename it in the cd tree
385 set(__file ${_CD_NAME_ON_CD})
387 get_filename_component(__file ${item} NAME)
389 set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
390 # add it also into the hybridcd if not specified otherwise
391 if(NOT _CD_NOT_IN_HYBRIDCD)
392 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "livecd/${_CD_DESTINATION}/${__file}=${item}")
397 # do we need also to add it to hybridcd?
398 list(FIND _CD_FOR hybridcd __cd)
399 if(NOT __cd EQUAL -1)
402 add_dependencies(hybridcd ${_CD_TARGET})
404 foreach(item ${_CD_FILE})
406 # rename it in the cd tree
407 set(__file ${_CD_NAME_ON_CD})
409 get_filename_component(__file ${item} NAME)
411 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
413 endif() #end hybridcd
415 # do we add it to regtest?
416 list(FIND _CD_FOR regtest __cd)
417 if(NOT __cd EQUAL -1)
418 # whether or not we should put it in reactos.cab or directly on cd
421 foreach(item ${_CD_FILE})
423 # rename it in the cd tree
424 set(__file ${_CD_NAME_ON_CD})
426 get_filename_component(__file ${item} NAME)
428 set_property(GLOBAL APPEND PROPERTY BOOTCDREGTEST_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
432 add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
435 #add it in reactos.cab
436 #dir_to_num(${_CD_DESTINATION} _num)
437 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
440 # add_dependencies(reactos_cab ${_CD_TARGET})
446 function(create_iso_lists)
447 # generate reactos.cab before anything else
448 get_property(_filelist GLOBAL PROPERTY REACTOS_CAB_DEPENDS)
450 # begin with reactos.inf. We want this command to be always executed, so we pretend it generates another file although it will never do.
452 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/__some_non_existent_file
453 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf
454 DEPENDS ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf reactos_cab_inf)
457 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
458 COMMAND native-cabman -C ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff -RC ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf -N -P ${REACTOS_SOURCE_DIR}
459 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf native-cabman ${_filelist})
461 add_custom_target(reactos_cab DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab)
462 add_dependencies(reactos_cab reactos_cab_inf)
466 FILE ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
468 NO_CAB FOR bootcd regtest)
471 FILE ${CMAKE_CURRENT_BINARY_DIR}/livecd.iso
475 get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
476 string(REPLACE ";" "\n" _filelist "${_filelist}")
477 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst "${_filelist}")
480 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcd.$<CONFIG>.lst
481 INPUT ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst)
483 get_property(_filelist GLOBAL PROPERTY LIVECD_FILE_LIST)
484 string(REPLACE ";" "\n" _filelist "${_filelist}")
485 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst "${_filelist}")
488 OUTPUT ${REACTOS_BINARY_DIR}/boot/livecd.$<CONFIG>.lst
489 INPUT ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst)
491 get_property(_filelist GLOBAL PROPERTY HYBRIDCD_FILE_LIST)
492 string(REPLACE ";" "\n" _filelist "${_filelist}")
493 file(APPEND ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst "${_filelist}")
496 OUTPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.$<CONFIG>.lst
497 INPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst)
499 get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
500 string(REPLACE ";" "\n" _filelist "${_filelist}")
501 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst "${_filelist}")
504 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.$<CONFIG>.lst
505 INPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst)
508 # Create module_clean targets
509 function(add_clean_target _target)
510 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
511 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
512 set(_clean_command make clean)
513 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
514 set(_clean_command nmake /nologo clean)
515 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
516 set(_clean_command ninja -t clean ${_target})
517 set(_clean_working_directory ${REACTOS_BINARY_DIR})
519 add_custom_target(${_target}_clean
520 COMMAND ${_clean_command}
521 WORKING_DIRECTORY ${_clean_working_directory}
522 COMMENT "Cleaning ${_target}")
526 function(add_library name)
527 _add_library(${name} ${ARGN})
528 add_clean_target(${name})
529 # cmake adds a module_EXPORTS define when compiling a module or a shared library. We don't use that.
530 get_target_property(_type ${name} TYPE)
531 if (_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
532 set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "")
536 function(add_executable name)
537 _add_executable(${name} ${ARGN})
538 add_clean_target(${name})
540 elseif(USE_FOLDER_STRUCTURE)
541 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
542 string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
544 function(add_custom_target name)
545 _add_custom_target(${name} ${ARGN})
546 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
547 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
550 function(add_library name)
551 _add_library(${name} ${ARGN})
552 get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
553 if(_target_excluded AND ${name} MATCHES "^lib.*")
554 set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
556 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
557 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
559 # cmake adds a module_EXPORTS define when compiling a module or a shared library. We don't use that.
560 get_target_property(_type ${name} TYPE)
561 if (_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
562 set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "")
566 function(add_executable name)
567 _add_executable(${name} ${ARGN})
568 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
569 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
572 function(add_library name)
573 _add_library(${name} ${ARGN})
574 # cmake adds a module_EXPORTS define when compiling a module or a shared library. We don't use that.
575 get_target_property(_type ${name} TYPE)
576 if (_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
577 set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "")
582 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
583 function(concatenate_files _output _file1)
584 file(TO_NATIVE_PATH "${_output}" _real_output)
585 file(TO_NATIVE_PATH "${_file1}" _file_list)
586 foreach(_file ${ARGN})
587 file(TO_NATIVE_PATH "${_file}" _real_file)
588 set(_file_list "${_file_list} + ${_real_file}")
592 COMMAND cmd.exe /C "copy /Y /B ${_file_list} ${_real_output} > nul"
593 DEPENDS ${_file1} ${ARGN})
596 macro(concatenate_files _output)
599 COMMAND cat ${ARGN} > ${_output}
604 function(add_importlibs _module)
605 add_dependency_node(${_module})
607 if("${LIB}" MATCHES "msvcrt")
608 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
609 target_link_libraries(${_module} msvcrtex)
611 target_link_libraries(${_module} lib${LIB})
612 add_dependencies(${_module} lib${LIB})
613 add_dependency_edge(${_module} ${LIB})
617 function(set_module_type MODULE TYPE)
618 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
620 if(__module_UNPARSED_ARGUMENTS)
621 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
624 # Add the module to the module group list, if it is defined
625 if(DEFINED CURRENT_MODULE_GROUP)
626 set_property(GLOBAL APPEND PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST "${MODULE}")
629 # Set subsystem. Also take this as an occasion
630 # to error out if someone gave a non existing type
631 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll)
632 OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
633 set(__subsystem native)
634 elseif(${TYPE} STREQUAL win32cui)
635 set(__subsystem console)
636 elseif(${TYPE} STREQUAL win32gui)
637 set(__subsystem windows)
638 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
639 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
640 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
643 if(DEFINED __subsystem)
644 set_subsystem(${MODULE} ${__subsystem})
647 # Set the PE image version numbers from the NT OS version ReactOS is based on
649 add_target_link_flags(${MODULE} "/VERSION:5.01")
651 add_target_link_flags(${MODULE} "-Wl,--major-image-version,5 -Wl,--minor-image-version,01")
652 add_target_link_flags(${MODULE} "-Wl,--major-os-version,5 -Wl,--minor-os-version,01")
655 # Set unicode definitions
657 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
661 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
662 list(GET __module_ENTRYPOINT 0 __entrypoint)
663 list(LENGTH __module_ENTRYPOINT __length)
664 if(${__length} EQUAL 2)
665 list(GET __module_ENTRYPOINT 1 __entrystack)
666 elseif(NOT ${__length} EQUAL 1)
667 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
670 elseif(${TYPE} STREQUAL nativecui)
671 set(__entrypoint NtProcessStartup)
673 elseif(${TYPE} STREQUAL win32cui)
675 set(__entrypoint wmainCRTStartup)
677 set(__entrypoint mainCRTStartup)
679 elseif(${TYPE} STREQUAL win32gui)
681 set(__entrypoint wWinMainCRTStartup)
683 set(__entrypoint WinMainCRTStartup)
685 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
686 OR (${TYPE} STREQUAL cpl))
687 set(__entrypoint DllMainCRTStartup)
689 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
690 set(__entrypoint DriverEntry)
692 elseif(${TYPE} STREQUAL nativedll)
693 set(__entrypoint DllMain)
695 elseif(${TYPE} STREQUAL module)
699 if(DEFINED __entrypoint)
700 if(DEFINED __entrystack)
701 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
703 set_entrypoint(${MODULE} ${__entrypoint})
708 if(__module_IMAGEBASE)
709 set_image_base(${MODULE} ${__module_IMAGEBASE})
710 elseif(${TYPE} STREQUAL win32dll)
711 if(DEFINED baseaddress_${MODULE})
712 set_image_base(${MODULE} ${baseaddress_${MODULE}})
714 message(STATUS "${MODULE} has no base address")
716 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
717 set_image_base(${MODULE} 0x00010000)
720 # Now do some stuff which is specific to each type
721 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
722 add_dependencies(${MODULE} bugcodes xdk)
723 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
724 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
728 if(${TYPE} STREQUAL win32ocx)
729 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
732 if(${TYPE} STREQUAL cpl)
733 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
736 # Do compiler specific stuff
737 set_module_type_toolchain(${MODULE} ${TYPE})
740 function(start_module_group __name)
741 if(DEFINED CURRENT_MODULE_GROUP)
742 message(FATAL_ERROR "CURRENT_MODULE_GROUP is already set ('${CURRENT_MODULE_GROUP}')")
744 set(CURRENT_MODULE_GROUP ${__name} PARENT_SCOPE)
747 function(end_module_group)
748 get_property(__modulelist GLOBAL PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST)
749 add_custom_target(${CURRENT_MODULE_GROUP})
750 foreach(__module ${__modulelist})
751 add_dependencies(${CURRENT_MODULE_GROUP} ${__module})
753 set(CURRENT_MODULE_GROUP PARENT_SCOPE)
756 function(preprocess_file __in __out)
758 foreach(__def ${ARGN})
759 list(APPEND __arg -D${__def})
762 add_custom_command(OUTPUT ${_out}
763 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
766 add_custom_command(OUTPUT ${_out}
767 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
772 function(get_includes OUTPUT_VAR)
773 get_directory_property(_includes INCLUDE_DIRECTORIES)
774 foreach(arg ${_includes})
775 list(APPEND __tmp_var -I${arg})
777 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
780 function(get_defines OUTPUT_VAR)
781 get_directory_property(_defines COMPILE_DEFINITIONS)
782 foreach(arg ${_defines})
783 list(APPEND __tmp_var -D${arg})
785 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
789 function(add_object_library _target)
790 add_library(${_target} OBJECT ${ARGN})
793 function(add_object_library _target)
794 add_library(${_target} ${ARGN})
798 function(add_registry_inf)
799 # Add to the inf files list
800 foreach(_file ${ARGN})
801 set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
802 set_property(GLOBAL APPEND PROPERTY REGISTRY_INF_LIST ${_source_file})
806 function(create_registry_hives)
808 # Shortcut to the registry.inf file
809 set(_registry_inf "${CMAKE_BINARY_DIR}/boot/bootdata/registry.inf")
811 # Get the list of inf files
812 get_property(_inf_files GLOBAL PROPERTY REGISTRY_INF_LIST)
814 # Convert files to utf16le
815 foreach(_file ${_inf_files})
816 get_filename_component(_file_name ${_file} NAME_WE)
817 string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _converted_file "${_file}")
818 string(REPLACE ${_file_name} "${_file_name}_utf16" _converted_file ${_converted_file})
819 add_custom_command(OUTPUT ${_converted_file}
820 COMMAND native-utf16le ${_file} ${_converted_file}
821 DEPENDS native-utf16le ${_file})
822 list(APPEND _converted_files ${_converted_file})
825 # Concatenate all registry files to registry.inf
826 concatenate_files(${_registry_inf} ${_converted_files})
828 # Add registry.inf to bootcd
829 add_custom_target(registry_inf DEPENDS ${_registry_inf})
830 add_cd_file(TARGET registry_inf
831 FILE ${_registry_inf}
836 # BootCD setup system hive
838 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV
839 COMMAND native-mkhive -h:SETUPREG -u -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf ${CMAKE_SOURCE_DIR}/boot/bootdata/setupreg.inf
840 DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf)
842 add_custom_target(bootcd_hives
843 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV)
846 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV
853 list(APPEND _livecd_inf_files
855 ${CMAKE_SOURCE_DIR}/boot/bootdata/livecd.inf
856 ${CMAKE_SOURCE_DIR}/boot/bootdata/hiveinst.inf)
859 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/system
860 ${CMAKE_BINARY_DIR}/boot/bootdata/software
861 ${CMAKE_BINARY_DIR}/boot/bootdata/default
862 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
863 ${CMAKE_BINARY_DIR}/boot/bootdata/security
864 COMMAND native-mkhive -h:SYSTEM,SOFTWARE,DEFAULT,SAM,SECURITY -d:${CMAKE_BINARY_DIR}/boot/bootdata ${_livecd_inf_files}
865 DEPENDS native-mkhive ${_livecd_inf_files})
867 add_custom_target(livecd_hives
868 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/system
869 ${CMAKE_BINARY_DIR}/boot/bootdata/software
870 ${CMAKE_BINARY_DIR}/boot/bootdata/default
871 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
872 ${CMAKE_BINARY_DIR}/boot/bootdata/security)
875 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/system
876 ${CMAKE_BINARY_DIR}/boot/bootdata/software
877 ${CMAKE_BINARY_DIR}/boot/bootdata/default
878 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
879 ${CMAKE_BINARY_DIR}/boot/bootdata/security
881 DESTINATION reactos/system32/config
886 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
887 COMMAND native-mkhive -h:BCD -u -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf
888 DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf)
890 add_custom_target(bcd_hive
891 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/BCD)
894 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
898 FOR bootcd regtest livecd)
903 set(ROSSYM_LIB "rossym")
908 function(add_rc_deps _target_rc)
909 set_source_files_properties(${_target_rc} PROPERTIES OBJECT_DEPENDS "${ARGN}")
912 add_custom_target(rostests_install COMMAND ${CMAKE_COMMAND} -DCOMPONENT=rostests -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
913 function(add_rostests_file)
914 cmake_parse_arguments(_ROSTESTS "" "RENAME;SUBDIR;TARGET" "FILE" ${ARGN})
915 if(NOT (_ROSTESTS_TARGET OR _ROSTESTS_FILE))
916 message(FATAL_ERROR "You must provide a target or a file to install!")
919 set(_ROSTESTS_NAME_ON_CD "${_ROSTESTS_RENAME}")
920 if(NOT _ROSTESTS_FILE)
921 set(_ROSTESTS_FILE "$<TARGET_FILE:${_ROSTESTS_TARGET}>")
922 if(NOT _ROSTESTS_RENAME)
923 set(_ROSTESTS_NAME_ON_CD "$<TARGET_FILE_NAME:${_ROSTESTS_TARGET}>")
926 if(NOT _ROSTESTS_RENAME)
927 get_filename_component(_ROSTESTS_NAME_ON_CD ${_ROSTESTS_FILE} NAME)
932 set(_ROSTESTS_SUBDIR "/${_ROSTESTS_SUBDIR}")
936 add_cd_file(TARGET ${_ROSTESTS_TARGET} FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
938 add_cd_file(FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
941 if(DEFINED ENV{ROSTESTS_INSTALL})
943 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests RENAME ${_ROSTESTS_RENAME})
945 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests)