How to make the build for a Fetch Content dep project's build happen within configure

60 Views Asked by At

I have a cmake configured project using cpprestsdk which is made available by FetchContent command family.

The problem is when I configure my project, for the cpprestsdk dep it only download the repo and checkout git branch or maybe configured the cpprestsdk's cmake thing. but I cannot use the cpprestsdk::cpprest library in my project CMakeLists.txt(complains were like "cpprestsdk::cpprest not found"). But the build of cpprestsdk only happen when I build my project.

my config for cpprestsdk deps

cmake_minimum_required(VERSION 3.5)

project(myproject)
include(FetchContent)
set(ENABLE_WERROR OFF)
set(WERROR OFF CACHE INTERNAL "Turn off Treat warnings as errors")
FetchContent_Declare(
    cpprestsdk
    GIT_REPOSITORY https://github.com/microsoft/cpprestsdk.git
    GIT_TAG v2.10.17
    OVERRIDE_FIND_PACKAGE
)

FetchContent_MakeAvailable(
    cpprestsdk
)

find_package(cpprestsdk 2.10.17 REQUIRED )
add_executable(myproject svr.cc)
target_link_libraries(myproject 
    cpprestsdk::cpprest
)

The error is Target "myproject" links to: cpprestsdk::cpprest but the target was not found. .

So, How to make the build of this dep happen when I configure my project? Vcpkg is not used in this project and I don't want to use vcpkg in this project.

0

There are 0 best solutions below