Skip to content

Commit

Permalink
[CMake] Support for cross-compilation when build runtimes
Browse files Browse the repository at this point in the history
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.

Differential Revision: https://reviews.llvm.org/D41678

llvm-svn: 322046
  • Loading branch information
petrhosek committed Jan 8, 2018
1 parent 87e6192 commit c046a04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llvm/cmake/modules/CrossCompile.cmake
Expand Up @@ -50,6 +50,8 @@ function(llvm_create_cross_target_internal target_name toolchain buildtype)
-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}
Expand Down
14 changes: 12 additions & 2 deletions llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Expand Up @@ -102,7 +102,7 @@ function(llvm_ExternalProject_Add name source_dir)
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++)
Expand Down Expand Up @@ -136,6 +136,16 @@ function(llvm_ExternalProject_Add name source_dir)
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
Expand All @@ -149,7 +159,7 @@ function(llvm_ExternalProject_Add name source_dir)
-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}
Expand Down
3 changes: 3 additions & 0 deletions llvm/runtimes/CMakeLists.txt
Expand Up @@ -354,6 +354,9 @@ else() # if this is included from LLVM's CMake
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
Expand Down

0 comments on commit c046a04

Please sign in to comment.