You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.2 KiB

1 month ago
  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)
  4. set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes
  5. execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
  6. -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} .
  7. RESULT_VARIABLE result
  8. WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
  9. )
  10. if(result)
  11. message(FATAL_ERROR "CMake step for googletest failed: ${result}")
  12. endif()
  13. execute_process(
  14. COMMAND ${CMAKE_COMMAND} --build .
  15. RESULT_VARIABLE result
  16. WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
  17. )
  18. if(result)
  19. message(FATAL_ERROR "Build step for googletest failed: ${result}")
  20. endif()
  21. # Prevent overriding the parent project's compiler/linker
  22. # settings on Windows
  23. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  24. include(${GOOGLETEST_PREFIX}/googletest-paths.cmake)
  25. # googletest doesn't seem to want to stay build warning clean so let's not hurt ourselves.
  26. if (MSVC)
  27. add_compile_options(/wd4244 /wd4722)
  28. else()
  29. add_compile_options(-w)
  30. endif()
  31. # Add googletest directly to our build. This defines
  32. # the gtest and gtest_main targets.
  33. add_subdirectory(${GOOGLETEST_SOURCE_DIR}
  34. ${GOOGLETEST_BINARY_DIR}
  35. EXCLUDE_FROM_ALL)
  36. if(NOT DEFINED GTEST_COMPILE_COMMANDS)
  37. set(GTEST_COMPILE_COMMANDS ON)
  38. endif()
  39. set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
  40. set_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
  41. set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})
  42. set_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock_main,INTERFACE_INCLUDE_DIRECTORIES> EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS})