Skip to content

Commit

Permalink
cmake: when linking googletest switch alias to fetchcontent side so t…
Browse files Browse the repository at this point in the history
…hat we use the namespaced target (and potentially avoid adding -lgtest_main to the command line)
  • Loading branch information
nmm0 committed Feb 14, 2025
1 parent 6b9bead commit 920f2b9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function(mdspan_add_test name)
set_source_files_properties(${name} PROPERTIES LANGUAGE ${MDSPAN_TEST_LANGUAGE})
endif()
add_executable(${name} ${ARGUMENT_SOURCE})
target_link_libraries(${name} mdspan gtest_main)
target_link_libraries(${name} mdspan GTest::gtest_main)
add_test(${name} ${name})
set_property(TARGET ${name} PROPERTY COMPILE_WARNING_AS_ERROR ON)
target_compile_definitions(${name}
Expand All @@ -31,7 +31,6 @@ endfunction()

if(MDSPAN_USE_SYSTEM_GTEST)
find_package(GTest CONFIG REQUIRED)
add_library(gtest_main ALIAS GTest::gtest_main)
else()
include(FetchContent)

Expand All @@ -42,6 +41,8 @@ else()
)

fetchcontent_makeavailable(googletest)

add_library(GTest::gtest_main ALIAS gtest_main)
endif()

# FIXME_MSVC
Expand Down

0 comments on commit 920f2b9

Please sign in to comment.