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
+include(LLVMExternalProjectUtils)
+
function(llvm_create_cross_target_internal target_name toolchain buildtype)
if(NOT DEFINED LLVM_${target_name}_BUILD)
llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE})
endfunction()
+# Sets up a native build for a tool, used e.g. for cross-compilation and
+# LLVM_OPTIMIZED_TABLEGEN. Always builds in Release.
+# - target: The target to build natively
+# - output_path_var: A variable name which receives the path to the built target
+# - DEPENDS: Any additional dependencies for the target
+function(build_native_tool target output_path_var)
+ cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
+
+ if(CMAKE_CONFIGURATION_TYPES)
+ set(output_path "${LLVM_NATIVE_BUILD}/Release/bin/${target}")
+ else()
+ set(output_path "${LLVM_NATIVE_BUILD}/bin/${target}")
+ endif()
+
+ llvm_ExternalProject_BuildCmd(build_cmd ${target} ${LLVM_NATIVE_BUILD}
+ CONFIGURATION Release)
+ add_custom_command(OUTPUT "${output_path}"
+ COMMAND ${build_cmd}
+ DEPENDS CONFIGURE_LLVM_NATIVE ${ARG_DEPENDS}
+ WORKING_DIRECTORY "${LLVM_NATIVE_BUILD}"
+ COMMENT "Building native ${target}..."
+ USES_TERMINAL)
+ set(${output_path_var} "${output_path}" PARENT_SCOPE)
+endfunction()
+
llvm_create_cross_target_internal(NATIVE "" Release)
# Extra parameters for `tblgen' may come after `ofn' parameter.
# Adds the name of the generated file to TABLEGEN_OUTPUT.
-include(LLVMExternalProjectUtils)
-
if(LLVM_MAIN_INCLUDE_DIR)
set(LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_INCLUDE_DIR})
endif()
if(LLVM_USE_HOST_TOOLS)
if( ${${project}_TABLEGEN} STREQUAL "${target}" )
- if (NOT CMAKE_CONFIGURATION_TYPES)
- set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/${target}")
- else()
- set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/Release/bin/${target}")
- endif()
+ build_native_tool(${target} ${project}_TABLEGEN_EXE DEPENDS ${target})
set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE)
- llvm_ExternalProject_BuildCmd(tblgen_build_cmd ${target}
- ${LLVM_NATIVE_BUILD}
- CONFIGURATION Release)
+ add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE})
+ set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE)
+
# Create an artificial dependency between tablegen projects, because they
# compile the same dependencies, thus using the same build folders.
# FIXME: A proper fix requires sequentially chaining tablegens.
if (NOT ${project} STREQUAL LLVM AND TARGET ${project}-tablegen-host)
add_dependencies(${project}-tablegen-host LLVM-tablegen-host)
endif()
- add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE}
- COMMAND ${tblgen_build_cmd}
- DEPENDS CONFIGURE_LLVM_NATIVE ${target}
- WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
- COMMENT "Building native TableGen..."
- USES_TERMINAL)
- add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE})
- set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE)
endif()
endif()
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
- set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "")
+ build_native_tool(llvm-config LLVM_CONFIG_PATH)
+ set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
- add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}"
- COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $<CONFIG>
- DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
- WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
- COMMENT "Building native llvm-config..."
- USES_TERMINAL)
add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
- add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
-
add_dependencies(llvm-config NativeLLVMConfig)
endif()