I'm using this script for my project:
cmake_minimum_required (VERSION 3.20)
set(PROJECT_NAME CurlSomething)
project(${PROJECT_NAME})
find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: " ${OPENSSL_INCLUDE_DIR})
message("OpenSSL include dir: " ${OPENSSL_LIBRARIES})
include(FetchContent) # Needs to be included first
FetchContent_Declare(curl
URL https://github.com/curl/curl/releases/download/curl-8_1_2/curl-8.1.2.zip
)
FetchContent_MakeAvailable(curl)
FetchContent_Declare(json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
)
FetchContent_MakeAvailable(json)
set(SRC_FILES
main.cpp
)
set(INCLUDE_DIRS
${CMAKE_CURRENT_LIST_DIR}
${CURL_SOURCE_DIR}/include
)
set(LINK_LIBRARIES
)
message("Curl src dir: " ${curl_SOURCE_DIR})
add_executable (${PROJECT_NAME} ${SRC_FILES})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 23)
include_directories(${INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE libcurl nlohmann_json::nlohmann_json)
I have OpenSSL installed at default location, and cmake finds OPENSSL_INCLUDE_DIR and OPENSSL_LIBRARIES properly, but it builds libcurl without https anyway ("Protocol "https" not supported or disabled in libcurl"). How can I fix this? Just in case, I've seen this thread, but it does not explain how to link it in cmake script. I've tried to add this:
add_compile_definitions(USE_WINDOWS_SSPI)
add_compile_definitions(USE_SCHANNEL)
but it didn't help.
Also, its not directly related to the main question, but how does cmake find OpenSSL? I haven't found anything related to it in environment variables, I haven't edited CMAKE_MODULE_PATH and I haven't provided "FindOpenSSL.cmake"
UPD. I've build OpenSSL for x64 and I don't specify compiler or target system for cmake, all I do is this:
cmake ..
cmake --build .
And I have libcurl dll in the folder with .exe