Based on this question CMake cpprestsdk I tried to create a specific target from cpprestsdk source code. First, I cloned the github project into /home/user/git/cpprestsdk
Then, I created the CmakeLists.txt file
project(ProjectName)
find_package(cpprestsdk CONFIG REQUIRED)
target_link_libraries(ProjectName PRIVATE cpprestsdk::cpprestsdk_boost_internal)
and the cmake command:
cmake -DCMAKE_PREFIX_PATH=/home/user/git/cpprestsdk/Release/src .
and got the following error:
CMake Error at cpprestsdk/Release/src/cpprestsdk-config.cmake:25 (include):
include could not find load file:
/home/ebalbar/git/cpprestsdk/Release/src/cpprestsdk-targets.cmake
Call Stack (most recent call first):
CMakeLists.txt:2 (find_package)
CMake Error at CMakeLists.txt:3 (target_link_libraries):
Cannot specify link libraries for target "ProjectName" which is not built
by this project.
The target file can be found under /home/user/git/cpprestsdk/Release/src/CMakeFiles/Export/lib/cmake/cpprestsdk/cpprestsdk-targets.cmake
So the question is how to build cpprestsdk::cpprestsdk_boost_internal
target?
Thanks in advance!
as @Tsyvarev pointed out first the library should be built and installed.
cmake .
cmake --build .
cmake --install . --prefix <install_folder>
Then, the application CMakeList.txt should look like this:
cmake_minimum_required(VERSION 3.16)
# In your project's CMakeLists.txt
project(ProjectName)
set(CMAKE_PREFIX_PATH "<install_folder>")
find_package(cpprestsdk REQUIRED)
add_library(my_target SHARED main.cpp)
# Link to `cpprestsdk::cpprestsdk_openssl_internal` in your target
target_link_libraries(my_target cpprestsdk::cpprestsdk_openssl_internal)
then I could build the application with the following cmake commands:
cmake .
cmake --build .