title: Why CMake does not seem to apply -pthread using add_compile_options command?
body: <p>I am trying to compile a simple C++ program using g++ 4.8.2 using CMake 2.8.12.2 which makes use of C++11 features and also multithreading. For that, compiler flags -std=c++11 and -pthread must be used. From my understanding, in CMake, setting these flags can be done in various ways, one is to use the set command:</p>
  
  <pre><code>set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
  </code></pre>
  
  <p>The other (supposedly preferred) way is to use add_compile_options command:</p>
  
  <pre><code>add_compile_options(-std=c++11)
  add_compile_options(-pthread)
  </code></pre>
  
  <p>(Or in one line: <code>add_compile_options(-std=c++11 -pthread)</code>)</p>
  
  <p>So, the problem is that in my case, only the first method works - by using the set command. The problem is with using the add_compile_options which results in crash of the compiled output executable with the following message (just like the -pthread was not specified at all):</p>
  
  <pre><code>terminate called after throwing an instance of 'std::system_error'
    what():  Enable multithreading to use std::thread: Operation not permitted
  Aborted (core dumped)
  </code></pre>
  
  <p>The code I test with:</p>
  
  <pre><code>#include &lt;future&gt;
  
  int main()
  {
      auto a = std::async(std::launch::async, [](){});
      a.wait();
      return 0;
  }
  </code></pre>
  
  <p>From the fact that this program compiles, I can infer that -std=c++11 was applied. The question is that why -pthread is not applied?</p>