I managed to find a solution myself: `````````````````````````````````````````````````````````````` cmake_minimum_required(VERSION 3.11)
project(testProj) include(FetchContent) FetchContent_Declare( Catch2 GIT_REPOSITORY "https://github.com/catchorg/Catch2" ) FetchContent_GetProperties(Catch2) #mispelled name in original post if(NOT Catch2_POPULATED) FetchContent_Populate(Catch2) message(STATUS "Catch source dir: ${catch2_SOURCE_DIR}") message(STATUS "Catch binary dir: ${catch2_BINARY_DIR}") add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR}) #can be case insensitive endif() add_executable(testExe main.cpp ) message(STATUS "Catch include dir: ${catch2_SOURCE_DIR}/include") target_link_libraries(testExe Catch) #name of library to link is case sensitive! `````````````````````````````````````````````````````````````` On Sun, Mar 11, 2018 at 8:02 PM Saad Khattak <saadrus...@gmail.com> wrote: > 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 >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake