title: CMake + GoogleTest not running tests, no output
body: <p>I would like some help setting up google test and cmake. I am using Visual Studio 2017 as my ide/compiler. </p>
  
  <p>My main problem is that I am not sure whether my tests are getting run or even working! I run the RUN_TESTS project and everything seems to run ok but I don't get any print out that google test main ran. e.g "Running main() from gtest_main.cc" etc.  </p>
  
  <p>This is what I would like...</p>
  
  <ol>
  <li>keep my project code separate from test code </li>
  <li>the option of having my code (the classes to be tested) as part of a project </li>
  <li>or as a separate library that a project links to.  </li>
  </ol>
  
  <p>I would like my tests to be able to handle both cases 2) &amp; 3).</p>
  
  <p>I also am including my code in my test executable like below which I don't think is the right way to do it. </p>
  
  <pre><code>add_executable (unit_tests example.h example.cpp test/example_add.cpp test/example_subtract.cpp)
  </code></pre>
  
  <p>And also I am using #include "../example.h" in my test files to include my code to be tested. I don't think that is right. CMake should have already added the include path to the project settings?</p>
  
  <p>I have the following folder structure for my cmake project. example.h/.cpp is some code that I want to be tested. It is currently set up within a project like I describe in case 2) above. </p>
  
  <p>\Project2</p>
  
  <p>---\src<br>
    ------CMakeLists.txt<br>
    ------CMakeLists.txt.in<br>
    ------example.cpp<br>
    ------example.h<br>
    ------main.cpp<br>
    ------\test<br>
    ---------example_add.cpp<br>
    ---------example_subtract.cpp</p>
  
  <p><strong>CMakeLists.txt</strong></p>
  
  <pre><code>cmake_minimum_required (VERSION 3.9)
  project (Project2)
  
  include (CTest)
  
  # The version number.
  set (Project2_VERSION_MAJOR 1)
  set (Project2_VERSION_MINOR 0)
  
  # add the binary tree to the search path for include files
  # so that we will find Project1Config.h
  include_directories ("${PROJECT_BINARY_DIR}")
  
  # Download and unpack googletest at configure time
  configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
  execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
    RESULT_VARIABLE result
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
  if(result)
    message(FATAL_ERROR "CMake step for googletest failed: ${result}")
  endif()
  execute_process(COMMAND ${CMAKE_COMMAND} --build .
    RESULT_VARIABLE result
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
  if(result)
    message(FATAL_ERROR "Build step for googletest failed: ${result}")
  endif()
  
  # Prevent overriding the parent project's compiler/linker
  # settings on Windows
  set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  
  # Add googletest directly to our build. This defines
  # the gtest and gtest_main targets.
  add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
                   ${CMAKE_BINARY_DIR}/googletest-build
                   EXCLUDE_FROM_ALL)
  
  # The gtest/gtest_main targets carry header search path
  # dependencies automatically when using CMake 2.8.11 or
  # later. Otherwise, we have to add them here ourselves.
  if (CMAKE_VERSION VERSION_LESS 2.8.11)
    include_directories("${gtest_SOURCE_DIR}/include")
  endif()
  
  # add the executable
  add_executable (Project2 main.cpp example.h example.cpp)
  target_link_libraries(Project2 gtest_main)
  target_link_libraries (Project2 ${EXTRA_LIBS})
  
  add_executable (unit_tests example.h example.cpp test/example_add.cpp test/example_subtract.cpp)
  target_link_libraries (unit_tests gtest_main)
  #
  #
  #   INSTALL
  #
  #
  
  # add the install targets
  install (TARGETS Project2 DESTINATION bin)
  
  #
  #
  #   TESTS
  #
  #
  
  add_test (NAME example_test COMMAND Project2)
  add_test (NAME unit COMMAND ${CMAKE_BINARY_DIR}/unit_tests)
  </code></pre>
  
  <p><strong>CMakeLists.txt.in</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.9)
  
  project(googletest-download NONE)
  
  include(ExternalProject)
  ExternalProject_Add(googletest
    GIT_REPOSITORY    https://github.com/google/googletest.git
    GIT_TAG           master
    SOURCE_DIR        "${CMAKE_BINARY_DIR}/googletest-src"
    BINARY_DIR        "${CMAKE_BINARY_DIR}/googletest-build"
    CONFIGURE_COMMAND ""
    BUILD_COMMAND     ""
    INSTALL_COMMAND   ""
    TEST_COMMAND      ""
  )
  </code></pre>
  
  <p><strong>example.h</strong></p>
  
  <pre><code>#pragma once
  
  double add_numbers(const double f1, const double f2);
  
  double subtract_numbers(const double f1, const double f2);
  
  double multiply_numbers(const double f1, const double f2);
  </code></pre>
  
  <p><strong>example.cpp</strong></p>
  
  <pre><code>#include "example.h"
  
  double add_numbers(const double f1, const double f2)
  {
      return f1 + f2;
  }
  
  double subtract_numbers(const double f1, const double f2)
  {
      return f1 - f2;
  }
  
  double multiply_numbers(const double f1, const double f2)
  {
      return f1 * f2;
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; "hello, world!" &lt;&lt; std::endl;
  
      return 0;
  } 
  </code></pre>
  
  <p><strong>example_add.cpp</strong></p>
  
  <pre><code>#include "gtest/gtest.h"
  #include "../example.h"
  
  TEST(example, add)
  {
      double res;
      res = add_numbers(1.0, 2.0);
      ASSERT_NEAR(res, 3.0, 1.0e-11);
  }
  </code></pre>
  
  <p><strong>example_subtract.cpp</strong></p>
  
  <pre><code>#include "gtest/gtest.h"
  #include "../example.h"
  
  TEST(example, subtract)
  {
      double res;
      res = subtract_numbers(1.0, 2.0);
      ASSERT_NEAR(res, -1.0, 1.0e-11);
  }
  </code></pre>