title: Adding compiler flags to CMakeLists.txt
body: <p>I want to use the newest version of Boost library and have the following contents of a <code>CMakeLists.txt</code> file:</p>
  
  <pre><code>cmake_minimum_required (VERSION 3.0)
  project (foo)
  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DBOOST_ERROR_CODE_HEADER_ONLY -lpthread")
  # set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread")
  
  add_executable (first first.cpp)
  </code></pre>
  
  <p>With that I keep getting the following linker error:</p>
  
  <blockquote>
    <p>undefined reference to `pthread_detach</p>
  </blockquote>
  
  <p>However, if I compile my code without the use of CMake, with the following command:</p>
  
  <pre><code>g++ foo.cpp -std=c++11 -DBOOST_ERROR_CODE_HEADER_ONLY -lpthread
  </code></pre>
  
  <p>It works fine.</p>
  
  <p>The question is how to get it to work using CMake. Why doesn't it work when I specify the compiler flags via setting <code>CMAKE_CXX_FLAGS</code>? I thought I might have to specify <code>CMAKE_EXE_LINKER_FLAGS</code> instead, but doing that doesn't help at all.</p>