@@ -3,4 +3,47 @@ project(gtest_coverage)
33
44set (CMAKE_CXX_STANDARD 20)
55
6- add_executable (gtest_coverage main.cpp src/testsubject.cpp)
6+ # Reference: https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
7+ # Download and unpack googletest at configure time
8+ configure_file (CMakeLists.txt.in googletest-download/CMakeLists.txt)
9+ execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR} " .
10+ RESULT_VARIABLE result
11+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /googletest-download)
12+ if (result)
13+ message (FATAL_ERROR "CMake step for googletest failed: ${result} " )
14+ endif ()
15+ execute_process (COMMAND ${CMAKE_COMMAND} --build .
16+ RESULT_VARIABLE result
17+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /googletest-download)
18+ if (result)
19+ message (FATAL_ERROR "Build step for googletest failed: ${result} " )
20+ endif ()
21+
22+ # Prevent overriding the parent project's compiler/linker
23+ # settings on Windows
24+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
25+
26+ # Add googletest directly to our build. This defines
27+ # the gtest and gtest_main targets.
28+ add_subdirectory (${CMAKE_CURRENT_BINARY_DIR} /googletest-src
29+ ${CMAKE_CURRENT_BINARY_DIR} /googletest-build
30+ EXCLUDE_FROM_ALL )
31+
32+ # The gtest/gtest_main targets carry header search path
33+ # dependencies automatically when using CMake 2.8.11 or
34+ # later. Otherwise we have to add them here ourselves.
35+ if (CMAKE_VERSION VERSION_LESS 2.8.11)
36+ include_directories ("${gtest_SOURCE_DIR} /include" )
37+ endif ()
38+
39+ # Now simply link against gtest or gtest_main as needed.
40+ include_directories (cmake-build -debug/googletest-src/googlemock/include )
41+ include_directories (cmake-build -debug/googletest-src/googletest/include )
42+
43+ set (SOURCE_FILES src/testsubject.cpp)
44+ add_executable (main main.cpp ${SOURCE_FILES} )
45+
46+ set (TEST_FILES test /tester.cpp)
47+ add_executable (test ${TEST_FILES} ${SOURCE_FILES} )
48+
49+ target_link_libraries (test gtest gtest_main)
0 commit comments