diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dda69629e1..fe177259f0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,6 +252,7 @@ endif() option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF) option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF) option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF) +option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF) option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) diff --git a/cmake/modules/HandleLLVMStdlib.cmake b/cmake/modules/HandleLLVMStdlib.cmake index 47bb6cddc8e..66ad078fb66 100644 --- a/cmake/modules/HandleLLVMStdlib.cmake +++ b/cmake/modules/HandleLLVMStdlib.cmake @@ -12,22 +12,28 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED) set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) endif() - function(append_if condition value) - if(${condition}) - foreach(variable ${ARGN}) - set(${variable} "${${variable}} ${value}" PARENT_SCOPE) - endforeach(variable) - endif() + function(append value) + foreach(variable ${ARGN}) + set(${variable} "${${variable}} ${value}" PARENT_SCOPE) + endforeach(variable) endfunction() include(CheckCXXCompilerFlag) if(LLVM_ENABLE_LIBCXX) if(LLVM_COMPILER_IS_GCC_COMPATIBLE) check_cxx_compiler_flag("-stdlib=libc++" CXX_SUPPORTS_STDLIB) - append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_CXX_FLAGS) - append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_EXE_LINKER_FLAGS) - append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_SHARED_LINKER_FLAGS) - append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_MODULE_LINKER_FLAGS) + if(CXX_SUPPORTS_STDLIB) + append("-stdlib=libc++" + CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS + CMAKE_MODULE_LINKER_FLAGS) + if(LLVM_ENABLE_LIBCXXABI) + append("-lc++abi" + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS + CMAKE_MODULE_LINKER_FLAGS) + endif() + else() + message(WARNING "Can't specify libc++ with '-stdlib='") + endif() else() message(WARNING "Not sure how to specify libc++ for this compiler") endif()