mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
[Tests] Link gtest_main on the fetched-gtest path
The downloaded-gtest branch set GTEST_BOTH_LIBRARIES to `gtest` alone, while FindGTest sets it to both halves. Every test target links that list rather than picking an entry point, so on this path nothing provides main() and any test source that does not define its own fails at link with `undefined reference to main` pointing at crt1.o, naming neither gtest nor the line responsible. That stayed latent while every test carried its own four-line main(). A test that omits it now fails, and the error points at the C runtime rather than at gtest, which is a long way from the cause. Restoring both halves makes the two paths agree and drops the boilerplate requirement on new test sources. The 18 sources that still define main() keep linking: gtest_main.cc defines nothing but main, so the linker leaves its object in the archive unused rather than reporting a duplicate.
This commit is contained in:
parent
5aafeffe4c
commit
976a4a9a7e
1 changed files with 6 additions and 2 deletions
|
|
@ -30,7 +30,11 @@ if(NOT GTEST_FOUND)
|
|||
target_include_directories(gtest INTERFACE "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/gtest-src/include>")
|
||||
|
||||
set(GTEST_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/gtest-src/include")
|
||||
set(GTEST_BOTH_LIBRARIES gtest)
|
||||
# gtest_main is not optional here. FindGTest sets GTEST_BOTH_LIBRARIES to both halves, so this
|
||||
# has to match it or the two paths disagree about what provides main(). A test source that
|
||||
# defines its own main() gets away with the omission; one that does not fails at link with
|
||||
# `undefined reference to main` pointing at crt1.o, which names neither gtest nor this line.
|
||||
set(GTEST_BOTH_LIBRARIES gtest gtest_main)
|
||||
endif()
|
||||
|
||||
# Directory-scoped on purpose: the test subdirectories below add targets that include the
|
||||
|
|
@ -92,7 +96,7 @@ function(cockatrice_add_test)
|
|||
# Only needed when gtest was downloaded and add_subdirectory'd above. An imported gtest
|
||||
# target already carries its own dependency, so this must stay conditional.
|
||||
if(NOT GTEST_FOUND)
|
||||
add_dependencies(${ARG_NAME} gtest)
|
||||
add_dependencies(${ARG_NAME} gtest gtest_main)
|
||||
endif()
|
||||
|
||||
# MANUAL targets are built but deliberately kept out of ctest: benchmarks that need a card
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue