Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -224,6 +224,7 @@ # Target options -------------------------------------------------------------- option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) +set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.") set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") @@ -460,11 +461,27 @@ # 'config-ix' use them during feature checks. It also adds them to both # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") -add_target_flags_if(LIBCXX_TARGET_TRIPLE "--target=${LIBCXX_TARGET_TRIPLE}") -add_target_flags_if(LIBCXX_SYSROOT "--sysroot=${LIBCXX_SYSROOT}") -add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") -if (LIBCXX_TARGET_TRIPLE) + +if(LIBCXX_TARGET_TRIPLE) + add_target_flags("--target=${LIBCXX_TARGET_TRIPLE}") +elseif(CMAKE_CXX_COMPILER_TARGET) + set(LIBCXX_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") +endif() +if(LIBCXX_SYSROOT) + add_target_flags("--sysroot=${LIBCXX_SYSROOT}") +elseif(CMAKE_SYSROOT) + set(LIBCXX_SYSROOT "${CMAKE_SYSROOT}") +endif() +message("TOOLCHAIN ${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}") +if(LIBCXX_GCC_TOOLCHAIN) + add_target_flags("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") +elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) + set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") +endif() + +if(LIBCXX_TARGET_TRIPLE) set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") + set(LIBCXX_USE_TARGET ON) endif() # Configure compiler. Index: libcxx/test/lit.site.cfg.in =================================================================== --- libcxx/test/lit.site.cfg.in +++ libcxx/test/lit.site.cfg.in @@ -17,7 +17,7 @@ config.configuration_variant = "@LIBCXX_LIT_VARIANT@" config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" -config.use_target = len("@LIBCXX_TARGET_TRIPLE@") > 0 +config.use_target = bool("@LIBCXX_TARGET_TRIPLE@") config.sysroot = "@LIBCXX_SYSROOT@" config.gcc_toolchain = "@LIBCXX_GCC_TOOLCHAIN@" config.generate_coverage = "@LIBCXX_GENERATE_COVERAGE@" Index: libcxxabi/CMakeLists.txt =================================================================== --- libcxxabi/CMakeLists.txt +++ libcxxabi/CMakeLists.txt @@ -231,15 +231,26 @@ # Configure target flags add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32") -add_target_flags_if(LIBCXXABI_TARGET_TRIPLE - "--target=${LIBCXXABI_TARGET_TRIPLE}") -add_target_flags_if(LIBCXXABI_GCC_TOOLCHAIN - "--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}") -add_target_flags_if(LIBCXXABI_SYSROOT - "--sysroot=${LIBCXXABI_SYSROOT}") + +if(LIBCXXABI_TARGET_TRIPLE) + add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE}") +elseif(CMAKE_CXX_COMPILER_TARGET) + set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") +endif() +if(LIBCXX_GCC_TOOLCHAIN) + add_target_flags("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}") +elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) + set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") +endif() +if(LIBCXXABI_SYSROOT) + add_target_flags("--sysroot=${LIBCXXABI_SYSROOT}") +elseif(CMAKE_SYSROOT) + set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}") +endif() if (LIBCXXABI_TARGET_TRIPLE) set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}") + set(LIBCXXABI_USE_TARGET ON) endif() # Configure compiler. Must happen after setting the target flags. Index: libcxxabi/test/lit.site.cfg.in =================================================================== --- libcxxabi/test/lit.site.cfg.in +++ libcxxabi/test/lit.site.cfg.in @@ -20,7 +20,7 @@ config.enable_exceptions = "@LIBCXXABI_ENABLE_EXCEPTIONS@" config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" -config.use_target = len("@LIBCXXABI_TARGET_TRIPLE@") > 0 +config.use_target = bool("@LIBCXXABI_TARGET_TRIPLE@") config.sysroot = "@LIBCXXABI_SYSROOT@" config.gcc_toolchain = "@LIBCXXABI_GCC_TOOLCHAIN@" config.cxx_ext_threads = "@LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY@" Index: libunwind/CMakeLists.txt =================================================================== --- libunwind/CMakeLists.txt +++ libunwind/CMakeLists.txt @@ -225,15 +225,26 @@ endmacro() add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32") -add_target_flags_if(LIBUNWIND_TARGET_TRIPLE - "--target=${LIBUNWIND_TARGET_TRIPLE}") -add_target_flags_if(LIBUNWIND_GCC_TOOLCHAIN - "--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}") -add_target_flags_if(LIBUNWIND_SYSROOT - "--sysroot=${LIBUNWIND_SYSROOT}") + +if(LIBUNWIND_TARGET_TRIPLE) + add_target_flags("--target=${LIBUNWIND_TARGET_TRIPLE}") +elseif(CMAKE_CXX_COMPILER_TARGET) + set(LIBUNWIND_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") +endif() +if(LIBUNWIND_GCC_TOOLCHAIN) + add_target_flags("--gcc-toolchain=${LIBUNWIND_GCC_TOOLCHAIN}") +elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) + set(LIBUNWIND_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") +endif() +if(LIBUNWIND_SYSROOT) + add_target_flags("--sysroot=${LIBUNWIND_SYSROOT}") +elseif(CMAKE_SYSROOT) + set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}") +endif() if (LIBUNWIND_TARGET_TRIPLE) set(TARGET_TRIPLE "${LIBUNWIND_TARGET_TRIPLE}") + set(LIBUNWIND_USE_TARGET ON) endif() # Configure compiler. Index: libunwind/test/lit.site.cfg.in =================================================================== --- libunwind/test/lit.site.cfg.in +++ libunwind/test/lit.site.cfg.in @@ -20,7 +20,7 @@ config.enable_exceptions = "@LIBUNWIND_ENABLE_EXCEPTIONS@" config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" -config.use_target = len("@LIBUNWIND_TARGET_TRIPLE@") > 0 +config.use_target = bool("@LIBUNWIND_TARGET_TRIPLE@") config.sysroot = "@LIBUNWIND_SYSROOT@" config.gcc_toolchain = "@LIBUNWIND_GCC_TOOLCHAIN@" config.cxx_ext_threads = "@LIBUNWIND_BUILD_EXTERNAL_THREAD_LIBRARY@"