I have build the libcurl from source with cmake and installed to /usr/local/ and I used find_package(CURL 7.88.1 EXACT REQUIRED) in my project’s main CMakeLists.txt. It find CURL with 7.88.1 version, however, when I want to print CURL_LIBRARIES and CURL_INCLUDE_DIRS in CMakeLists.txt prints nothing. Furthermore, I tried to link the libcurl with CURL::libcurl which is set in CURLTargets.cmake still I can’t see it linked shared to my binary.
find_package(CURL 7.88.1 EXACT REQUIRED)
message("curl libs: ${CURL_LIBRARIES}")
message("curl dirs: ${CURL_INCLUDE_DIRS}")
...
target_include_directories(${PROJECT_NAME}
PUBLIC
${Boost_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
${RAPIDJSON_INCLUDE_DIRS}
${ZeroMQ_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES}
spdlog::spdlog
CURL::libcurl
${CURL_LIBRARIES}
${ZeroMQ_LIBRARY})
output:
-- Found CURL: /usr/local/lib/cmake/CURL/CURLConfig.cmake (found suitable exact version "7.88.1")
curl libs:
curl dirs:
cmake reference: FindCURL
OS: Windows subsystem linux Ubuntu 20.04
CMake Version: 3.19.8
>Solution :
Apparently the FindCURL module, when CURL is installed with cmake, loads CURL’s own cmake config instead of doing whatever it normally does, so it doesn’t set these variables.
However, in both cases you should be able to add CURL::libcurl as a library with target_link_libraries(${PROJECT_NAME} CURL::libcurl). This will automatically set the include directories and add the library and anything else that’s needed.