[REACTOS]: Add a "testdata" subdirectory in %SystemRoot%\bin\ where you can put all...
[reactos.git] / reactos / cmake / CMakeMacros.cmake
index 4737656..a59bb26 100644 (file)
@@ -72,6 +72,8 @@ macro(set_cpp)
         if(MSVC)
             add_definitions(-DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++)
             include_directories(${REACTOS_SOURCE_DIR}/include/c++/stlport)
+        else()
+            replace_compile_flags("-nostdinc" " ")
         endif()
     endif()
 
@@ -169,7 +171,7 @@ macro(dir_to_num dir var)
         set(${var} 6)
     elseif(${dir} STREQUAL reactos/bin)
         set(${var} 7)
-    elseif(${dir} STREQUAL reactos/bin/data)
+    elseif(${dir} STREQUAL reactos/bin/testdata)
         set(${var} 8)
     elseif(${dir} STREQUAL reactos/media)
         set(${var} 9)
@@ -189,13 +191,83 @@ macro(dir_to_num dir var)
         set(${var} 16)
     elseif(${dir} STREQUAL reactos/system32/wbem)
         set(${var} 17)
+    elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
+        set(${var} 18)
+    elseif(${dir} STREQUAL reactos/Help)
+        set(${var} 19)
+    elseif(${dir} STREQUAL reactos/Config)
+        set(${var} 20)
+    elseif(${dir} STREQUAL reactos/Cursors)
+        set(${var} 21)
+    elseif(${dir} STREQUAL reactos/system32/ShellExt)
+        set(${var} 22)
+    elseif(${dir} STREQUAL reactos/Temp)
+        set(${var} 23)
+    elseif(${dir} STREQUAL reactos/system32/spool)
+        set(${var} 24)
+    elseif(${dir} STREQUAL reactos/system32/spool/drivers)
+        set(${var} 25)
+    elseif(${dir} STREQUAL reactos/system32/spool/drivers/color)
+        set(${var} 26)
+    elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86)
+        set(${var} 27)
+    elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86/3)
+        set(${var} 28)
+    elseif(${dir} STREQUAL reactos/system32/spool/prtprocs)
+        set(${var} 29)
+    elseif(${dir} STREQUAL reactos/system32/spool/prtprocs/w32x86)
+        set(${var} 30)
+    elseif(${dir} STREQUAL reactos/system32/spool/PRINTERS)
+        set(${var} 31)
+    elseif(${dir} STREQUAL reactos/system32/wbem/Repository)
+        set(${var} 32)
+    elseif(${dir} STREQUAL reactos/system32/wbem/Repository/FS)
+        set(${var} 33)
+    elseif(${dir} STREQUAL reactos/system32/wbem/mof/good)
+        set(${var} 34)
+    elseif(${dir} STREQUAL reactos/system32/wbem/mof/bad)
+        set(${var} 35)
+    elseif(${dir} STREQUAL reactos/system32/wbem/AdStatus)
+        set(${var} 36)
+    elseif(${dir} STREQUAL reactos/system32/wbem/xml)
+        set(${var} 37)
+    elseif(${dir} STREQUAL reactos/system32/wbem/Logs)
+        set(${var} 38)
+    elseif(${dir} STREQUAL reactos/system32/wbem/AutoRecover)
+        set(${var} 39)
+    elseif(${dir} STREQUAL reactos/system32/wbem/snmp)
+        set(${var} 40)
+    elseif(${dir} STREQUAL reactos/system32/wbem/Performance)
+        set(${var} 41)
+    elseif(${dir} STREQUAL reactos/twain_32)
+        set(${var} 42)
+    elseif(${dir} STREQUAL reactos/repair)
+        set(${var} 43)
+    elseif(${dir} STREQUAL reactos/Web)
+        set(${var} 44)
+    elseif(${dir} STREQUAL reactos/Web/Wallpaper)
+        set(${var} 45)
+    elseif(${dir} STREQUAL reactos/Prefetch)
+        set(${var} 46)
+    elseif(${dir} STREQUAL reactos/security)
+        set(${var} 47)
+    elseif(${dir} STREQUAL reactos/security/Database)
+        set(${var} 48)
+    elseif(${dir} STREQUAL reactos/security/logs)
+        set(${var} 49)
+    elseif(${dir} STREQUAL reactos/security/templates)
+        set(${var} 50)
+    elseif(${dir} STREQUAL reactos/system32/CatRoot)
+        set(${var} 51)
+    elseif(${dir} STREQUAL reactos/system32/CatRoot2)
+        set(${var} 52)
     else()
         message(FATAL_ERROR "Wrong destination: ${dir}")
     endif()
 endmacro()
 
 function(add_cd_file)
-    cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
+    cmake_parse_arguments(_CD "NO_CAB;NOT_IN_HYBRIDCD" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
     if(NOT (_CD_TARGET OR _CD_FILE))
         message(FATAL_ERROR "You must provide a target or a file to install!")
     endif()
@@ -216,8 +288,10 @@ function(add_cd_file)
     endif()
 
     #do we add it to all CDs?
-    if(_CD_FOR STREQUAL all)
-        set(_CD_FOR "bootcd;livecd;regtest")
+    list(FIND _CD_FOR all __cd)
+    if(NOT __cd EQUAL -1)
+        list(REMOVE_AT _CD_FOR __cd)
+        list(INSERT _CD_FOR __cd "bootcd;livecd;regtest")
     endif()
 
     #do we add it to bootcd?
@@ -234,10 +308,14 @@ function(add_cd_file)
                     get_filename_component(__file ${item} NAME)
                 endif()
                 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
+                #add it also into the hybridcd if not specified otherwise
+                if(NOT _CD_NOT_IN_HYBRIDCD)
+                    set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "bootcd/${_CD_DESTINATION}/${__file}=${item}")
+                endif()
             endforeach()
             if(_CD_TARGET)
                 #manage dependency
-                add_dependencies(bootcd ${_CD_TARGET})
+                add_dependencies(bootcd ${_CD_TARGET} registry_inf)
             endif()
         else()
             #add it in reactos.cab
@@ -246,9 +324,11 @@ function(add_cd_file)
             file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${__relative_file}\" ${_num}\n")
             unset(__relative_file)
             if(_CD_TARGET)
-                #manage dependency
-                add_dependencies(reactos_cab ${_CD_TARGET})
+                #manage dependency - target level
+                add_dependencies(reactos_cab_inf ${_CD_TARGET})
             endif()
+            # manage dependency - file level
+            set_property(GLOBAL APPEND PROPERTY REACTOS_CAB_DEPENDS ${_CD_FILE})
         endif()
     endif() #end bootcd
 
@@ -257,7 +337,7 @@ function(add_cd_file)
     if(NOT __cd EQUAL -1)
         #manage dependency
         if(_CD_TARGET)
-            add_dependencies(livecd ${_CD_TARGET})
+            add_dependencies(livecd ${_CD_TARGET} registry_inf)
         endif()
         foreach(item ${_CD_FILE})
             if(_CD_NAME_ON_CD)
@@ -267,9 +347,27 @@ function(add_cd_file)
                 get_filename_component(__file ${item} NAME)
             endif()
             set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
+            #add it also into the hybridcd if not specified otherwise
+            if(NOT _CD_NOT_IN_HYBRIDCD)
+                set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "livecd/${_CD_DESTINATION}/${__file}=${item}")
+            endif()
         endforeach()
     endif() #end livecd
 
+    #do we need also to add it to hybridcd?
+    list(FIND _CD_FOR hybridcd __cd)
+    if(NOT __cd EQUAL -1)
+        foreach(item ${_CD_FILE})
+            if(_CD_NAME_ON_CD)
+                #rename it in the cd tree
+                set(__file ${_CD_NAME_ON_CD})
+            else()
+                get_filename_component(__file ${item} NAME)
+            endif()
+            set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
+        endforeach()
+    endif() #end hybridcd
+
     #do we add it to regtest?
     list(FIND _CD_FOR regtest __cd)
     if(NOT __cd EQUAL -1)
@@ -287,7 +385,7 @@ function(add_cd_file)
             endforeach()
             if(_CD_TARGET)
                 #manage dependency
-                add_dependencies(bootcdregtest ${_CD_TARGET})
+                add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
             endif()
         else()
             #add it in reactos.cab
@@ -302,6 +400,34 @@ function(add_cd_file)
 endfunction()
 
 function(create_iso_lists)
+    # generate reactos.cab before anything else
+    get_property(_filelist GLOBAL PROPERTY REACTOS_CAB_DEPENDS)
+
+    # begin with reactos.inf. We want this command to be always executed, so we pretend it generates another file although it will never do.
+    add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/__some_non_existent_file
+        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf
+        DEPENDS ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf reactos_cab_inf)
+
+    add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
+        COMMAND native-cabman -C ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff -RC ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf -N -P ${REACTOS_SOURCE_DIR}
+        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf native-cabman ${_filelist})
+
+    add_custom_target(reactos_cab DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab)
+    add_dependencies(reactos_cab reactos_cab_inf)
+
+    add_cd_file(
+        TARGET reactos_cab
+        FILE ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
+        DESTINATION reactos
+        NO_CAB FOR bootcd regtest)
+
+    add_cd_file(
+        FILE ${CMAKE_CURRENT_BINARY_DIR}/livecd.iso
+        DESTINATION livecd
+        FOR hybridcd)
+
     get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
     string(REPLACE ";" "\n" _filelist "${_filelist}")
     file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.lst "${_filelist}")
@@ -312,6 +438,11 @@ function(create_iso_lists)
     file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.lst "${_filelist}")
     unset(_filelist)
 
+    get_property(_filelist GLOBAL PROPERTY HYBRIDCD_FILE_LIST)
+    string(REPLACE ";" "\n" _filelist "${_filelist}")
+    file(APPEND ${REACTOS_BINARY_DIR}/boot/hybridcd.lst "${_filelist}")
+    unset(_filelist)
+
     get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
     string(REPLACE ";" "\n" _filelist "${_filelist}")
     file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.lst "${_filelist}")
@@ -374,30 +505,24 @@ elseif(USE_FOLDER_STRUCTURE)
 endif()
 
 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
-    macro(to_win_path _cmake_path _native_path)
-        string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
-    endmacro()
-
-    # yeah the parameter mess sucks, but thats what works...
-    function(concatenate_files _file1 _target2 _output)
-        get_target_property(_file2 ${_target2} LOCATION)
-        to_win_path("${_file1}" _real_file1)
-        to_win_path("${_file2}" _real_file2)
-        to_win_path("${_output}" _real_output)
+    function(concatenate_files _output _file1)
+        file(TO_NATIVE_PATH "${_output}" _real_output)
+        file(TO_NATIVE_PATH "${_file1}" _file_list)
+        foreach(_file ${ARGN})
+            file(TO_NATIVE_PATH "${_file}" _real_file)
+            set(_file_list "${_file_list} + ${_real_file}")
+        endforeach()
         add_custom_command(
             OUTPUT ${_output}
-            COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
-            DEPENDS ${_file1}
-            DEPENDS ${_target2})
+            COMMAND cmd.exe /C "copy /Y /B ${_file_list} ${_real_output} > nul"
+            DEPENDS ${_file1} ${ARGN})
     endfunction()
 else()
-    macro(concatenate_files _file1 _target2 _output)
-        get_target_property(_file2 ${_target2} LOCATION)
+    macro(concatenate_files _output)
         add_custom_command(
             OUTPUT ${_output}
-            COMMAND cat ${_file1} ${_file2} > ${_output}
-            DEPENDS ${_file1}
-            DEPENDS ${_target2})
+            COMMAND cat ${ARGN} > ${_output}
+            DEPENDS ${ARGN})
     endmacro()
 endif()
 
@@ -415,32 +540,26 @@ function(add_importlibs _module)
 endfunction()
 
 function(set_module_type MODULE TYPE)
-    cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
+    cmake_parse_arguments(__module "UNICODE;HOTPATCHABLE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
 
     if(__module_UNPARSED_ARGUMENTS)
         message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
     endif()
 
+    # Add the module to the module group list, if it is defined
+    if(DEFINED CURRENT_MODULE_GROUP)
+        set_property(GLOBAL APPEND PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST "${MODULE}")
+    endif()
+
     # Set subsystem. Also take this as an occasion
     # to error out if someone gave a non existing type
-    if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
+    if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll)
+            OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
         set(__subsystem native)
     elseif(${TYPE} STREQUAL win32cui)
         set(__subsystem console)
     elseif(${TYPE} STREQUAL win32gui)
         set(__subsystem windows)
-    elseif(${TYPE} STREQUAL kbdlayout)
-        set_entrypoint(${MODULE} 0)
-        set_image_base(${MODULE} 0x5FFF0000)
-        set_subsystem(${MODULE} native)
-        if (MSVC)
-            # Merge the .text and .rdata section into the .data section
-            add_target_link_flags(${MODULE} "/ignore:4254 /SECTION:.data,ER /MERGE:.text=.data /MERGE:.rdata=.data /MERGE:.bss=.data /MERGE:.edata=.data")
-        else()
-            # Use a custom linker script
-            add_target_link_flags(${MODULE} "-Wl,-T,${CMAKE_SOURCE_DIR}/kbdlayout.lds")
-            add_dependencies(${MODULE} "${CMAKE_SOURCE_DIR}/kbdlayout.lds")
-        endif()
     elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
             OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
         message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
@@ -455,6 +574,17 @@ function(set_module_type MODULE TYPE)
         add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
     endif()
 
+    # Handle hotpatchable images.
+    # GCC has this as a function attribute so we're handling it using DECLSPEC_HOTPATCH
+    if(__module_HOTPATCHABLE AND MSVC AND (NOT ARCH STREQUAL "arm"))
+        if(ARCH STREQUAL "i386")
+            set_property(TARGET ${MODULE} APPEND_STRING PROPERTY COMPILE_FLAGS " /hotpatch")
+            set_property(TARGET ${MODULE} APPEND_STRING PROPERTY LINK_FLAGS " /FUNCTIONPADMIN:5")
+        elseif(ARCH STREQUAL "amd64")
+            set_property(TARGET ${MODULE} APPEND_STRING PROPERTY LINK_FLAGS " /FUNCTIONPADMIN:6")
+        endif()
+    endif()
+
     # set entry point
     if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
         list(GET __module_ENTRYPOINT 0 __entrypoint)
@@ -504,21 +634,23 @@ function(set_module_type MODULE TYPE)
 
     #set base address
     if(__module_IMAGEBASE)
-        set_image_base(${MODULE} __module_IMAGEBASE)
+        set_image_base(${MODULE} ${__module_IMAGEBASE})
     elseif(${TYPE} STREQUAL win32dll)
         if(DEFINED baseaddress_${MODULE})
             set_image_base(${MODULE} ${baseaddress_${MODULE}})
         else()
             message(STATUS "${MODULE} has no base address")
         endif()
-    elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
+    elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
         set_image_base(${MODULE} 0x00010000)
     endif()
 
     # Now do some stuff which is specific to each type
-    if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
+    if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
         add_dependencies(${MODULE} bugcodes)
-        set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
+        if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
+            set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
+        endif()
     endif()
 
     if(${TYPE} STREQUAL win32ocx)
@@ -533,9 +665,25 @@ function(set_module_type MODULE TYPE)
     set_module_type_toolchain(${MODULE} ${TYPE})
 endfunction()
 
+function(start_module_group __name)
+    if(DEFINED CURRENT_MODULE_GROUP)
+        message(FATAL_ERROR "CURRENT_MODULE_GROUP is already set ('${CURRENT_MODULE_GROUP}')")
+    endif()
+    set(CURRENT_MODULE_GROUP ${__name} PARENT_SCOPE)
+endfunction()
+
+function(end_module_group)
+    get_property(__modulelist GLOBAL PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST)
+    add_custom_target(${CURRENT_MODULE_GROUP})
+    foreach(__module ${__modulelist})
+        add_dependencies(${CURRENT_MODULE_GROUP} ${__module})
+    endforeach()
+    set(CURRENT_MODULE_GROUP PARENT_SCOPE)
+endfunction()
+
 function(preprocess_file __in __out)
     set(__arg ${__in})
-    foreach(__def in ${ARGN})
+    foreach(__def ${ARGN})
         list(APPEND __arg -D${__def})
     endforeach()
     if(MSVC)
@@ -575,6 +723,78 @@ else()
     endfunction()
 endif()
 
+function(add_registry_inf)
+    # Add to the inf files list
+    foreach(_file ${ARGN})
+        set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
+        set_property(GLOBAL APPEND PROPERTY REGISTRY_INF_LIST ${_source_file})
+    endforeach()
+endfunction()
+
+function(create_registry_hives)
+
+    # Shortcut to the registry.inf file
+    set(_registry_inf "${CMAKE_BINARY_DIR}/boot/bootdata/registry.inf")
+
+    # Get the list of inf files
+    get_property(_inf_files GLOBAL PROPERTY REGISTRY_INF_LIST)
+
+    # Convert files to utf16le
+    foreach(_file ${_inf_files})
+        get_filename_component(_file_name ${_file} NAME_WE)
+        string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _converted_file "${_file}")
+        string(REPLACE ${_file_name} "${_file_name}_utf16" _converted_file ${_converted_file})
+        add_custom_command(OUTPUT ${_converted_file}
+                           COMMAND native-utf16le ${_file} ${_converted_file}
+                           DEPENDS native-utf16le ${_file})
+        list(APPEND _converted_files ${_converted_file})
+    endforeach()
+
+    # Concatenate all registry files to registry.inf
+    concatenate_files(${_registry_inf} ${_converted_files})
+
+    # Add registry.inf to bootcd
+    add_custom_target(registry_inf DEPENDS ${_registry_inf})
+    add_cd_file(TARGET registry_inf
+                FILE ${_registry_inf}
+                DESTINATION reactos
+                NO_CAB
+                FOR bootcd regtest)
+
+    # livecd hives
+    list(APPEND _livecd_inf_files
+        ${_registry_inf}
+        ${CMAKE_SOURCE_DIR}/boot/bootdata/livecd.inf
+        ${CMAKE_SOURCE_DIR}/boot/bootdata/hiveinst.inf)
+
+    add_custom_command(
+        OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/sam
+            ${CMAKE_BINARY_DIR}/boot/bootdata/default
+            ${CMAKE_BINARY_DIR}/boot/bootdata/security
+            ${CMAKE_BINARY_DIR}/boot/bootdata/software
+            ${CMAKE_BINARY_DIR}/boot/bootdata/system
+        COMMAND native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/ ${_livecd_inf_files}
+        DEPENDS native-mkhive ${_livecd_inf_files})
+
+    add_custom_target(livecd_hives
+        DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/sam
+            ${CMAKE_BINARY_DIR}/boot/bootdata/default
+            ${CMAKE_BINARY_DIR}/boot/bootdata/security
+            ${CMAKE_BINARY_DIR}/boot/bootdata/software
+            ${CMAKE_BINARY_DIR}/boot/bootdata/system)
+
+    add_cd_file(
+        FILE ${CMAKE_BINARY_DIR}/boot/bootdata/sam
+            ${CMAKE_BINARY_DIR}/boot/bootdata/default
+            ${CMAKE_BINARY_DIR}/boot/bootdata/security
+            ${CMAKE_BINARY_DIR}/boot/bootdata/software
+            ${CMAKE_BINARY_DIR}/boot/bootdata/system
+        TARGET livecd_hives
+        DESTINATION reactos/system32/config
+        FOR livecd)
+
+endfunction()
+
 if(KDBG)
     set(ROSSYM_LIB "rossym")
 else()