[CMake] How to link against projects added through FetchContent
Saad Khattak
saadrustam at gmail.com
Sun Mar 11 20:02:17 EDT 2018
Hi,
I would like to know how to use the FetchContent properly so that I can
link against downloaded (CMake enabled) projects. I have looked at the
CMake docs, which although are quite thorough, almost always fail to list a
complete example which is incredibly crucial to get up and running quickly.
With ExternalProject_Add, we use add_dependencies(...) but that doesn't
seem to be the case for FetchContent. Since I can immediately call
add_subdirectory(...), I assumed that I can simply link to the library. But
that doesn't seem to do anything.
Here's my CMakeLists.txt
``````````````````````````````````````````````````````````````
cmake_minimum_required(VERSION 3.5)
project(testProj)
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY "https://github.com/catchorg/Catch2"
TEST_COMMAND ""
)
FetchContent_GetProperties(catch)
if(NOT Catch2_POPULATED)
FetchContent_Populate(Catch2)
add_subdirectory(${Catch2_SOURCE_DIR} ${Catch2_BINARY_DIR})
endif()
add_executable(testExe main.cpp)
target_link_libraries(testExe Catch2)
``````````````````````````````````````````````````````````````
CMake populates Catch2 with Catch2-NOTFOUND.
So, my question is, how do I link against projects added through
FetchContent?
- Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180312/9e65875d/attachment.html>
More information about the CMake
mailing list