diff options
author | Petr Hosek <phosek@chromium.org> | 2018-11-16 04:46:48 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2018-11-16 04:46:48 +0000 |
commit | f8e27b3878af18a2ab7c0ea9a1ed54799361ea48 (patch) | |
tree | c3cfec443308d91c116e81eb2575a03de7c75ecc /llvm/cmake/modules/LLVMExternalProjectUtils.cmake | |
parent | 5f5c773765b03aae78e324851d4f995580766362 (diff) | |
download | bcm5719-llvm-f8e27b3878af18a2ab7c0ea9a1ed54799361ea48.tar.gz bcm5719-llvm-f8e27b3878af18a2ab7c0ea9a1ed54799361ea48.zip |
[CMake] Support cross-compiling with multi-stage builds
When using multi-stage builds, we would like support cross-compilation.
Example is 2-stage build when the first stage is compiled for host while
the second stage is compiled for the target.
Normally, the second stage would be also used for compiling runtimes,
but that's not possible when cross-compiling, so we use the first stage
compiler instead. However, we still want to use the second stage paths.
To do so, we set the -resource-dir of the first stage compiler to point
to the resource directory of the second stage.
We also need compiler tools that support the target architecture. These
tools are not guaranteed to be present on the host, but in case of
multi-stage build, we can build these tools in the first stage.
Differential Revision: https://reviews.llvm.org/D54461
llvm-svn: 347025
Diffstat (limited to 'llvm/cmake/modules/LLVMExternalProjectUtils.cmake')
-rw-r--r-- | llvm/cmake/modules/LLVMExternalProjectUtils.cmake | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake index f736c394784..4d26a30f97b 100644 --- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake @@ -162,8 +162,35 @@ function(llvm_ExternalProject_Add name source_dir) -DCMAKE_OBJDUMP=${CMAKE_OBJDUMP} -DCMAKE_STRIP=${CMAKE_STRIP}) set(llvm_config_path ${LLVM_CONFIG_PATH}) + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + ${PACKAGE_VERSION}) + set(resource_dir "${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION}") + set(flag_types ASM C CXX MODULE_LINKER SHARED_LINKER EXE_LINKER) + foreach(type ${flag_types}) + set(${type}_flag -DCMAKE_${type}_FLAGS=-resource-dir=${resource_dir}) + endforeach() + string(REPLACE ";" "|" flag_string "${flag_types}") + foreach(arg ${ARG_CMAKE_ARGS}) + if(arg MATCHES "^-DCMAKE_(${flag_string})_FLAGS") + foreach(type ${flag_types}) + if(arg MATCHES "^-DCMAKE_${type}_FLAGS") + string(REGEX REPLACE "^-DCMAKE_${type}_FLAGS=(.*)$" "\\1" flag_value "${arg}") + set(${type}_flag "${${type}_flag} ${flag_value}") + endif() + endforeach() + else() + list(APPEND cmake_args ${arg}) + endif() + endforeach() + foreach(type ${flag_types}) + list(APPEND cmake_args ${${type}_flag}) + endforeach() + endif() else() set(llvm_config_path "$<TARGET_FILE:llvm-config>") + set(cmake_args ${ARG_CMAKE_ARGS}) endif() ExternalProject_Add(${name} @@ -187,7 +214,7 @@ function(llvm_ExternalProject_Add name source_dir) -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 - ${ARG_CMAKE_ARGS} + ${cmake_args} ${PASSTHROUGH_VARIABLES} INSTALL_COMMAND "" STEP_TARGETS configure build |