I am trying to make sense of previous help:
So I wrote a dead simple use-case of a project using gtest.
Currently I have:
% cat CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(p)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # release-1.12.1
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(googletest)
if(TARGET GTest::gtest_main)
message("Target was found")
endif()
find_package(GTest 1.12.1 REQUIRED)
# Now make sure hwy uses our gtest 1.12.1:
set(HWY_SYSTEM_GTEST ON CACHE BOOL "")
FetchContent_Declare(
hwy
GIT_REPOSITORY https://github.com/google/highway.git
GIT_TAG 22e3d7276f4157d4a47586ba9fd91dd6303f441a # 1.0.1
)
FetchContent_MakeAvailable(hwy)
If I run it, here is what I get:
$ cmake ..
[...]
Target was found
-- Found GTest: /usr/lib/x86_64-linux-gnu/libgtest.a (Required is at least version "1.12.1")
[...]
-- Found GTest: /usr/lib/x86_64-linux-gnu/cmake/GTest/GTestConfig.cmake (found version "1.10.0")
The output is total non-sense to me. I'd would like to re-inject the build tree of googletest 1.12.1 during building of hwy 1.0.1. My question is as follow: how should I do that in the above example ?
The original upstream documentation is quite unclear about integrating FetchContent_Declare with find_package().
The important part of the question was the following two lines:
# Now make sure hwy uses our gtest 1.12.1:
set(HWY_SYSTEM_GTEST ON CACHE BOOL "")
The mechanism to re-inject gtest into hwy. My question was not about simple direct usage of gtest through fetchcontent.