Reactos

Rework host tools

Now configured at the same time as reactos and only
one list of targets to maintain

Correctly rebuilds when a tool changes (tested widl)

authored by

Andrew Cook and committed by
Mark Jansen
ce531a28 87a625bd

+54 -155
+11 -27
CMakeLists.txt
··· 31 31 set(CMAKE_POSITION_INDEPENDENT_CODE OFF) 32 32 #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF) 33 33 34 - if(NOT DEFINED NEW_STYLE_BUILD) 35 - set(NEW_STYLE_BUILD TRUE) 36 - endif() 37 - 38 34 if(NOT ARCH) 39 35 set(ARCH i386) 40 36 endif() ··· 75 71 # include(sdk/cmake/bison-flex.cmake) 76 72 77 73 if(NOT CMAKE_CROSSCOMPILING) 78 - 79 - if(NEW_STYLE_BUILD) 80 - set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR}) 81 - endif() 82 - 74 + set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR}) 83 75 add_definitions(-DTARGET_${ARCH}) 84 76 85 77 if(MSVC) ··· 105 97 add_subdirectory(sdk/tools) 106 98 add_subdirectory(sdk/lib) 107 99 108 - if(NOT NEW_STYLE_BUILD) 109 - if(NOT MSVC) 110 - export(TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc rsym mkshelllink utf16le xml2sdb FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) 111 - else() 112 - export(TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) 113 - endif() 100 + set(NATIVE_TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb) 101 + if(NOT MSVC) 102 + list(APPEND NATIVE_TARGETS rsym) 114 103 endif() 115 104 105 + export(TARGETS ${NATIVE_TARGETS} FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) 106 + configure_file(sdk/cmake/host-tools.in ${CMAKE_BINARY_DIR}/TargetList.cmake) 107 + 116 108 else() 109 + # Add host tools target 110 + include(sdk/cmake/host-tools.cmake) 111 + setup_host_tools() 112 + 117 113 # We don't need CMake importlib handling. 118 114 unset(CMAKE_IMPORT_LIBRARY_SUFFIX) 119 115 120 - if(NEW_STYLE_BUILD) 121 - include(sdk/cmake/host-tools.cmake) 122 - endif() 123 - 124 116 # Print build type 125 117 message("-- Build Type: ${CMAKE_BUILD_TYPE}") 126 118 ··· 133 125 134 126 #useful stuff! 135 127 include(CMakeParseArguments) 136 - 137 - if(NOT NEW_STYLE_BUILD) 138 - if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR) 139 - set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build) 140 - endif() 141 - set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables") 142 - include(${IMPORT_EXECUTABLES}) 143 - endif() 144 128 145 129 if(DBG) 146 130 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
+1 -58
configure.cmd
··· 18 18 goto quit 19 19 ) 20 20 21 - REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR% 22 - if /I "%1" == "arm_hosttools" ( 23 - echo Configuring x86 host tools for ARM cross build 24 - 25 - REM This launches %VSINSTALLDIR%VS\vcvarsall.bat 26 - call %2 x86 27 - 28 - REM Configure host tools for x86. 29 - cmake -G %3 -A Win32 -DARCH:STRING=i386 %~dp0 30 - exit 31 - ) 32 - 33 21 REM Get the source root directory 34 22 set REACTOS_SOURCE_DIR=%~dp0 35 23 ··· 95 83 goto quit 96 84 ) 97 85 98 - set NEW_STYLE_BUILD=1 99 86 set USE_CLANG_CL=0 100 87 101 88 REM Parse command line parameters 102 89 :repeat 103 - if /I "%1" == "-DNEW_STYLE_BUILD" ( 104 - set NEW_STYLE_BUILD=%2 105 - ) else if "%BUILD_ENVIRONMENT%" == "MinGW" ( 90 + if "%BUILD_ENVIRONMENT%" == "MinGW" ( 106 91 if /I "%1" == "Codeblocks" ( 107 92 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles" 108 93 ) else if /I "%1" == "Eclipse" ( ··· 210 195 goto quit 211 196 ) 212 197 213 - if "%NEW_STYLE_BUILD%"=="0" ( 214 - 215 - if not exist host-tools ( 216 - mkdir host-tools 217 - ) 218 - 219 - if not exist reactos ( 220 - mkdir reactos 221 - ) 222 - 223 - echo Preparing host tools... 224 - cd host-tools 225 - if EXIST CMakeCache.txt ( 226 - del CMakeCache.txt /q 227 - ) 228 - 229 - set REACTOS_BUILD_TOOLS_DIR=!CD! 230 - 231 - REM Use x86 for ARM host tools 232 - if "%ARCH%" == "arm" ( 233 - REM Launch new script instance for x86 host tools configuration 234 - start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR% 235 - ) else ( 236 - cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%" 237 - ) 238 - 239 - cd.. 240 - 241 - ) 242 - 243 198 echo Preparing reactos... 244 199 245 - if "%NEW_STYLE_BUILD%"=="0" ( 246 - cd reactos 247 - ) 248 - 249 200 if EXIST CMakeCache.txt ( 250 201 del CMakeCache.txt /q 251 - del host-tools\CMakeCache.txt /q 252 202 ) 253 203 254 - if "%NEW_STYLE_BUILD%"=="0" ( 255 - set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%" 256 - ) 257 204 258 205 if "%BUILD_ENVIRONMENT%" == "MinGW" ( 259 206 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%" ··· 261 208 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%" 262 209 ) else ( 263 210 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%" 264 - ) 265 - 266 - if "%NEW_STYLE_BUILD%"=="0" ( 267 - cd.. 268 211 ) 269 212 270 213 if %ERRORLEVEL% NEQ 0 (
+1 -26
configure.sh
··· 9 9 ARCH=$ROS_ARCH 10 10 REACTOS_SOURCE_DIR=$(cd `dirname $0` && pwd) 11 11 REACTOS_OUTPUT_PATH=output-$BUILD_ENVIRONMENT-$ARCH 12 - USE_NEW_STYLE=1 13 12 14 13 usage() { 15 14 echo Invalid parameter given. ··· 34 33 makefiles|Makefiles) 35 34 CMAKE_GENERATOR="Unix Makefiles" 36 35 ;; 37 - with-host-tools) 38 - USE_NEW_STYLE=0 39 - ;; 40 36 *) 41 37 usage 42 38 esac ··· 50 46 cd "$REACTOS_OUTPUT_PATH" 51 47 fi 52 48 53 - #EXTRA_ARGS="" 54 - if [ $USE_NEW_STYLE -eq 0 ]; then 55 - mkdir -p host-tools 56 - mkdir -p reactos 57 - echo Preparing host tools... 58 - cd host-tools 59 - rm -f CMakeCache.txt 60 - 61 - REACTOS_BUILD_TOOLS_DIR="$PWD" 62 - cmake -G "$CMAKE_GENERATOR" -DARCH:STRING=$ARCH $ROS_CMAKEOPTS -DNEW_STYLE_BUILD:BOOL=0 "$REACTOS_SOURCE_DIR" 63 - 64 - EXTRA_ARGS="$EXTRA_ARGS -DREACTOS_BUILD_TOOLS_DIR:PATH=$REACTOS_BUILD_TOOLS_DIR" 65 - 66 - cd .. 67 - fi 68 - 69 49 echo Preparing reactos... 70 - 71 - if [ $USE_NEW_STYLE -eq 0 ]; then 72 - cd reactos 73 - fi 74 - 75 50 rm -f CMakeCache.txt host-tools/CMakeCache.txt 76 51 77 - cmake -G "$CMAKE_GENERATOR" -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-gcc.cmake -DARCH:STRING=$ARCH -DNEW_STYLE_BUILD:BOOL=$USE_NEW_STYLE $EXTRA_ARGS $ROS_CMAKEOPTS "$REACTOS_SOURCE_DIR" 52 + cmake -G "$CMAKE_GENERATOR" -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-gcc.cmake -DARCH:STRING=$ARCH $EXTRA_ARGS $ROS_CMAKEOPTS "$REACTOS_SOURCE_DIR" 78 53 79 54 echo Configure script complete! Enter directories and execute appropriate build commands \(ex: ninja, make, makex, etc...\).
+1 -6
sdk/cmake/gcc.cmake
··· 228 228 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>") 229 229 else() 230 230 # Normal rsym build 231 - if(NEW_STYLE_BUILD) 232 - string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type) 233 - get_target_property(RSYM native-rsym IMPORTED_LOCATION_${_build_type}) 234 - else() 235 - get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG) 236 - endif() 231 + get_target_property(RSYM native-rsym IMPORTED_LOCATION_NOCONFIG) 237 232 238 233 set(CMAKE_C_LINK_EXECUTABLE 239 234 "<CMAKE_C_COMPILER> ${CMAKE_C_FLAGS} <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
+38 -35
sdk/cmake/host-tools.cmake
··· 1 1 2 - if(CMAKE_HOST_WIN32) 3 - set(native_suffix ".exe") 4 - endif() 2 + function(setup_host_tools) 3 + file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/host-tools) 4 + 5 + message(STATUS "Configuring host tools...") 6 + # cmake sets CC and CXX when those languages are enabled 7 + # so we need to clear them here 8 + execute_process(COMMAND 9 + ${CMAKE_COMMAND} 10 + -E env --unset=CC --unset=CXX 11 + ${CMAKE_COMMAND} 12 + -G "${CMAKE_GENERATOR}" 13 + -DARCH:STRING=${ARCH} 14 + ${USE_CLANG_CL_ARG} 15 + ${REACTOS_SOURCE_DIR} 16 + WORKING_DIRECTORY ${REACTOS_BINARY_DIR}/host-tools 17 + RESULT_VARIABLE _host_config_result 18 + OUTPUT_VARIABLE _host_config_log 19 + ERROR_VARIABLE _host_config_log) 5 20 6 - string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type) 21 + # Show cmake output only if host-tools breaks 22 + if(NOT _host_config_result EQUAL 0) 23 + message("\nHost tools log:") 24 + message("${_host_config_log}") 25 + message(FATAL_ERROR "Failed to configure host tools") 26 + endif() 7 27 8 - # List of host tools 9 - list(APPEND host_tools_list bin2c hpp widl gendib cabman fatten isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb) 10 - if(NOT MSVC) 11 - list(APPEND host_tools_list rsym) 12 - endif() 28 + set_property(SOURCE host_tools PROPERTY SYMBOLIC 1) 13 29 14 - foreach(_host_tool ${host_tools_list}) 15 - if(MSVC_IDE) 16 - get_filename_component(_tool_location "${CMAKE_CURRENT_BINARY_DIR}/host-tools/${CMAKE_BUILD_TYPE}/${_host_tool}${native_suffix}" ABSOLUTE) 17 - else() 18 - get_filename_component(_tool_location "${CMAKE_CURRENT_BINARY_DIR}/host-tools/${_host_tool}${native_suffix}" ABSOLUTE) 19 - endif() 20 - list(APPEND tools_binaries ${_tool_location}) 21 - add_executable(native-${_host_tool} IMPORTED) 22 - set_property(TARGET native-${_host_tool} PROPERTY IMPORTED_LOCATION_${_build_type} ${_tool_location}) 23 - add_dependencies(native-${_host_tool} host-tools) 24 - endforeach() 30 + # Make a host-tools target so it'll be built when needed 31 + # custom target + symbolic output prevents cmake from running 32 + # the command multiple times per build 33 + add_custom_command( 34 + COMMAND ${CMAKE_COMMAND} --build ${REACTOS_BINARY_DIR}/host-tools 35 + OUTPUT host_tools) 36 + add_custom_target(build-host-tools ALL DEPENDS host_tools) 25 37 26 - if(USE_CLANG_CL) 27 - # FIXME: Fix host tools build with clang 28 - #set(USE_CLANG_CL_ARG "-DCMAKE_C_COMPILER=clang-cl;-DCMAKE_CXX_COMPILER=clang-cl") 29 - endif() 38 + include(${REACTOS_BINARY_DIR}/host-tools/ImportExecutables.cmake) 39 + include(${REACTOS_BINARY_DIR}/host-tools/TargetList.cmake) 30 40 31 - include(ExternalProject) 41 + foreach(_target ${NATIVE_TARGETS}) 42 + add_dependencies(native-${_target} build-host-tools) 43 + endforeach() 32 44 33 - ExternalProject_Add(host-tools 34 - SOURCE_DIR ${REACTOS_SOURCE_DIR} 35 - BINARY_DIR ${REACTOS_BINARY_DIR}/host-tools 36 - STAMP_DIR ${REACTOS_BINARY_DIR}/host-tools/stamps 37 - BUILD_ALWAYS 1 38 - PREFIX host-tools 39 - EXCLUDE_FROM_ALL 1 40 - CMAKE_ARGS "-DNEW_STYLE_BUILD=1;-DARCH:STRING=${ARCH};${USE_CLANG_CL_ARG}" 41 - INSTALL_COMMAND "" 42 - BUILD_BYPRODUCTS ${tools_binaries}) 45 + endfunction()
+1
sdk/cmake/host-tools.in
··· 1 + set(NATIVE_TARGETS @NATIVE_TARGETS@)
+1 -3
sdk/tools/CMakeLists.txt
··· 1 1 2 2 function(add_host_tool _tool) 3 3 add_executable(${_tool} ${ARGN}) 4 - if(NEW_STYLE_BUILD) 5 - set_target_properties(${_tool} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TOOLS_FOLDER}) 6 - endif() 4 + set_target_properties(${_tool} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TOOLS_FOLDER}) 7 5 endfunction() 8 6 9 7 #add_executable(pefixup pefixup.c)