llvm.org GIT mirror llvm / f66e620
[cmake] Add function for building native tool Instead of duplicating functionality for building native versions of tblgen and llvm-config, add a function to set up a native tool build. This will also be used for llvm-nm in a follow-up. This should be NFC for tblgen, besides the slightly different COMMENT for the custom command (it'll display the tablegen target name instead of always saying TableGen). For the native llvm-config, it's a behavior change in that we'll use llvm_ExternalProject_BuildCmd instead of constructing the build command manually, always build in Release, and reference the correct binary path for multi-config generators. I believe all of these changes to be bug fixes. Differential Revision: https://reviews.llvm.org/D60024 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357486 91177308-0d34-0410-b5e6-96231b3b80d8 Shoaib Meenai 6 months ago
3 changed file(s) with 33 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
0 include(LLVMExternalProjectUtils)
1
2 function(llvm_create_cross_target_internal target_name toolchain buildtype)
13
24 if(NOT DEFINED LLVM_${target_name}_BUILD)
6668 llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE})
6769 endfunction()
6870
71 # Sets up a native build for a tool, used e.g. for cross-compilation and
72 # LLVM_OPTIMIZED_TABLEGEN. Always builds in Release.
73 # - target: The target to build natively
74 # - output_path_var: A variable name which receives the path to the built target
75 # - DEPENDS: Any additional dependencies for the target
76 function(build_native_tool target output_path_var)
77 cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
78
79 if(CMAKE_CONFIGURATION_TYPES)
80 set(output_path "${LLVM_NATIVE_BUILD}/Release/bin/${target}")
81 else()
82 set(output_path "${LLVM_NATIVE_BUILD}/bin/${target}")
83 endif()
84
85 llvm_ExternalProject_BuildCmd(build_cmd ${target} ${LLVM_NATIVE_BUILD}
86 CONFIGURATION Release)
87 add_custom_command(OUTPUT "${output_path}"
88 COMMAND ${build_cmd}
89 DEPENDS CONFIGURE_LLVM_NATIVE ${ARG_DEPENDS}
90 WORKING_DIRECTORY "${LLVM_NATIVE_BUILD}"
91 COMMENT "Building native ${target}..."
92 USES_TERMINAL)
93 set(${output_path_var} "${output_path}" PARENT_SCOPE)
94 endfunction()
95
6996 llvm_create_cross_target_internal(NATIVE "" Release)
0 # LLVM_TARGET_DEFINITIONS must contain the name of the .td file to process.
11 # Extra parameters for `tblgen' may come after `ofn' parameter.
22 # Adds the name of the generated file to TABLEGEN_OUTPUT.
3
4 include(LLVMExternalProjectUtils)
53
64 if(LLVM_MAIN_INCLUDE_DIR)
75 set(LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_INCLUDE_DIR})
135133
136134 if(LLVM_USE_HOST_TOOLS)
137135 if( ${${project}_TABLEGEN} STREQUAL "${target}" )
138 if (NOT CMAKE_CONFIGURATION_TYPES)
139 set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/${target}")
140 else()
141 set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/Release/bin/${target}")
142 endif()
136 build_native_tool(${target} ${project}_TABLEGEN_EXE DEPENDS ${target})
143137 set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE)
144138
145 llvm_ExternalProject_BuildCmd(tblgen_build_cmd ${target}
146 ${LLVM_NATIVE_BUILD}
147 CONFIGURATION Release)
139 add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE})
140 set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE)
141
148142 # Create an artificial dependency between tablegen projects, because they
149143 # compile the same dependencies, thus using the same build folders.
150144 # FIXME: A proper fix requires sequentially chaining tablegens.
151145 if (NOT ${project} STREQUAL LLVM AND TARGET ${project}-tablegen-host)
152146 add_dependencies(${project}-tablegen-host LLVM-tablegen-host)
153147 endif()
154 add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE}
155 COMMAND ${tblgen_build_cmd}
156 DEPENDS CONFIGURE_LLVM_NATIVE ${target}
157 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
158 COMMENT "Building native TableGen..."
159 USES_TERMINAL)
160 add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE})
161 set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE)
162148 endif()
163149 endif()
164150
7474 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
7575
7676 if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
77 set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "")
77 build_native_tool(llvm-config LLVM_CONFIG_PATH)
78 set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
7879
79 add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}"
80 COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $
81 DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
82 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
83 COMMENT "Building native llvm-config..."
84 USES_TERMINAL)
8580 add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
86 add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
87
8881 add_dependencies(llvm-config NativeLLVMConfig)
8982 endif()