From 1b7969eee250d4e3d12666a909971dd26adcbd77 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Wed, 5 Feb 2014 00:02:37 +0000 Subject: [CMake] Move -stdlib=libc++ handling into its own file. r200744 moved this into cmake/config-ix.cmake, so that it would happen very early in the build process. However, standalone builds of Clang and other external projects never include this file (which is correct). Now, -stdlib=libc++ and the LLVM_COMPILER_IS_GCC_COMPATIBLE option are both set in a new include file, HandleLLVMStdlib, which is included by both config-ix.cmake and HandleLLVMOptions.cmake. This preserves existing behavior for projects relying on HandleLLVMOptions and still does the right thing for builds of LLVM itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200811 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/HandleLLVMOptions.cmake | 1 + cmake/modules/HandleLLVMStdlib.cmake | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 cmake/modules/HandleLLVMStdlib.cmake (limited to 'cmake/modules') diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index b40103ca18..9cb39ff268 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -2,6 +2,7 @@ # options and executing the appropriate CMake commands to realize the users' # selections. +include(HandleLLVMStdlib) include(AddLLVMDefinitions) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) diff --git a/cmake/modules/HandleLLVMStdlib.cmake b/cmake/modules/HandleLLVMStdlib.cmake new file mode 100644 index 0000000000..47bb6cddc8 --- /dev/null +++ b/cmake/modules/HandleLLVMStdlib.cmake @@ -0,0 +1,35 @@ +# This CMake module is responsible for setting the standard library to libc++ +# if the user has requested it. + +if(NOT DEFINED LLVM_STDLIB_HANDLED) + set(LLVM_STDLIB_HANDLED ON) + + if(CMAKE_COMPILER_IS_GNUCXX) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON) + elseif( MSVC ) + set(LLVM_COMPILER_IS_GCC_COMPATIBLE OFF) + elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) + 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() + 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) + else() + message(WARNING "Not sure how to specify libc++ for this compiler") + endif() + endif() +endif() -- cgit v1.2.3