mirror of
https://github.com/google/benchmark.git
synced 2024-12-28 21:40:15 +08:00
4b77194032
https://github.com/google/benchmark/pull/801 is stuck with some cryptic cmake failure due to some linking issue between googletest and threading libraries. I suspect that is mostly happening because of the, uhm, intentionally extremely twisted-in-the-brains approach that is being used to actually build the library as part of the buiild, except without actually building it as part of the build. If we do actually build it as part of the build, then all the transitive dependencies should magically be in order, and maybe everything will just work. This new version of cmake magic was written by me in0e22f085c5/cmake/Modules/GoogleTest.cmake.in
0e22f085c5/cmake/Modules/GoogleTest.cmake
, based on the official googletest docs and LOTS of experimentation.
59 lines
2.5 KiB
CMake
59 lines
2.5 KiB
CMake
cmake_minimum_required(VERSION 2.8.12)
|
|
|
|
project(googletest-download NONE)
|
|
|
|
# Enable ExternalProject CMake module
|
|
include(ExternalProject)
|
|
|
|
option(ALLOW_DOWNLOADING_GOOGLETEST "If googletest src tree is not found in location specified by GOOGLETEST_PATH, do fetch the archive from internet" OFF)
|
|
set(GOOGLETEST_PATH "/usr/src/googletest" CACHE PATH
|
|
"Path to the googletest root tree. Should contain googletest and googlemock subdirs. And CMakeLists.txt in root, and in both of these subdirs")
|
|
|
|
# Download and install GoogleTest
|
|
|
|
message(STATUS "Looking for Google Test sources")
|
|
message(STATUS "Looking for Google Test sources in ${GOOGLETEST_PATH}")
|
|
if(EXISTS "${GOOGLETEST_PATH}" AND IS_DIRECTORY "${GOOGLETEST_PATH}" AND EXISTS "${GOOGLETEST_PATH}/CMakeLists.txt" AND
|
|
EXISTS "${GOOGLETEST_PATH}/googletest" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googletest" AND EXISTS "${GOOGLETEST_PATH}/googletest/CMakeLists.txt" AND
|
|
EXISTS "${GOOGLETEST_PATH}/googlemock" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googlemock" AND EXISTS "${GOOGLETEST_PATH}/googlemock/CMakeLists.txt")
|
|
message(STATUS "Found Google Test in ${GOOGLETEST_PATH}")
|
|
|
|
ExternalProject_Add(
|
|
googletest
|
|
PREFIX "${CMAKE_BINARY_DIR}"
|
|
DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/download"
|
|
SOURCE_DIR "${GOOGLETEST_PATH}" # use existing src dir.
|
|
BINARY_DIR "${CMAKE_BINARY_DIR}/build"
|
|
CONFIGURE_COMMAND ""
|
|
BUILD_COMMAND ""
|
|
INSTALL_COMMAND ""
|
|
TEST_COMMAND ""
|
|
)
|
|
else()
|
|
if(NOT ALLOW_DOWNLOADING_GOOGLETEST)
|
|
message(SEND_ERROR "Did not find Google Test sources! Either pass correct path in GOOGLETEST_PATH, or enable ALLOW_DOWNLOADING_GOOGLETEST, or disable BENCHMARK_ENABLE_GTEST_TESTS / BENCHMARK_ENABLE_TESTING.")
|
|
else()
|
|
message(WARNING "Did not find Google Test sources! Fetching from web...")
|
|
ExternalProject_Add(
|
|
googletest
|
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
GIT_TAG master
|
|
PREFIX "${CMAKE_BINARY_DIR}"
|
|
STAMP_DIR "${CMAKE_BINARY_DIR}/stamp"
|
|
DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/download"
|
|
SOURCE_DIR "${CMAKE_BINARY_DIR}/src"
|
|
BINARY_DIR "${CMAKE_BINARY_DIR}/build"
|
|
CONFIGURE_COMMAND ""
|
|
BUILD_COMMAND ""
|
|
INSTALL_COMMAND ""
|
|
TEST_COMMAND ""
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
ExternalProject_Get_Property(googletest SOURCE_DIR BINARY_DIR)
|
|
file(WRITE googletest-paths.cmake
|
|
"set(GOOGLETEST_SOURCE_DIR \"${SOURCE_DIR}\")
|
|
set(GOOGLETEST_BINARY_DIR \"${BINARY_DIR}\")
|
|
")
|