[CMAKE]
[reactos.git] / reactos / cmake / CMakeMacros.cmake
index 4b92915..68ab5a6 100644 (file)
@@ -171,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)
@@ -315,7 +315,7 @@ function(add_cd_file)
             endforeach()
             if(_CD_TARGET)
                 #manage dependency
-                add_dependencies(bootcd ${_CD_TARGET} converted_hives)
+                add_dependencies(bootcd ${_CD_TARGET} registry_inf)
             endif()
         else()
             #add it in reactos.cab
@@ -337,7 +337,7 @@ function(add_cd_file)
     if(NOT __cd EQUAL -1)
         #manage dependency
         if(_CD_TARGET)
-            add_dependencies(livecd ${_CD_TARGET} converted_hives)
+            add_dependencies(livecd ${_CD_TARGET} registry_inf)
         endif()
         foreach(item ${_CD_FILE})
             if(_CD_NAME_ON_CD)
@@ -385,7 +385,7 @@ function(add_cd_file)
             endforeach()
             if(_CD_TARGET)
                 #manage dependency
-                add_dependencies(bootcdregtest ${_CD_TARGET} converted_hives)
+                add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
             endif()
         else()
             #add it in reactos.cab
@@ -505,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()
 
@@ -583,8 +577,8 @@ function(set_module_type MODULE TYPE)
     # 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"))
-        set_property(TARGET ${MODULE} APPEND_STRING PROPERTY COMPILE_FLAGS " /hotpatch")
         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")
@@ -653,7 +647,7 @@ function(set_module_type MODULE TYPE)
 
     # Now do some stuff which is specific to each type
     if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
-        add_dependencies(${MODULE} bugcodes)
+        add_dependencies(${MODULE} bugcodes xdk)
         if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
             set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
         endif()
@@ -689,7 +683,7 @@ endfunction()
 
 function(preprocess_file __in __out)
     set(__arg ${__in})
-    foreach(__def in ${ARGN})
+    foreach(__def ${ARGN})
         list(APPEND __arg -D${__def})
     endforeach()
     if(MSVC)
@@ -729,8 +723,84 @@ 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()
     set(ROSSYM_LIB "")
 endif()
+
+function(add_rc_deps _target_rc)
+    set_source_files_properties(${_target_rc} PROPERTIES OBJECT_DEPENDS "${ARGN}")
+endfunction()