15dda2efdSMircea Trofin# Download and unpack googletest at configure time 25dda2efdSMircea Trofinset(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest") 35dda2efdSMircea Trofinconfigure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY) 45dda2efdSMircea Trofin 55dda2efdSMircea Trofinset(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes 65dda2efdSMircea Trofinexecute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" 75dda2efdSMircea Trofin -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} . 85dda2efdSMircea Trofin RESULT_VARIABLE result 95dda2efdSMircea Trofin WORKING_DIRECTORY ${GOOGLETEST_PREFIX} 105dda2efdSMircea Trofin) 115dda2efdSMircea Trofin 125dda2efdSMircea Trofinif(result) 135dda2efdSMircea Trofin message(FATAL_ERROR "CMake step for googletest failed: ${result}") 145dda2efdSMircea Trofinendif() 155dda2efdSMircea Trofin 165dda2efdSMircea Trofinexecute_process( 175dda2efdSMircea Trofin COMMAND ${CMAKE_COMMAND} --build . 185dda2efdSMircea Trofin RESULT_VARIABLE result 195dda2efdSMircea Trofin WORKING_DIRECTORY ${GOOGLETEST_PREFIX} 205dda2efdSMircea Trofin) 215dda2efdSMircea Trofin 225dda2efdSMircea Trofinif(result) 235dda2efdSMircea Trofin message(FATAL_ERROR "Build step for googletest failed: ${result}") 245dda2efdSMircea Trofinendif() 255dda2efdSMircea Trofin 265dda2efdSMircea Trofin# Prevent overriding the parent project's compiler/linker 275dda2efdSMircea Trofin# settings on Windows 285dda2efdSMircea Trofinset(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 295dda2efdSMircea Trofin 305dda2efdSMircea Trofininclude(${GOOGLETEST_PREFIX}/googletest-paths.cmake) 315dda2efdSMircea Trofin 325dda2efdSMircea Trofin# Add googletest directly to our build. This defines 335dda2efdSMircea Trofin# the gtest and gtest_main targets. 345dda2efdSMircea Trofinadd_subdirectory(${GOOGLETEST_SOURCE_DIR} 355dda2efdSMircea Trofin ${GOOGLETEST_BINARY_DIR} 365dda2efdSMircea Trofin EXCLUDE_FROM_ALL) 375dda2efdSMircea Trofin 38*a5b79717SMircea Trofin# googletest doesn't seem to want to stay build warning clean so let's not hurt ourselves. 39*a5b79717SMircea Trofinif (MSVC) 40*a5b79717SMircea Trofin target_compile_options(gtest PRIVATE "/wd4244" "/wd4722") 41*a5b79717SMircea Trofin target_compile_options(gtest_main PRIVATE "/wd4244" "/wd4722") 42*a5b79717SMircea Trofin target_compile_options(gmock PRIVATE "/wd4244" "/wd4722") 43*a5b79717SMircea Trofin target_compile_options(gmock_main PRIVATE "/wd4244" "/wd4722") 44*a5b79717SMircea Trofinelse() 45*a5b79717SMircea Trofin target_compile_options(gtest PRIVATE "-w") 46*a5b79717SMircea Trofin target_compile_options(gtest_main PRIVATE "-w") 47*a5b79717SMircea Trofin target_compile_options(gmock PRIVATE "-w") 48*a5b79717SMircea Trofin target_compile_options(gmock_main PRIVATE "-w") 49*a5b79717SMircea Trofinendif() 50*a5b79717SMircea Trofin 51a290770fSMircea Trofinif(NOT DEFINED GTEST_COMPILE_COMMANDS) 52a290770fSMircea Trofin set(GTEST_COMPILE_COMMANDS ON) 53a290770fSMircea Trofinendif() 54a290770fSMircea Trofin 55a290770fSMircea Trofinset_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 56a290770fSMircea Trofinset_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 57a290770fSMircea Trofinset_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 58a290770fSMircea Trofinset_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 59