I have a C++ project using CMake as a build system, and I’d like to use cucumber-cpp
. In this project, I have a GTest/ GMock dependency which I resolve as per the instructions here (mixture of FetchContent_Declare
and FetchContent_MakeAvailable
).
I then try to add the cucumber-cpp
dependency with the following:
ExternalProject_Add(
CucumberCpp
GIT_REPOSITORY "https://github.com/cucumber/cucumber-cpp.git"
GIT_TAG v0.7
CMAKE_ARGS
-DCUKE_ENABLE_GTEST=ON -DCUKE_TESTS_UNIT=OFF
-DCUKE_ENABLE_EXAMPLES=OFF -DCUKE_ENABLE_BOOST_TEST=OFF -DCUKE_ENABLE_QT=OFF
-DCUKE_TESTS_VALGRIND=OFF)
However, I can see CMake complain that GTest can’t be found when configuring cucumber-cpp
:
[1/9] Creating directories for 'googletest-populate'
[1/9] Performing download step (git clone) for 'googletest-populate'
Cloning into 'googletest-src'...
HEAD is now at f8d7d77c Bump version to v1.14 in preparation for release
[2/9] Performing disconnected update step for 'googletest-populate'
[3/9] No patch_disconnected step for 'googletest-populate'
[5/9] No configure step for 'googletest-populate'
[6/9] No build step for 'googletest-populate'
[7/9] No install step for 'googletest-populate'
[8/9] No test step for 'googletest-populate'
[9/9] Completed 'googletest-populate'
...
[6/16] Performing configure step for 'CucumberCpp'
...
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) (Required is at least version "1.11.0")
When I go on to build my source using cucumber-cpp
, I get various linker failures about being unable to find references to GTestStep
. From looking at the cucumber-cpp
CMakeLists.txt
, it seems the following is problematic:
if(TARGET GTest::gtest)
list(APPEND CUKE_EXTRA_PRIVATE_LIBRARIES GTest::gtest)
list(APPEND CUKE_SOURCES drivers/GTestDriver.cpp)
endif()
I appear to be able to resolve this issue if I just apt install libgtest-dev libgmock-dev
then rebuild, but I want to continue building GTest/ GMock from source in my project. Unsure whether I’m doing something silly here.