title: cmake does not consider -pthread
body: <p>I am trying to make a testbench to my program using gmock/gtest; Linux/Ubuntu; KDevelop/CMake. From the link error message I conclude that part of the gtest package is missing pthread support. </p>
  
  <pre><code>/home/projects/cpp/gmock/gtest/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal&lt;testing::TestPartResultReporterInterface*&gt;::~ThreadLocal()':
  gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x16): undefined reference to `pthread_getspecific'
  gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x2b): undefined reference to `pthread_key_delete'
  </code></pre>
  
  <p>I also read  </p>
  
  <p><a href="https://stackoverflow.com/questions/8739495/googletest-how-to-setup">googletest: how to setup?</a></p>
  
  <p>Using g++ directly, everything works. So, since I am usinc KDevelop/CMake, I suspect either my code or CMake.</p>
  
  <p>In my CMakeLists.txt I do use </p>
  
  <pre><code>add_definitions( -pthread  -m64)
  </code></pre>
  
  <p>However, I do not see any effect in the Makefile. 
  Am I missing something from my CMakeLists.txt, or CMake does not consider the line above?</p>
  
  <p>My CMakeLists.txt</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  add_definitions( -Dpthread )
  
  project(ThreadTest)
  
  INCLUDE_DIRECTORIES(gmock/gtest/include)
  
  set ( GTEST_LIBS libgtest.a )
  link_directories( ~/projects/cpp/gmock/gtest)
  
  add_executable(ThreadTest main_test.cpp)
  target_link_libraries(ThreadTest  ${GTEST_LIBS})
  </code></pre>
  
  <p>Do I misunderstand, that add_definitions should work in this situation?</p>
  
  <p>After reading 
  <a href="https://stackoverflow.com/questions/5395309/cmake-and-threads">How do I force cmake to include &quot;-pthread&quot; option during compilation?</a>
  my question  really looks like duplicate. However, </p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  add_definitions( -Dpthread )
  
  project(ThreadTest)
  
  INCLUDE_DIRECTORIES(gmock/gtest/include)
  
  find_package( Threads )
  set ( GTEST_LIBS libgtest.a )
  link_directories( ~/projects/cpp/gmock/gtest)
  
  add_executable(ThreadTest main_test.cpp)
  target_link_libraries(ThreadTest  ${GTEST_LIBS}  ${CMAKE_THREAD_LIBS_INIT})
  </code></pre>
  
  <p>still gives the warning 'Could NOT find Threads'. I tried to search Ubuntu software center for "threads", with no result. After that, I installed libghc-threads-dev. However, when using</p>
  
  <pre><code>set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  find_package(Threads REQUIRED)
  </code></pre>
  
  <p>I keep receiving 'Could NOT find Threads', as error. What shall I do to satisfy find_package, and why do I have this problem, when the simple Makefile produces what I expect?</p>
  
  <p>PS: my main file:</p>
  
  <pre><code>#include "gmock/gtest/include/gtest/gtest.h"
  
  TEST(blahTest, blah1) {
      EXPECT_EQ(1, 1);
  }
  
  int main (int argc, char** argv) {
      ::testing::InitGoogleTest(&amp;argc, argv);
  
      int returnValue;
  
      returnValue =  RUN_ALL_TESTS();
  
       return returnValue;
  }
  </code></pre>