1# Download and unpack googletest at configure time 2set(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest") 3configure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY) 4 5set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes 6execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" 7 -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} . 8 RESULT_VARIABLE result 9 WORKING_DIRECTORY ${GOOGLETEST_PREFIX} 10) 11 12if(result) 13 message(FATAL_ERROR "CMake step for googletest failed: ${result}") 14endif() 15 16execute_process( 17 COMMAND ${CMAKE_COMMAND} --build . 18 RESULT_VARIABLE result 19 WORKING_DIRECTORY ${GOOGLETEST_PREFIX} 20) 21 22if(result) 23 message(FATAL_ERROR "Build step for googletest failed: ${result}") 24endif() 25 26# Prevent overriding the parent project's compiler/linker 27# settings on Windows 28set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 29 30include(${GOOGLETEST_PREFIX}/googletest-paths.cmake) 31 32# Add googletest directly to our build. This defines 33# the gtest and gtest_main targets. 34add_subdirectory(${GOOGLETEST_SOURCE_DIR} 35 ${GOOGLETEST_BINARY_DIR} 36 EXCLUDE_FROM_ALL) 37 38set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>) 39set_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest_main,INTERFACE_INCLUDE_DIRECTORIES>) 40set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock,INTERFACE_INCLUDE_DIRECTORIES>) 41set_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock_main,INTERFACE_INCLUDE_DIRECTORIES>) 42