[PATCH] D41678: [CMake] Support for cross-compilation when build runtimes
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 2 12:15:13 PST 2018
phosek created this revision.
phosek added a reviewer: beanz.
Herald added a subscriber: mgorny.
When cross-compiling, we cannot use the just built toolchain, instead
we need to use the host toolchain which we assume has a support for
targeting the selected target platform. We also need to pass the path
to the native version of llvm-config to external projects.
Repository:
rL LLVM
https://reviews.llvm.org/D41678
Files:
cmake/modules/CrossCompile.cmake
cmake/modules/LLVMExternalProjectUtils.cmake
runtimes/CMakeLists.txt
Index: runtimes/CMakeLists.txt
===================================================================
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -354,6 +354,9 @@
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
+ -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
+ -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
+ -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
-DCMAKE_C_COMPILER_WORKS=ON
-DCMAKE_CXX_COMPILER_WORKS=ON
-DCMAKE_ASM_COMPILER_WORKS=ON
Index: cmake/modules/LLVMExternalProjectUtils.cmake
===================================================================
--- cmake/modules/LLVMExternalProjectUtils.cmake
+++ cmake/modules/LLVMExternalProjectUtils.cmake
@@ -102,7 +102,7 @@
endforeach()
endforeach()
- if(ARG_USE_TOOLCHAIN)
+ if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING)
if(CLANG_IN_TOOLCHAIN)
set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
@@ -136,6 +136,16 @@
set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
endif()
+ if(CMAKE_CROSSCOMPILING)
+ set(compiler_args -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+ -DCMAKE_AR=${CMAKE_AR}
+ -DCMAKE_RANLIB=${CMAKE_RANLIB})
+ set(llvm_config_path "${LLVM_NATIVE_BUILD}/bin/llvm-config")
+ else()
+ set(llvm_config_path "$<TARGET_FILE:llvm-config>")
+ endif()
+
ExternalProject_Add(${name}
DEPENDS ${ARG_DEPENDS} llvm-config
${name}-clobber
@@ -149,7 +159,7 @@
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
${sysroot_arg}
-DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR}
- -DLLVM_CONFIG_PATH=$<TARGET_FILE:llvm-config>
+ -DLLVM_CONFIG_PATH=${llvm_config_path}
-DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}
-DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE}
-DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT}
Index: cmake/modules/CrossCompile.cmake
===================================================================
--- cmake/modules/CrossCompile.cmake
+++ cmake/modules/CrossCompile.cmake
@@ -49,6 +49,8 @@
-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
-DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}"
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}"
+ -DLLVM_DEFAULT_TARGET_TRIPLE="${TARGET_TRIPLE}"
+ -DLLVM_TARGET_ARCH="${LLVM_TARGET_ARCH}"
${build_type_flags} ${linker_flag} ${external_clang_dir}
WORKING_DIRECTORY ${LLVM_${target_name}_BUILD}
DEPENDS CREATE_LLVM_${target_name}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41678.128446.patch
Type: text/x-patch
Size: 3149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180102/b7c9855d/attachment.bin>
More information about the llvm-commits
mailing list