mirror of
https://github.com/google/benchmark.git
synced 2025-04-02 07:31:05 +08:00
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.
41 lines
1.7 KiB
CMake
41 lines
1.7 KiB
CMake
# Download and unpack googletest at configure time
|
|
set(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest")
|
|
configure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY)
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
|
|
-DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH="${CMAKE_CURRENT_SOURCE_DIR}/googletest" .
|
|
RESULT_VARIABLE result
|
|
WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
|
|
)
|
|
|
|
if(result)
|
|
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
|
endif()
|
|
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} --build .
|
|
RESULT_VARIABLE result
|
|
WORKING_DIRECTORY ${GOOGLETEST_PREFIX}
|
|
)
|
|
|
|
if(result)
|
|
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
|
endif()
|
|
|
|
# Prevent overriding the parent project's compiler/linker
|
|
# settings on Windows
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
|
|
include(${GOOGLETEST_PREFIX}/googletest-paths.cmake)
|
|
|
|
# Add googletest directly to our build. This defines
|
|
# the gtest and gtest_main targets.
|
|
add_subdirectory(${GOOGLETEST_SOURCE_DIR}
|
|
${GOOGLETEST_BINARY_DIR}
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
set_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gtest_main,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
set_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:gmock_main,INTERFACE_INCLUDE_DIRECTORIES>)
|