1 # Download and unpack googletest at configure time
2 set(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest")
3 configure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY)
5 set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes
6 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
7 -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} .
9 WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
13 message(FATAL_ERROR "CMake step for googletest failed: ${result}")
17 COMMAND ${CMAKE_COMMAND} --build .
18 RESULT_VARIABLE result
19 WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
23 message(FATAL_ERROR "Build step for googletest failed: ${result}")
26 # Prevent overriding the parent project's compiler/linker
28 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
30 include(${GOOGLETEST_PREFIX}/googletest-paths.cmake)
32 # googletest doesn't seem to want to stay build warning clean so let's not hurt ourselves.
33 add_compile_options(-w)
35 # Add googletest directly to our build. This defines
36 # the gtest and gtest_main targets.
37 add_subdirectory(${GOOGLETEST_SOURCE_DIR}
38 ${GOOGLETEST_BINARY_DIR}
41 if(NOT DEFINED GTEST_COMPILE_COMMANDS)
42 set(GTEST_COMPILE_COMMANDS ON)
45 set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
46 set_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
47 set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
48 set_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})