title: CMAKE: switch between clang / g++ and libc++ /libstdc++
body: <p>This is my first cmake file. I have a linux system with both clang and g++. Also libc++ is installed. I develop on Mac (xcode) but deploy to linux.
  I am writing a cmake file in which I can pick either clang or g++ and libc++ or libstdc++. So 4 possible combinations.</p>
  
  <p>I figured out how to select the compiler and force c++11 on it, but I can't figure out how to specify the standard library. Any suggestions?</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>## cmake ###
  cmake_minimum_required (VERSION 3.5)
  
  #set project directories
  set(ProjectDirectory ${CMAKE_SOURCE_DIR}) #.../Project/
  set(BuildDirectory ${ProjectDirectory}/Build)
  set(ProductDirectory ${ProjectDirectory}/Products)
  set(sourceDirectory ${ProjectDirectory}/Source)
  
  #print project directories
  message(${ProjectDirectory})
  message(${BuildDirectory})
  message(${ProductDirectory})
  
  #configure cmake
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ProductDirectory})
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ProductDirectory})
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ProductDirectory})
  
  set(CMAKE_VERBOSE_MAKEFILE on)
  
  #compiler and standard library settings
  set(CMAKE_CXX_COMPILER "clang++")
  set(CMAKE_CXX_STANDARD 11)
  #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -stdlib=libc++")
          #libstdc++ #linux
          #libc++    #OS X
  
  #compiler flags
  SET( CompilerFlags  " ")
  #SET( CompilerFlags  "${CompilerFlags} -stdlib=libc++" )
  SET( CompilerFlags  "${CompilerFlags} -Wno-unknown-pragmas" )
  SET( CompilerFlags  "${CompilerFlags} -Wall" )
  SET( CompilerFlags  "${CompilerFlags} -Wextra" )
  
  set (CMAKE_CXX_FLAGS ${CompilerFlags})
  
  #linker flags
  #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
  
  #message(${CMAKE_CXX_FLAGS})
  
  ##################
  ### Libraries ###
  ################
  ### common library ###
  project(common)
  
  #message(STATUS ${CMAKE_CXX_FLAGS})
  
  #source files
  #set (commonSource ${sourceDirectory}/Object/object.cpp) #specify specific files
  file(GLOB_RECURSE commonSource ${sourceDirectory}/Object/*.cpp) # recursive
  
  #targets
  add_library (common STATIC ${commonSource})
  
  #target_compile_options (common PUBLIC ${CompilerFlags})
  
  
  #####################
  ### Applications ###
  ###################
  ### Hello project ###
  project (hello)
  
  #source files
  #set (helloSource ${sourceDirectory}/main.cpp)
  
  #targets
  #add_executable (hello ${helloSource})
  
  #linking
  #target_link_libraries (hello common)
  
  
  #install(TARGETS common DESTINATION ${ProductDirectory})
  </code></pre>
  
  <p>I run this command on a console</p>
  
  <pre><code>../Project/Build$ rm -r *; rm -r ../Products/*; cmake ..; make VERBOSE=1;
  </code></pre>
  
  <p>My folder structure is:</p>
  
  <pre><code>Project
      Source
      Build
      Products
      CMakeLists.txt
  </code></pre>
  
  <p>I have also noticed that the compiler flags are sometimes ignored and only used when I run cmake and make a second time.</p>
  
  <p>Also, I use a lot of <code>#warning todo</code> in my code
  How can I disable these warnings during compilation?</p>