diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -465,17 +465,17 @@ add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") if(LIBCXX_TARGET_TRIPLE) - add_target_flags("--target=${LIBCXX_TARGET_TRIPLE}") + add_target_flags_if_supported("--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}") + add_target_flags_if_supported("--sysroot=${LIBCXX_SYSROOT}") elseif(CMAKE_SYSROOT) set(LIBCXX_SYSROOT "${CMAKE_SYSROOT}") endif() if(LIBCXX_GCC_TOOLCHAIN) - add_target_flags("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") + add_target_flags_if_supported("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") endif() diff --git a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake --- a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake +++ b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake @@ -121,6 +121,17 @@ endif() endmacro() +# Add all the flags supported by the compiler to all of +# 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBCXX_COMPILE_FLAGS' +# and 'LIBCXX_LINK_FLAGS'. +macro(add_target_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_target_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + # Add a specified list of flags to both 'LIBCXX_COMPILE_FLAGS' and # 'LIBCXX_LINK_FLAGS'. macro(add_flags) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -258,17 +258,17 @@ add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32") if(LIBCXXABI_TARGET_TRIPLE) - add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE}") + add_target_flags_if_supported("--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}") + add_target_flags_if_supported("--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}") + add_target_flags_if_supported("--sysroot=${LIBCXXABI_SYSROOT}") elseif(CMAKE_SYSROOT) set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}") endif() diff --git a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake --- a/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake +++ b/libcxxabi/cmake/Modules/HandleLibcxxabiFlags.cmake @@ -123,6 +123,17 @@ endif() endmacro() +# Add all the flags supported by the compiler to all of +# 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBCXXABI_COMPILE_FLAGS' +# and 'LIBCXXABI_LINK_FLAGS'. +macro(add_target_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXXABI_SUPPORTS_${flagname}_FLAG") + add_target_flags_if(LIBCXXABI_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + # Add a specified list of flags to both 'LIBCXXABI_COMPILE_FLAGS' and # 'LIBCXXABI_LINK_FLAGS'. macro(add_flags) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -152,17 +152,17 @@ add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32") if(LIBUNWIND_TARGET_TRIPLE) - add_target_flags("--target=${LIBUNWIND_TARGET_TRIPLE}") + add_target_flags_if_supported("--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}") + add_target_flags_if_supported("--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}") + add_target_flags_if_supported("--sysroot=${LIBUNWIND_SYSROOT}") elseif(CMAKE_SYSROOT) set(LIBUNWIND_SYSROOT "${CMAKE_SYSROOT}") endif() diff --git a/libunwind/cmake/Modules/HandleLibunwindFlags.cmake b/libunwind/cmake/Modules/HandleLibunwindFlags.cmake --- a/libunwind/cmake/Modules/HandleLibunwindFlags.cmake +++ b/libunwind/cmake/Modules/HandleLibunwindFlags.cmake @@ -124,6 +124,17 @@ endif() endmacro() +# Add all the flags supported by the compiler to all of +# 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBUNWIND_COMPILE_FLAGS' +# and 'LIBUNWIND_LINK_FLAGS'. +macro(add_target_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBUNWIND_SUPPORTS_${flagname}_FLAG") + add_target_flags_if(LIBUNWIND_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + # Add a specified list of flags to both 'LIBUNWIND_COMPILE_FLAGS' and # 'LIBUNWIND_LINK_FLAGS'. macro(add_flags)