googletest.cmake 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function(download_googltest)
  2. include(FetchContent)
  3. set(googletest_URL "https://github.com/google/googletest/archive/release-1.10.0.tar.gz")
  4. set(googletest_HASH "SHA256=9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb")
  5. set(BUILD_GMOCK ON CACHE BOOL "" FORCE)
  6. set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
  7. set(gtest_disable_pthreads ON CACHE BOOL "" FORCE)
  8. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  9. FetchContent_Declare(googletest
  10. URL ${googletest_URL}
  11. URL_HASH ${googletest_HASH}
  12. )
  13. FetchContent_GetProperties(googletest)
  14. if(NOT googletest_POPULATED)
  15. message(STATUS "Downloading googletest")
  16. FetchContent_Populate(googletest)
  17. endif()
  18. message(STATUS "googletest is downloaded to ${googletest_SOURCE_DIR}")
  19. message(STATUS "googletest's binary dir is ${googletest_BINARY_DIR}")
  20. if(APPLE)
  21. set(CMAKE_MACOSX_RPATH ON) # to solve the following warning on macOS
  22. endif()
  23. #[==[
  24. -- Generating done
  25. Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
  26. --help-policy CMP0042" for policy details. Use the cmake_policy command to
  27. set the policy and suppress this warning.
  28. MACOSX_RPATH is not specified for the following targets:
  29. gmock
  30. gmock_main
  31. gtest
  32. gtest_main
  33. This warning is for project developers. Use -Wno-dev to suppress it.
  34. ]==]
  35. add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
  36. target_include_directories(gtest
  37. INTERFACE
  38. ${googletest_SOURCE_DIR}/googletest/include
  39. ${googletest_SOURCE_DIR}/googlemock/include
  40. )
  41. endfunction()
  42. download_googltest()