[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / third-party / benchmark / cmake / GoogleTest.cmake.in
blobce653ac375acaf01b812e81e15f4633378f69fbf
1 cmake_minimum_required(VERSION 2.8.12)
3 project(googletest-download NONE)
5 # Enable ExternalProject CMake module
6 include(ExternalProject)
8 option(ALLOW_DOWNLOADING_GOOGLETEST "If googletest src tree is not found in location specified by GOOGLETEST_PATH, do fetch the archive from internet" OFF)
9 set(GOOGLETEST_PATH "/usr/src/googletest" CACHE PATH
10                     "Path to the googletest root tree. Should contain googletest and googlemock subdirs. And CMakeLists.txt in root, and in both of these subdirs")
12 # Download and install GoogleTest
14 message(STATUS "Looking for Google Test sources")
15 message(STATUS "Looking for Google Test sources in ${GOOGLETEST_PATH}")
16 if(EXISTS "${GOOGLETEST_PATH}"            AND IS_DIRECTORY "${GOOGLETEST_PATH}"            AND EXISTS "${GOOGLETEST_PATH}/CMakeLists.txt" AND
17    EXISTS "${GOOGLETEST_PATH}/googletest" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googletest" AND EXISTS "${GOOGLETEST_PATH}/googletest/CMakeLists.txt" AND
18    EXISTS "${GOOGLETEST_PATH}/googlemock" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googlemock" AND EXISTS "${GOOGLETEST_PATH}/googlemock/CMakeLists.txt")
19   message(STATUS "Found Google Test in ${GOOGLETEST_PATH}")
21   ExternalProject_Add(
22     googletest
23     PREFIX            "${CMAKE_BINARY_DIR}"
24     DOWNLOAD_DIR      "${CMAKE_BINARY_DIR}/download"
25     SOURCE_DIR        "${GOOGLETEST_PATH}" # use existing src dir.
26     BINARY_DIR        "${CMAKE_BINARY_DIR}/build"
27     CONFIGURE_COMMAND ""
28     BUILD_COMMAND     ""
29     INSTALL_COMMAND   ""
30     TEST_COMMAND      ""
31   )
32 else()
33   if(NOT ALLOW_DOWNLOADING_GOOGLETEST)
34     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.")
35     return()
36   else()
37     message(WARNING "Did not find Google Test sources! Fetching from web...")
38     ExternalProject_Add(
39       googletest
40       GIT_REPOSITORY    https://github.com/google/googletest.git
41       GIT_TAG           "release-1.11.0"
42       PREFIX            "${CMAKE_BINARY_DIR}"
43       STAMP_DIR         "${CMAKE_BINARY_DIR}/stamp"
44       DOWNLOAD_DIR      "${CMAKE_BINARY_DIR}/download"
45       SOURCE_DIR        "${CMAKE_BINARY_DIR}/src"
46       BINARY_DIR        "${CMAKE_BINARY_DIR}/build"
47       CONFIGURE_COMMAND ""
48       BUILD_COMMAND     ""
49       INSTALL_COMMAND   ""
50       TEST_COMMAND      ""
51     )
52   endif()
53 endif()
55 ExternalProject_Get_Property(googletest SOURCE_DIR BINARY_DIR)
56 file(WRITE googletest-paths.cmake
57 "set(GOOGLETEST_SOURCE_DIR \"${SOURCE_DIR}\")
58 set(GOOGLETEST_BINARY_DIR \"${BINARY_DIR}\")