How to solve libcurl + wolfssl linking problem?

890 Views Asked by At

Good afternoon! Ran into a problem linking libcurl (version 7.83) and wolfssl (latest release). The mint 20.3 system, the linking problem is also relevant under win10. I use cmake to automate the assembly, if you take mint, where there is no native support for tls (relevant for win7), then I set the flag in cmakelists libcurl

cmake_dependent_option(CURL_USE_WOLFSSL "enable wolfSSL for SSL/TLS" ON CURL_ENABLE_SSL ON)

In wolfssl I create a static lib, because then all the linking is static, because such a task.

option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)

I also changed this, because according to the documentation in wolfssl with curl, you need to disable this option:

add_option("WOLFSSL_OLD_NAMES"
    "Keep backwards compat with old names (default: enabled)"
    "no" "yes;no")

I compile Wolfsll and install it in local/lib of the system.

At the level of the entire project, I connect wolfssl

target_link_libraries(${PROJECT_NAME} PRIVATE
            ${Boost_LIBRARIES}
            libcurl
            wolfssl
            )

Errors:

usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `multi_getsock':
multi.c:(.text+0x1dd): undefined reference to `Curl_ssl'
/usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `init_completed':
multi.c:(.text+0x897): undefined reference to `Curl_connect_done'
/usr/bin/ld: multi.c:(.text+0x8b4): undefined reference to `Curl_ssl_detach_conn'
/usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `Curl_detach_connnection':
multi.c:(.text+0x1557): undefined reference to `Curl_connect_done'
/usr/bin/ld: multi.c:(.text+0x1574): undefined reference to `Curl_ssl_detach_conn'
/usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `Curl_multi_add_perform':
multi.c:(.text+0x2814): undefined reference to `Curl_ssl_associate_conn'
/usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `multi_done':
multi.c:(.text+0x2a1b): undefined reference to `Curl_connect_done'
/usr/bin/ld: multi.c:(.text+0x2a38): undefined reference to `Curl_ssl_detach_conn'
/usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `curl_multi_remove_handle':
multi.c:(.text+0x3189): undefined reference to `Curl_connect_done'
/usr/bin/ld: multi.c:(.text+0x31a7): undefined reference to `Curl_ssl_detach_conn'
/usr/bin/ld: thirdparty/curl/lib/libcurl.a(multi.c.o): in function `multi_runsingle':
multi.c:(.text+0x38ab): undefined reference to `Curl_connect_done'
/usr/bin/ld: multi.c:(.text+0x38c8): undefined reference to `Curl_ssl_detach_conn'
/usr/bin/ld: multi.c:(.text+0x3bf0): undefined reference to `Curl_proxy_connect'
/usr/bin/ld: multi.c:(.text+0x3c81): undefined reference to `Curl_http_connect'
/usr/bin/ld: multi.c:(.text+0x42b0): undefined reference to `Curl_connect_free'
/usr/bin/ld: multi.c:(.text+0x43f9): undefined reference to `Curl_connect_complete'
/usr/bin/ld: multi.c:(.text+0x44e5): undefined reference to `Curl_connect_done'
/usr/bin/ld: multi.c:(.text+0x4502): undefined reference to `Curl_ssl_detach_conn'
/usr/bin/ld: multi.c:(.text+0x467e): undefined reference to `Curl_connect_free'
/usr/bin/ld: multi.c:(.text+0x48d1): undefined reference to `Curl_connect_ongoing'
/usr/bin/ld: multi.c:(.text+0x4946): undefined reference to `Curl_connect_ongoing'
/usr/bin/ld: multi.c:(.text+0x4c94): undefined reference to `Curl_connect_free'
/usr/bin/ld: multi.c:(.text+0x4df4): undefined reference to `Curl_connect_ongoing'
/usr/bin/ld: multi.c:(.text+0x4e29): undefined reference to `Curl_connect_ongoing'
and etc

PS if the project is linked with openSSL, then there are no problems, everything works. wolfssl I want to use for tls1.2

The main cmakelists.txt

cmake_minimum_required(VERSION 3.16)
project(project)

if (UNIX)
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v -Os -s -static-libgcc -static-libstdc++")
endif ()

#boost
set(BOOST_ROOT "$ENV{HOME}/boost_1_78_0")
set(Boost_NO_WARN_NEW_VERSIONS ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost 1.78.0 REQUIRED)
if (Boost_FOUND)
    message("~BOOST FOUND\n")
    include_directories(${Boost_INCLUDE_DIRS})
else ()
    message(FATAL_ERROR "~Boost NOT FOUND\n")
endif ()

#curl
add_definitions("-DCURL_STATICLIB")
set(CURL_INCLUDE_DIR thirdparty/curl/include)
set(CURL_LIBRARY ${CMAKE_SOURCE_DIR}/thirdparty/curl/lib)
find_package(CURL)
if (CURL_FOUND)
    message("~CURL FOUND\n")
    include_directories(${CURL_INCLUDE_DIRS})
    add_definitions(-DHAVE_CURL)
else ()
    message(FATAL_ERROR "~CURL NOT FOUND\n")
endif ()

add_executable(${PROJECT_NAME} main.cpp)

add_subdirectory(thirdparty)

target_include_directories(${PROJECT_NAME} PRIVATE
        ${CMAKE_BINARY_DIR}/thirdparty/curl/lib #"curl_config.h"
        )


target_link_libraries(${PROJECT_NAME} PRIVATE
        ${Boost_LIBRARIES}
        libcurl
        wolfssl
        )

curl cmake

#***************************************************************************
#                                  _   _ ____  _
#  Project                     ___| | | |  _ \| |
#                             / __| | | | |_) | |
#                            | (__| |_| |  _ <| |___
#                             \___|\___/|_| \_\_____|
#

cmake_minimum_required(VERSION 3.2...3.16 FATAL_ERROR)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
include(Utilities)
include(Macros)
include(CMakeDependentOption)
include(CheckCCompilerFlag)

project(CURL C)

file(STRINGS ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS REGEX "#define LIBCURL_VERSION( |_NUM )")
string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
        CURL_VERSION ${CURL_VERSION_H_CONTENTS})
string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
        CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})


# Setup package meta-data
# SET(PACKAGE "curl")
message(STATUS "curl version=[${CURL_VERSION}]")
# SET(PACKAGE_TARNAME "curl")
# SET(PACKAGE_NAME "curl")
# SET(PACKAGE_VERSION "-")
# SET(PACKAGE_STRING "curl-")
# SET(PACKAGE_BUGREPORT "a suitable curl mailing list => https://curl.se/mail/")
set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
set(OS "\"${CMAKE_SYSTEM_NAME}\"")

include_directories(${CURL_SOURCE_DIR}/include)

option(CURL_WERROR "Turn compiler warnings into errors" OFF)
option(PICKY_COMPILER "Enable picky compiler options" ON)
option(BUILD_CURL_EXE "Set to ON to build curl executable." OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
if(WIN32)
    option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
    option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)
    option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
    set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
    if(CURL_TARGET_WINDOWS_VERSION)
        add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
        set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
    elseif(ENABLE_INET_PTON)
        # _WIN32_WINNT_VISTA (0x0600)
        add_definitions(-D_WIN32_WINNT=0x0600)
        set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0600")
    else()
        # _WIN32_WINNT_WINXP (0x0501)
        add_definitions(-D_WIN32_WINNT=0x0501)
        set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0501")
    endif()
    if(ENABLE_UNICODE)
        add_definitions(-DUNICODE -D_UNICODE)
        if(MINGW)
            add_compile_options(-municode)
        endif()
    endif()
endif()
option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)

cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
        ON "NOT ENABLE_ARES"
        OFF)

option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
    if(PICKY_COMPILER)
        foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wfloat-equal -Wsign-compare -Wundef -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wvla -Wdouble-promotion -Wenum-conversion -Warith-conversion)
            # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
            # test result in.
            string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
            check_c_compiler_flag(${_CCOPT} ${_optvarname})
            if(${_optvarname})
                set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
            endif()
        endforeach()
        foreach(_CCOPT long-long multichar format-nonliteral sign-conversion system-headers pedantic-ms-format)
            # GCC only warns about unknown -Wno- options if there are also other diagnostic messages,
            # so test for the positive form instead
            string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
            check_c_compiler_flag("-W${_CCOPT}" ${_optvarname})
            if(${_optvarname})
                set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${_CCOPT}")
            endif()
        endforeach()
    endif()
endif()

if(ENABLE_DEBUG)
    # DEBUGBUILD will be defined only for Debug builds
    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
    set(ENABLE_CURLDEBUG ON)
endif()

if(ENABLE_CURLDEBUG)
    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
endif()

# For debug libs and exes, add "-d" postfix
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
    set(CMAKE_DEBUG_POSTFIX "-d")
endif()

# initialize CURL_LIBS
set(CURL_LIBS "")

if(ENABLE_ARES)
    set(USE_ARES 1)
    find_package(CARES REQUIRED)
    list(APPEND CURL_LIBS ${CARES_LIBRARY})
endif()

include(CurlSymbolHiding)

option(CURL_ENABLE_EXPORT_TARGET "to enable cmake export target" ON)
mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)

option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
mark_as_advanced(CURL_DISABLE_ALTSVC)
option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
mark_as_advanced(CURL_DISABLE_COOKIES)
option(CURL_DISABLE_CRYPTO_AUTH "disables cryptographic authentication" OFF)
mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
option(CURL_DISABLE_DICT "disables DICT" OFF)
mark_as_advanced(CURL_DISABLE_DICT)
option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
mark_as_advanced(CURL_DISABLE_DOH)
option(CURL_DISABLE_FILE "disables FILE" OFF)
mark_as_advanced(CURL_DISABLE_FILE)
option(CURL_DISABLE_FTP "disables FTP" OFF)
mark_as_advanced(CURL_DISABLE_FTP)
option(CURL_DISABLE_GETOPTIONS "disables curl_easy_options API for existing options to curl_easy_setopt" OFF)
mark_as_advanced(CURL_DISABLE_GETOPTIONS)
option(CURL_DISABLE_GOPHER "disables Gopher" OFF)
mark_as_advanced(CURL_DISABLE_GOPHER)
option(CURL_DISABLE_HSTS "disables HSTS support" OFF)
mark_as_advanced(CURL_DISABLE_HSTS)
option(CURL_DISABLE_HTTP "disables HTTP" OFF)
mark_as_advanced(CURL_DISABLE_HTTP)
option(CURL_DISABLE_HTTP_AUTH "disables all HTTP authentication methods" OFF)
mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
option(CURL_DISABLE_IMAP "disables IMAP" OFF)
mark_as_advanced(CURL_DISABLE_IMAP)
option(CURL_DISABLE_LDAP "disables LDAP" OFF)
mark_as_advanced(CURL_DISABLE_LDAP)
option(CURL_DISABLE_LDAPS "disables LDAPS" OFF)
mark_as_advanced(CURL_DISABLE_LDAPS)
option(CURL_DISABLE_LIBCURL_OPTION "disables --libcurl option from the curl tool" OFF)
mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
option(CURL_DISABLE_MIME "disables MIME support" OFF)
mark_as_advanced(CURL_DISABLE_MIME)
option(CURL_DISABLE_MQTT "disables MQTT" OFF)
mark_as_advanced(CURL_DISABLE_MQTT)
option(CURL_DISABLE_NETRC "disables netrc parser" OFF)
mark_as_advanced(CURL_DISABLE_NETRC)
option(CURL_DISABLE_NTLM "disables NTLM support" OFF)
mark_as_advanced(CURL_DISABLE_NTLM)
option(CURL_DISABLE_PARSEDATE "disables date parsing" OFF)
mark_as_advanced(CURL_DISABLE_PARSEDATE)
option(CURL_DISABLE_POP3 "disables POP3" OFF)
mark_as_advanced(CURL_DISABLE_POP3)
option(CURL_DISABLE_PROGRESS_METER "disables built-in progress meter" OFF)
mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
option(CURL_DISABLE_PROXY "disables proxy support" OFF)
mark_as_advanced(CURL_DISABLE_PROXY)
option(CURL_DISABLE_RTSP "disables RTSP" OFF)
mark_as_advanced(CURL_DISABLE_RTSP)
option(CURL_DISABLE_SHUFFLE_DNS "disables shuffle DNS feature" OFF)
mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
option(CURL_DISABLE_SMB "disables SMB" OFF)
mark_as_advanced(CURL_DISABLE_SMB)
option(CURL_DISABLE_SMTP "disables SMTP" OFF)
mark_as_advanced(CURL_DISABLE_SMTP)
option(CURL_DISABLE_SOCKETPAIR "disables use of socketpair for curl_multi_poll" OFF)
mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
option(CURL_DISABLE_TELNET "disables Telnet" OFF)
mark_as_advanced(CURL_DISABLE_TELNET)
option(CURL_DISABLE_TFTP "disables TFTP" OFF)
mark_as_advanced(CURL_DISABLE_TFTP)
option(CURL_DISABLE_VERBOSE_STRINGS "disables verbose strings" OFF)
mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)

# Corresponds to HTTP_ONLY in lib/curl_setup.h
option(HTTP_ONLY "disables all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
mark_as_advanced(HTTP_ONLY)

if(HTTP_ONLY)
    set(CURL_DISABLE_DICT ON)
    set(CURL_DISABLE_FILE ON)
    set(CURL_DISABLE_FTP ON)
    set(CURL_DISABLE_GOPHER ON)
    set(CURL_DISABLE_IMAP ON)
    set(CURL_DISABLE_LDAP ON)
    set(CURL_DISABLE_LDAPS ON)
    set(CURL_DISABLE_MQTT ON)
    set(CURL_DISABLE_POP3 ON)
    set(CURL_DISABLE_RTSP ON)
    set(CURL_DISABLE_SMB ON)
    set(CURL_DISABLE_SMTP ON)
    set(CURL_DISABLE_TELNET ON)
    set(CURL_DISABLE_TFTP ON)
endif()

option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
mark_as_advanced(ENABLE_IPV6)
if(ENABLE_IPV6 AND NOT WIN32)
    include(CheckStructHasMember)
    check_struct_has_member("struct sockaddr_in6" sin6_addr "netinet/in.h"
            HAVE_SOCKADDR_IN6_SIN6_ADDR)
    check_struct_has_member("struct sockaddr_in6" sin6_scope_id "netinet/in.h"
            HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
    if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR)
        message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support")
        # Force the feature off as this name is used as guard macro...
        set(ENABLE_IPV6 OFF
                CACHE BOOL "Define if you want to enable IPv6 support" FORCE)
    endif()

    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT ENABLE_ARES)
        set(use_core_foundation ON)

        find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
        if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
            message(FATAL_ERROR "SystemConfiguration framework not found")
        endif()

        list(APPEND CURL_LIBS "-framework SystemConfiguration")
    endif()
endif()

if(USE_MANUAL)
    #nroff is currently only used when USE_MANUAL is set, so we can prevent the warning of no *NROFF if USE_MANUAL is OFF (or not defined), by not even looking for NROFF..
    curl_nroff_check()
endif()
find_package(Perl)

cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
        ON "NROFF_USEFUL;PERL_FOUND"
        OFF)

if(ENABLE_MANUAL)
    set(USE_MANUAL ON)
endif()

if(CURL_STATIC_CRT)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
endif()

# Disable warnings on Borland to avoid changing 3rd party code.
if(BORLAND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
endif()

# If we are on AIX, do the _ALL_SOURCE magic
if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
    set(_ALL_SOURCE 1)
endif()

# Include all the necessary files for macros
include(CMakePushCheckState)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)

# On windows preload settings
if(WIN32)
    set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
    include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
endif()

if(ENABLE_THREADED_RESOLVER)
    find_package(Threads REQUIRED)
    if(WIN32)
        set(USE_THREADS_WIN32 ON)
    else()
        set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
        set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
    endif()
    set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()

# Check for all needed libraries
check_library_exists_concat("${CMAKE_DL_LIBS}" dlopen HAVE_LIBDL)
check_library_exists_concat("socket" connect      HAVE_LIBSOCKET)
check_library_exists("c" gethostbyname "" NOT_NEED_LIBNSL)

if(NOT NOT_NEED_LIBNSL)
    check_library_exists_concat("nsl"    gethostbyname  HAVE_LIBNSL)
endif()

check_function_exists(gethostname HAVE_GETHOSTNAME)

if(WIN32)
    check_library_exists_concat("ws2_32" getch        HAVE_LIBWS2_32)
    check_library_exists_concat("winmm"  getch        HAVE_LIBWINMM)
endif()

# This check below for use of deprecated symbols is only temporary and is to
# be removed again after a year's service. Remove after November 25, 2022.
set(CURL_RECONFIG_REQUIRED 0)
foreach(_LIB GSSAPI OPENLDAP LIBSSH LIBSSH2 BEARSSL MBEDTLS NSS OPENSSL
        SCHANNEL SECTRANSP WOLFSSL)
    if(CMAKE_USE_${_LIB})
        set(CURL_RECONFIG_REQUIRED 1)
        message(SEND_ERROR "The option CMAKE_USE_${_LIB} was renamed to CURL_USE_${_LIB}.")
    endif()
endforeach()
if(CMAKE_USE_WINSSL)
    set(CURL_RECONFIG_REQUIRED 1)
    message(SEND_ERROR "The option CMAKE_USE_WINSSL was renamed to CURL_USE_SCHANNEL.")
endif()
if(CURL_RECONFIG_REQUIRED)
    message(FATAL_ERROR "Reconfig required")
endif()

# check SSL libraries
# TODO support GnuTLS
option(CURL_ENABLE_SSL "Enable SSL support" OFF)

if(APPLE)
    cmake_dependent_option(CURL_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
endif()
if (WIN32)
        cmake_dependent_option(CURL_USE_SCHANNEL "enable Windows native SSL/TLS" ON CURL_ENABLE_SSL ON)
    else()
        cmake_dependent_option(CURL_USE_SCHANNEL "enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
    endif ()
    cmake_dependent_option(CURL_WINDOWS_SSPI "Use windows libraries to allow NTLM authentication without openssl" OFF
            CURL_USE_SCHANNEL OFF)
endif ()
cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
cmake_dependent_option(CURL_USE_NSS "Enable NSS for SSL/TLS" OFF CURL_ENABLE_SSL OFF)
cmake_dependent_option(CURL_USE_WOLFSSL "enable wolfSSL for SSL/TLS" ON CURL_ENABLE_SSL ON)

set(openssl_default OFF)
if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_NSS OR CURL_USE_WOLFSSL)
    set(openssl_default OFF)
endif()

cmake_dependent_option(CURL_USE_OPENSSL "Use OpenSSL code. Experimental" ${openssl_default} CURL_ENABLE_SSL ON)
option(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG "Disable automatic loading of OpenSSL configuration" OFF)


#message("!!!\n", ${CURL_USE_OPENSSL} , "\n")

count_true(enabled_ssl_options_count
        CURL_USE_SCHANNEL
        CURL_USE_SECTRANSP
        CURL_USE_OPENSSL
        CURL_USE_MBEDTLS
        CURL_USE_BEARSSL
        CURL_USE_NSS
        CURL_USE_WOLFSSL
        )
if(enabled_ssl_options_count GREATER "1")
    set(CURL_WITH_MULTI_SSL ON)
endif()

if(CURL_USE_SCHANNEL)
    set(SSL_ENABLED ON)
    set(USE_SCHANNEL ON) # Windows native SSL/TLS support
    set(USE_WINDOWS_SSPI ON) # CURL_USE_SCHANNEL implies CURL_WINDOWS_SSPI
endif()
if(CURL_WINDOWS_SSPI)
    set(USE_WINDOWS_SSPI ON)
    set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -DSECURITY_WIN32")
endif()

if(CURL_USE_SECTRANSP)
    set(use_core_foundation ON)

    find_library(SECURITY_FRAMEWORK "Security")
    if(NOT SECURITY_FRAMEWORK)
        message(FATAL_ERROR "Security framework not found")
    endif()

    set(SSL_ENABLED ON)
    set(USE_SECTRANSP ON)
    list(APPEND CURL_LIBS "-framework Security")
endif()

if(use_core_foundation)
    find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
    if(NOT COREFOUNDATION_FRAMEWORK)
        message(FATAL_ERROR "CoreFoundation framework not found")
    endif()

    list(APPEND CURL_LIBS "-framework CoreFoundation")
endif()


# I use openssl from cmakelists.txt
#[[if (CURL_USE_OPENSSL)
  #openssl
  set(OPENSSL_USE_STATIC_LIBS TRUE)
  set(OPENSSL_MSVC_STATIC_RT TRUE)
  set(OPENSSL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/thirdparty/openssl/include)
  set(OPENSSL_FOUND ON)
  if (OPENSSL_FOUND)
    message("~OpenSSL FOUND\n")
  else ()
    message(FATAL_ERROR "~OpenSSL NOT FOUND\n")
  endif ()

  set(SSL_ENABLED ON)
  set(USE_OPENSSL ON)

  # Depend on OpenSSL via imported targets if supported by the running
  # version of CMake.  This allows our dependents to get our dependencies
  # transitively.
  if (NOT CMAKE_VERSION VERSION_LESS 3.4)
    list(APPEND CURL_LIBS ssl crypto)
  else ()
    list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
    include_directories(${OPENSSL_INCLUDE_DIR})
  endif ()

  set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
  check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
  check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
  check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
  check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
  check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
  check_include_file("openssl/rand.h" HAVE_OPENSSL_RAND_H)
  check_symbol_exists(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS)
  check_symbol_exists(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN)
  check_symbol_exists(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD)

  add_definitions(-DOPENSSL_SUPPRESS_DEPRECATED)
endif ()]]

if(CURL_USE_MBEDTLS)
    find_package(MbedTLS REQUIRED)
    set(SSL_ENABLED ON)
    set(USE_MBEDTLS ON)
    list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
    include_directories(${MBEDTLS_INCLUDE_DIRS})
endif()

if(CURL_USE_BEARSSL)
    find_package(BearSSL REQUIRED)
    set(SSL_ENABLED ON)
    set(USE_BEARSSL ON)
    list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
    include_directories(${BEARSSL_INCLUDE_DIRS})
endif()

if(CURL_USE_WOLFSSL)
    find_package(WolfSSL REQUIRED)
    message("~WolfSSL found\n")
    set(SSL_ENABLED ON)
    set(USE_WOLFSSL ON)
    list(APPEND CURL_LIBS ${WolfSSL_LIBRARIES})
    include_directories(${WolfSSL_INCLUDE_DIRS})
endif()

if(CURL_USE_NSS)
    find_package(NSS REQUIRED)
    include_directories(${NSS_INCLUDE_DIRS})
    list(APPEND CURL_LIBS ${NSS_LIBRARIES})
    set(SSL_ENABLED ON)
    set(USE_NSS ON)
    cmake_push_check_state()
    set(CMAKE_REQUIRED_INCLUDES ${NSS_INCLUDE_DIRS})
    set(CMAKE_REQUIRED_LIBRARIES ${NSS_LIBRARIES})
    check_symbol_exists(PK11_CreateManagedGenericObject "pk11pub.h" HAVE_PK11_CREATEMANAGEDGENERICOBJECT)
    cmake_pop_check_state()
endif()

stackoverflow does not allow to publish full cmake of the curl, because of the length, I cut not essential part.

1

There are 1 best solutions below

1
On

project(project) should be after all other find_package.

add_definitions("-DCURL_STATICLIB")

The above is wrong. It breaks normal configuring cURL. It must be

set(BUILD_SHARED_LIBS OFF)

Prefer use different names instead of CURL_INCLUDE_DIR and CURL_LIBRARY. Using the prefix "CURL_" can conflict with future cURL releases.

It seems you set those variables for find_package(CURL). It is absolutely wrong. It must be something like

#curl
set(BUILD_SHARED_LIBS OFF)
set(BUILD_CURL_EXE OFF)
set(CURL_ENABLE_SSL ON)
set(CURL_USE_WOLFSSL ON)
add_subdirectory(thirdparty/curl curl EXCLUDE_FROM_ALL)

project(project)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} CURL::libcurl)

target_include_directories is unnecessary.

If you modified curl/CMakeLists.txt, rollback it.

If you want getting libcurl pre-built and use ready libs, then build libcurl first:

cmake -S thirdparty/curl -B thirdparty/curl/out -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF \
    -DCURL_ENABLE_SSL=ON -DCURL_USE_WOLFSSL=ON -DCMAKE_BUILD_TYPE=Release && \
cmake --build thirdparty/curl/out
project(project)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} thirdparty/curl/include)
target_link_libraries(${PROJECT_NAME} thirdparty/curl/out/libcurl.a)

You should do similarity to boost.