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.

59 lines
2.6 KiB

1 month ago
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(googletest-download NONE)
  3. # Enable ExternalProject CMake module
  4. include(ExternalProject)
  5. option(ALLOW_DOWNLOADING_GOOGLETEST "If googletest src tree is not found in location specified by GOOGLETEST_PATH, do fetch the archive from internet" OFF)
  6. set(GOOGLETEST_PATH "/usr/src/googletest" CACHE PATH
  7. "Path to the googletest root tree. Should contain googletest and googlemock subdirs. And CMakeLists.txt in root, and in both of these subdirs")
  8. # Download and install GoogleTest
  9. message(STATUS "Looking for Google Test sources")
  10. message(STATUS "Looking for Google Test sources in ${GOOGLETEST_PATH}")
  11. if(EXISTS "${GOOGLETEST_PATH}" AND IS_DIRECTORY "${GOOGLETEST_PATH}" AND EXISTS "${GOOGLETEST_PATH}/CMakeLists.txt" AND
  12. EXISTS "${GOOGLETEST_PATH}/googletest" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googletest" AND EXISTS "${GOOGLETEST_PATH}/googletest/CMakeLists.txt" AND
  13. EXISTS "${GOOGLETEST_PATH}/googlemock" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googlemock" AND EXISTS "${GOOGLETEST_PATH}/googlemock/CMakeLists.txt")
  14. message(STATUS "Found Google Test in ${GOOGLETEST_PATH}")
  15. ExternalProject_Add(
  16. googletest
  17. PREFIX "${CMAKE_BINARY_DIR}"
  18. DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/download"
  19. SOURCE_DIR "${GOOGLETEST_PATH}" # use existing src dir.
  20. BINARY_DIR "${CMAKE_BINARY_DIR}/build"
  21. CONFIGURE_COMMAND ""
  22. BUILD_COMMAND ""
  23. INSTALL_COMMAND ""
  24. TEST_COMMAND ""
  25. )
  26. else()
  27. if(NOT ALLOW_DOWNLOADING_GOOGLETEST)
  28. message(SEND_ERROR "Did not find Google Test sources! Either pass correct path in GOOGLETEST_PATH, or enable BENCHMARK_DOWNLOAD_DEPENDENCIES, or disable BENCHMARK_USE_BUNDLED_GTEST, or disable BENCHMARK_ENABLE_GTEST_TESTS / BENCHMARK_ENABLE_TESTING.")
  29. return()
  30. else()
  31. message(WARNING "Did not find Google Test sources! Fetching from web...")
  32. ExternalProject_Add(
  33. googletest
  34. GIT_REPOSITORY https://github.com/google/googletest.git
  35. GIT_TAG "release-1.11.0"
  36. PREFIX "${CMAKE_BINARY_DIR}"
  37. STAMP_DIR "${CMAKE_BINARY_DIR}/stamp"
  38. DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/download"
  39. SOURCE_DIR "${CMAKE_BINARY_DIR}/src"
  40. BINARY_DIR "${CMAKE_BINARY_DIR}/build"
  41. CONFIGURE_COMMAND ""
  42. BUILD_COMMAND ""
  43. INSTALL_COMMAND ""
  44. TEST_COMMAND ""
  45. )
  46. endif()
  47. endif()
  48. ExternalProject_Get_Property(googletest SOURCE_DIR BINARY_DIR)
  49. file(WRITE googletest-paths.cmake
  50. "set(GOOGLETEST_SOURCE_DIR \"${SOURCE_DIR}\")
  51. set(GOOGLETEST_BINARY_DIR \"${BINARY_DIR}\")
  52. ")