Install turtle using cmake's FetchContent
dohashi opened this issue · comments
I don't know if this counts as a turtle issue, but I want to add turtle to my project using cmake's FetchContent. It downloads ok, but using the suggested technique did not lead to a functional install of turtle. Ideally, the following would work:
cmake_minimum_required( VERSION 3.11 )
project(test_proj)
include(FetchContent)
FetchContent_Declare(
turtle
GIT_REPOSITORY git@github.com:mat007/turtle
GIT_TAG v1.3.2
)
FetchContent_MakeAvailable( turtle )
add_executable( test test.cpp )
Where test.cpp tries to #include "turtle/mock.hpp"
I've tried with and without defining TURTLE_INSTALL to ON. It seems like the install step is not working in a way that is compatible with what FetchContext expects.
In case anyone else runs into this, I was able to make it work using this:
FetchContent_Declare(
turtle
GIT_REPOSITORY git@github.com:mat007/turtle
GIT_TAG v1.3.2
)
FetchContent_GetProperties(turtle)
if(NOT turtle_POPULATED)
FetchContent_Populate(turtle)
include_directories( ${turtle_SOURCE_DIR}/include )
endif()
This adds the include directory from the source tree, which seems to work.
FetchContent
makes the library available to CMake. It is basically a fancy add_subdirectory
. See the CMake documentation about that feature.
Hence you need to link to turtle just as with any other (CMake) library. I.e. you are missing a target_link_libraries(test PRIVATE turtle::turtle)
Add this to the bottom of your initial example and it will work just fine. Nothing else needed.
Ah, that works. Thank you.