xref: /reactos/sdk/cmake/host-tools.cmake (revision e32507b5)
1
2function(configure_host_tools HOST_TOOLS_DIR)
3    file(MAKE_DIRECTORY ${HOST_TOOLS_DIR})
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 ${HOST_TOOLS_DIR}
17        RESULT_VARIABLE _host_config_result
18        OUTPUT_VARIABLE _host_config_log
19        ERROR_VARIABLE  _host_config_log)
20
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()
27
28    set_property(SOURCE host_tools PROPERTY SYMBOLIC 1)
29
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 ${HOST_TOOLS_DIR}
35        OUTPUT host_tools)
36    add_custom_target(build-host-tools ALL DEPENDS host_tools)
37
38    include(${HOST_TOOLS_DIR}/ImportExecutables.cmake)
39    include(${HOST_TOOLS_DIR}/TargetList.cmake)
40
41    foreach(_target ${NATIVE_TARGETS})
42        add_dependencies(native-${_target} build-host-tools)
43    endforeach()
44
45endfunction()
46
47function(setup_host_tools)
48    if(WITH_HOST_TOOLS)
49        # Use pre-built tools, required for cross compiling with msvc
50        # as only one target architecture is available at a time
51        find_path(HOST_TOOLS_DIR
52            NAMES ImportExecutables.cmake
53            HINTS ${WITH_HOST_TOOLS} ${REACTOS_SOURCE_DIR}/${WITH_HOST_TOOLS}
54            NO_CMAKE_PATH
55            NO_CMAKE_ENVIRONMENT_PATH)
56        message(STATUS "Using prebuilt host tools: ${HOST_TOOLS_DIR}")
57        include(${HOST_TOOLS_DIR}/ImportExecutables.cmake)
58    else()
59        # Build host-tools. Changes to tool sources will rebuild targets
60        # using that tool
61        set(HOST_TOOLS_DIR ${REACTOS_BINARY_DIR}/host-tools)
62        configure_host_tools(${HOST_TOOLS_DIR})
63    endif()
64
65endfunction()
66