Home | History | Annotate | Download | only in modules
      1 # This CMake module is responsible for setting the standard library to libc++
      2 # if the user has requested it.
      3 
      4 if(NOT DEFINED LLVM_STDLIB_HANDLED)
      5   set(LLVM_STDLIB_HANDLED ON)
      6 
      7   if(CMAKE_COMPILER_IS_GNUCXX)
      8     set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON)
      9   elseif( MSVC )
     10     set(LLVM_COMPILER_IS_GCC_COMPATIBLE OFF)
     11   elseif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
     12     set(LLVM_COMPILER_IS_GCC_COMPATIBLE ON)
     13   endif()
     14 
     15   function(append_if condition value)
     16     if(${condition})
     17       foreach(variable ${ARGN})
     18         set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
     19       endforeach(variable)
     20     endif()
     21   endfunction()
     22 
     23   include(CheckCXXCompilerFlag)
     24   if(LLVM_ENABLE_LIBCXX)
     25     if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
     26       check_cxx_compiler_flag("-stdlib=libc++" CXX_SUPPORTS_STDLIB)
     27       append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_CXX_FLAGS)
     28       append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_EXE_LINKER_FLAGS)
     29       append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_SHARED_LINKER_FLAGS)
     30       append_if(CXX_SUPPORTS_STDLIB "-stdlib=libc++" CMAKE_MODULE_LINKER_FLAGS)
     31     else()
     32       message(WARNING "Not sure how to specify libc++ for this compiler")
     33     endif()
     34   endif()
     35 endif()
     36