0

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

SavedowW
  • 39
  • 5
  • Hi @SavedowW, Have you heard about package(s) manager(s)? Conan for example is built for c/c++ deps you can find here: https://conan.io/center/ the available packages. It provides for example nlohmann_json at: https://conan.io/center/nlohmann_json – loic.lopez Jun 23 '23 at 15:10
  • `add_compile_definitions(USE_WINDOWS_SSPI) add_compile_definitions(USE_SCHANNEL)` they must not be compile defined, they should be cmake variables `set(USE_WINDOWS_SSPI ON) set(USE_SCHANNEL ON)` before `FetchContent_MakeAvailable`. You have referenced to very outdated answer. Prefer using the manuals on the official curl site. – 273K Jun 23 '23 at 15:23
  • @273K I know, but official manual only mentions alternative "mingw32-ssl-zlib" target for mingw32-make, but I don't have it, and OPENSSL_PATH in PATH. I tried to set it, but it didnt help – SavedowW Jun 23 '23 at 15:48

0 Answers0