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