Skip to content

Commit

Permalink
cmake: remove manual download for googletest and use fetchcontent ins…
Browse files Browse the repository at this point in the history
…tead
  • Loading branch information
nmm0 committed Feb 14, 2025
1 parent ebfc8f5 commit 6b9bead
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
16 changes: 0 additions & 16 deletions cmake/googletest/CMakeLists.txt.in

This file was deleted.

34 changes: 8 additions & 26 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,15 @@ if(MDSPAN_USE_SYSTEM_GTEST)
find_package(GTest CONFIG REQUIRED)
add_library(gtest_main ALIAS GTest::gtest_main)
else()
# adapted from https://github.com/google/googletest/blob/master/googletest/README.md
configure_file(${PROJECT_SOURCE_DIR}/cmake/googletest/CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
)
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)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL
include(FetchContent)

fetchcontent_declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.16.0
)

fetchcontent_makeavailable(googletest)
endif()

# FIXME_MSVC
Expand Down

0 comments on commit 6b9bead

Please sign in to comment.