[CMAKE] Introduce a way to compile ReactOS without invoking CMake twice. You can...
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 6 Sep 2015 16:44:30 +0000 (16:44 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 6 Sep 2015 16:44:30 +0000 (16:44 +0000)
svn path=/trunk/; revision=69060

12 files changed:
reactos/CMakeLists.txt
reactos/cmake/gcc.cmake
reactos/cmake/host-tools.cmake [new file with mode: 0644]
reactos/tools/CMakeLists.txt
reactos/tools/cabman/CMakeLists.txt
reactos/tools/cdmake/CMakeLists.txt
reactos/tools/hpp/CMakeLists.txt
reactos/tools/kbdtool/CMakeLists.txt
reactos/tools/log2lines/CMakeLists.txt
reactos/tools/mkhive/CMakeLists.txt
reactos/tools/rsym/CMakeLists.txt
reactos/tools/widl/CMakeLists.txt

index 70cfe2f..6cd3327 100644 (file)
@@ -41,6 +41,10 @@ if(NOT CMAKE_VERSION STREQUAL "2.8.12.1-ReactOS")
     set(CMAKE_DISABLE_NINJA_DEPSLOG TRUE)
 endif()
 
+if(NOT DEFINED NEW_STYLE_BUILD)
+    set(NEW_STYLE_BUILD FALSE)
+endif()
+
 if(NOT ARCH)
     set(ARCH i386)
 endif()
@@ -80,6 +84,10 @@ endif()
 
 if(NOT CMAKE_CROSSCOMPILING)
 
+    if(NEW_STYLE_BUILD)
+        set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
+    endif()
+
     add_definitions(-DTARGET_${ARCH})
 
     if(MSVC)
@@ -102,14 +110,20 @@ if(NOT CMAKE_CROSSCOMPILING)
     add_subdirectory(tools)
     add_subdirectory(lib)
 
-    if(NOT MSVC)
-        export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc rsym mkshelllink utf16le FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
-    else()
-        export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc mkshelllink utf16le FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+    if(NOT NEW_STYLE_BUILD)
+        if(NOT MSVC)
+            export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc rsym mkshelllink utf16le FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+        else()
+            export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc mkshelllink utf16le FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
+        endif()
     endif()
 
 else()
 
+    if(NEW_STYLE_BUILD)
+        include(cmake/host-tools.cmake)
+    endif()
+
     # adjust the default behaviour of the FIND_XXX() commands:
     # search headers and libraries in the target environment, search
     # programs in the host environment
@@ -130,13 +144,14 @@ else()
         ${REACTOS_BINARY_DIR}/boot/ros_cab.txt
         ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt)
 
-    if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR)
-        set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build)
+    if(NOT NEW_STYLE_BUILD)
+        if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR)
+            set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build)
+        endif()
+        set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables")
+        include(${IMPORT_EXECUTABLES})
     endif()
 
-    set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables")
-    include(${IMPORT_EXECUTABLES})
-
     if(DBG)
         add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
     else()
index 73012ee..4bd6559 100644 (file)
@@ -225,7 +225,13 @@ elseif(NO_ROSSYM)
     set(CMAKE_RC_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
 else()
     # Normal rsym build
-    get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG)
+    if(NEW_STYLE_BUILD)
+        string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
+        get_target_property(RSYM native-rsym IMPORTED_LOCATION_${_build_type})
+    else()
+        get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG)
+    endif()
+    
     set(CMAKE_C_LINK_EXECUTABLE
         "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
         "${RSYM} -s ${REACTOS_SOURCE_DIR} <TARGET> <TARGET>")
diff --git a/reactos/cmake/host-tools.cmake b/reactos/cmake/host-tools.cmake
new file mode 100644 (file)
index 0000000..7991560
--- /dev/null
@@ -0,0 +1,37 @@
+
+if(CMAKE_HOST_WIN32)
+    set(native_suffix ".exe")
+endif()
+
+string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
+
+# List of host tools
+list(APPEND host_tools_list bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc mkshelllink utf16le)
+if(NOT MSVC)
+    list(APPEND host_tools_list rsym)
+endif()
+
+foreach(_host_tool ${host_tools_list})
+    if(MSVC_IDE)
+        get_filename_component(_tool_location "${CMAKE_CURRENT_BINARY_DIR}/host-tools/${CMAKE_BUILD_TYPE}/${_host_tool}${native_suffix}" ABSOLUTE)
+    else()
+        get_filename_component(_tool_location "${CMAKE_CURRENT_BINARY_DIR}/host-tools/${_host_tool}${native_suffix}" ABSOLUTE)
+    endif()
+    list(APPEND tools_binaries ${_tool_location})
+    add_executable(native-${_host_tool} IMPORTED)
+    set_property(TARGET native-${_host_tool} PROPERTY IMPORTED_LOCATION_${_build_type} ${_tool_location})
+    add_dependencies(native-${_host_tool} host-tools)
+endforeach()
+
+include(ExternalProject)
+
+ExternalProject_Add(host-tools
+    SOURCE_DIR ${REACTOS_SOURCE_DIR}
+    BINARY_DIR ${REACTOS_BINARY_DIR}/host-tools
+    STAMP_DIR ${REACTOS_BINARY_DIR}/host-tools/stamps
+    BUILD_ALWAYS 1
+    PREFIX host-tools
+    EXCLUDE_FROM_ALL 1
+    CMAKE_ARGS "-DNEW_STYLE_BUILD=1"
+    INSTALL_COMMAND ""
+    BUILD_BYPRODUCTS ${tools_binaries})
index 56f09b1..d1f402e 100644 (file)
@@ -1,21 +1,28 @@
 
+function(add_host_tool _tool)
+    add_executable(${_tool} ${ARGN})
+    if(NEW_STYLE_BUILD)
+        set_target_properties(${_tool} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TOOLS_FOLDER})
+    endif()
+endfunction()
+
 #add_executable(pefixup pefixup.c)
 
 if(MSVC)
     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()
 
-add_executable(bin2c bin2c.c)
-add_executable(gendib gendib/gendib.c)
-add_executable(geninc geninc/geninc.c)
-add_executable(mkshelllink mkshelllink/mkshelllink.c)
-add_executable(obj2bin obj2bin/obj2bin.c)
-add_executable(spec2def spec2def/spec2def.c)
+add_host_tool(bin2c bin2c.c)
+add_host_tool(gendib gendib/gendib.c)
+add_host_tool(geninc geninc/geninc.c)
+add_host_tool(mkshelllink mkshelllink/mkshelllink.c)
+add_host_tool(obj2bin obj2bin/obj2bin.c)
+add_host_tool(spec2def spec2def/spec2def.c)
 
 if(MSVC)
     set_property(SOURCE utf16le/utf16le.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " /EHsc")
 endif()
-add_executable(utf16le utf16le/utf16le.cpp)
+add_host_tool(utf16le utf16le/utf16le.cpp)
 
 add_subdirectory(cabman)
 add_subdirectory(cdmake)
index 2fd93f8..60242b6 100644 (file)
@@ -7,5 +7,5 @@ list(APPEND SOURCE
     raw.cxx)
 
 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs/zlib)
-add_executable(cabman ${SOURCE})
+add_host_tool(cabman ${SOURCE})
 target_link_libraries(cabman zlibhost)
index d2a70e6..caaeb07 100644 (file)
@@ -1,2 +1,2 @@
 
-add_executable(cdmake cdmake.c dirhash.c llmsort.c)
+add_host_tool(cdmake cdmake.c dirhash.c llmsort.c)
index 26113d3..684214f 100644 (file)
@@ -1,2 +1,2 @@
 
-add_executable(hpp hpp.c)
+add_host_tool(hpp hpp.c)
index 0e9db09..a8adaa2 100644 (file)
@@ -1,2 +1,2 @@
 
-add_executable(kbdtool data.c main.c output.c parser.c)
+add_host_tool(kbdtool data.c main.c output.c parser.c)
index 18b5658..8e1485b 100644 (file)
@@ -13,5 +13,5 @@ list(APPEND SOURCE
     util.c)
 
 include_directories(${REACTOS_SOURCE_DIR}/tools/rsym)
-add_executable(log2lines ${SOURCE})
+add_host_tool(log2lines ${SOURCE})
 target_link_libraries(log2lines rsym_common)
index 04bd747..66a91d3 100644 (file)
@@ -16,5 +16,5 @@ list(APPEND SOURCE
     registry.c
     rtl.c)
 
-add_executable(mkhive ${SOURCE})
+add_host_tool(mkhive ${SOURCE})
 target_link_libraries(mkhive unicode cmlibhost inflibhost)
index 0daf788..2e4e389 100644 (file)
@@ -4,12 +4,12 @@ add_library(rsym_common rsym_common.c)
 
 if(ARCH STREQUAL "i386")
     add_definitions(-D_X86_)
-    add_executable(rsym rsym.c)
+    add_host_tool(rsym rsym.c)
 elseif(ARCH STREQUAL "amd64")
-    add_executable(rsym rsym64.c)
+    add_host_tool(rsym rsym64.c)
 elseif(ARCH STREQUAL "arm")
     add_executable(rsym rsym64.c)
 endif()
 
 target_link_libraries(rsym rsym_common dbghelphost zlibhost unicode)
-add_executable(raddr2line rsym_common.c raddr2line.c)
+add_host_tool(raddr2line rsym_common.c raddr2line.c)
index 009c415..de1174b 100644 (file)
@@ -32,5 +32,5 @@ list(APPEND SOURCE
 
 # Taken from widl.rbuild
 add_definitions(-DINT16=SHORT)
-add_executable(widl ${SOURCE})
+add_host_tool(widl ${SOURCE})
 target_link_libraries(widl wpphost)