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