cmakelist.txt
647 lines
#***************************************************************************
#***************************************************************************
# _ _ ____ _
# _ _ ____ _
# Project ___| | | | _ \| |
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
# \___|\___/|_| \_\_____|
#
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
#
# This software is licensed as described in the file COPYING, which
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
# are also available at https://curl.se/docs/copyright.html.
#
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
# furnished to do so, under the terms of the COPYING file.
#
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
# KIND, either express or implied.
#
#
# SPDX-License-Identifier: curl
# SPDX-License-Identifier: curl
#
#
###########################################################################
###########################################################################
# by Tetetest and Sukender (Benoit Neil)
# by Tetetest and Sukender (Benoit Neil)
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
message(STATUS "Using CMake version ${CMAKE_VERSION}")
message(STATUS "Using CMake version ${CMAKE_VERSION}")
# Collect command-line arguments for buildinfo.txt.
# Collect command-line arguments for buildinfo.txt.
# Must reside at the top of the script to work as expected.
# Must reside at the top of the script to work as expected.
set(_cmake_args "")
set(_cmake_args "")
if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "")
if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "")
get_cmake_property(_cache_vars CACHE_VARIABLES)
get_cmake_property(_cache_vars CACHE_VARIABLES)
foreach(_cache_var IN ITEMS ${_cache_vars})
foreach(_cache_var IN ITEMS ${_cache_vars})
get_property(_cache_var_helpstring CACHE ${_cache_var} PROPERTY HELPSTRING)
get_property(_cache_var_helpstring CACHE ${_cache_var} PROPERTY HELPSTRING)
if(_cache_var_helpstring STREQUAL "No help, variable specified on the command line.")
if(_cache_var_helpstring STREQUAL "No help, variable specified on the command line.")
get_property(_cache_var_type CACHE ${_cache_var} PROPERTY TYPE)
get_property(_cache_var_type CACHE ${_cache_var} PROPERTY TYPE)
get_property(_cache_var_value CACHE ${_cache_var} PROPERTY VALUE)
get_property(_cache_var_value CACHE ${_cache_var} PROPERTY VALUE)
if(_cache_var_type STREQUAL "UNINITIALIZED")
if(_cache_var_type STREQUAL "UNINITIALIZED")
set(_cache_var_type)
set(_cache_var_type)
else()
else()
set(_cache_var_type ":${_cache_var_type}")
set(_cache_var_type ":${_cache_var_type}")
endif()
endif()
string(APPEND _cmake_args " -D${_cache_var}${_cache_var_type}=\"${_cache_var_value}\"")
string(APPEND _cmake_args " -D${_cache_var}${_cache_var_type}=\"${_cache_var_value}\"")
endif()
endif()
endforeach()
endforeach()
endif()
endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
include(Utilities)
include(Utilities)
include(Macros)
include(Macros)
include(CMakeDependentOption)
include(CMakeDependentOption)
include(CheckCCompilerFlag)
include(CheckCCompilerFlag)
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/curl/curlver.h" _curl_version_h_contents REGEX "#define LIBCURL_VERSION( |_NUM )")
file(STRINGS "${CMAKE_CURRENT_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 MATCH "#define LIBCURL_VERSION \"[^\"]*" _curl_version ${_curl_version_h_contents})
string(REGEX REPLACE "[^\"]+\"" "" _curl_version ${_curl_version})
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 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})
string(REGEX REPLACE "[^0]+0x" "" _curl_version_num ${_curl_version_num})
unset(_curl_version_h_contents)
unset(_curl_version_h_contents)
message(STATUS "curl version=[${_curl_version}]")
message(STATUS "curl version=[${_curl_version}]")
string(REGEX REPLACE "([0-9]+\.[0-9]+\.[0-9]+).+" "\\1" _curl_version_sem "${_curl_version}")
string(REGEX REPLACE "([0-9]+\.[0-9]+\.[0-9]+).+" "\\1" _curl_version_sem "${_curl_version}")
project(CURL
project(CURL
VERSION "${_curl_version_sem}"
VERSION "${_curl_version_sem}"
LANGUAGES C)
LANGUAGES C)
# CMake does not recognize some targets accurately. Touch up configuration manually as a workaround.
# CMake does not recognize some targets accurately. Touch up configuration manually as a workaround.
if(WINDOWS_STORE AND MINGW) # mingw UWP build
if(WINDOWS_STORE AND MINGW) # mingw UWP build
# CMake (as of v3.31.2) gets confused and applies the MSVC rc.exe command-line
# CMake (as of v3.31.2) gets confused and applies the MSVC rc.exe command-line
# template to windres. Reset it to the windres template via 'Modules/Platform/Windows-windres.cmake':
# template to windres. Reset it to the windres template via 'Modules/Platform/Windows-windres.cmake':
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>")
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>")
elseif(WIN32 AND WINCE AND CMAKE_C_COMPILER_ID STREQUAL "GNU") # mingw32ce build
elseif(WIN32 AND WINCE AND CMAKE_C_COMPILER_ID STREQUAL "GNU") # mingw32ce build
if(NOT MINGW32CE_LIBRARY_DIR)
if(NOT MINGW32CE_LIBRARY_DIR)
message(FATAL_ERROR "Set MINGW32CE_LIBRARY_DIR variable to the mingw32ce platform library directory.")
message(FATAL_ERROR "Set MINGW32CE_LIBRARY_DIR variable to the mingw32ce platform library directory.")
endif()
endif()
set(MINGW 1)
set(MINGW 1)
set(MINGW32CE 1)
set(MINGW32CE 1)
# Build implib with libcurl DLL. Copied from CMake's 'Modules/Platform/Windows-GNU.cmake'.
# Build implib with libcurl DLL. Copied from CMake's 'Modules/Platform/Windows-GNU.cmake'.
set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS>")
set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS>")
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB>")
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB>")
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
string(APPEND CMAKE_C_CREATE_SHARED_LIBRARY " ${CMAKE_GNULD_IMAGE_VERSION} <OBJECTS> <LINK_LIBRARIES>")
# Build resources. Copied from CMake's 'Modules/Platform/Windows-windres.cmake'.
# Build resources. Copied from CMake's 'Modules/Platform/Windows-windres.cmake'.
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>")
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> <INCLUDES> <FLAGS> <SOURCE> <OBJECT>")
enable_language(RC)
enable_language(RC)
# To compile long long integer literals
# To compile long long integer literals
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-std=gnu99")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-std=gnu99")
string(APPEND CMAKE_REQUIRED_FLAGS " -std=gnu99")
string(APPEND CMAKE_REQUIRED_FLAGS " -std=gnu99")
set(CMAKE_C_COMPILE_OPTIONS_PIC "") # CMake sets it to '-fPIC', confusing the toolchain and breaking builds. Zap it.
set(CMAKE_C_COMPILE_OPTIONS_PIC "") # CMake sets it to '-fPIC', confusing the toolchain and breaking builds. Zap it.
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
set(CMAKE_IMPORT_LIBRARY_PREFIX "lib")
set(CMAKE_IMPORT_LIBRARY_PREFIX "lib")
set(CMAKE_IMPORT_LIBRARY_SUFFIX ".dll.a")
set(CMAKE_IMPORT_LIBRARY_SUFFIX ".dll.a")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".a" ".lib")
elseif(DOS AND CMAKE_C_COMPILER_ID STREQUAL "GNU") # DJGPP
elseif(DOS AND CMAKE_C_COMPILER_ID STREQUAL "GNU") # DJGPP
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
endif()
# Fill platform level variable when using CMake's built-in Android configuration
# Fill platform level variable when using CMake's built-in Android configuration
if(ANDROID AND NOT DEFINED ANDROID_PLATFORM_LEVEL AND NOT CMAKE_SYSTEM_VERSION EQUAL 1)
if(ANDROID AND NOT DEFINED ANDROID_PLATFORM_LEVEL AND NOT CMAKE_SYSTEM_VERSION EQUAL 1)
set(ANDROID_PLATFORM_LEVEL "${CMAKE_SYSTEM_VERSION}")
set(ANDROID_PLATFORM_LEVEL "${CMAKE_SYSTEM_VERSION}")
endif()
endif()
set(_target_flags "")
set(_target_flags "")
if(APPLE)
if(APPLE)
string(APPEND _target_flags " APPLE")
string(APPEND _target_flags " APPLE")
endif()
endif()
if(UNIX)
if(UNIX)
string(APPEND _target_flags " UNIX")
string(APPEND _target_flags " UNIX")
endif()
endif()
if(BSD)
if(BSD)
string(APPEND _target_flags " BSD")
string(APPEND _target_flags " BSD")
endif()
endif()
if(ANDROID)
if(ANDROID)
string(APPEND _target_flags " ANDROID-${ANDROID_PLATFORM_LEVEL}")
string(APPEND _target_flags " ANDROID-${ANDROID_PLATFORM_LEVEL}")
endif()
endif()
if(WIN32)
if(WIN32)
string(APPEND _target_flags " WIN32")
string(APPEND _target_flags " WIN32")
endif()
endif()
if(WINCE)
if(WINCE)
string(APPEND _target_flags " WINCE")
string(APPEND _target_flags " WINCE")
endif()
endif()
if(WINDOWS_STORE)
if(WINDOWS_STORE)
string(APPEND _target_flags " UWP")
string(APPEND _target_flags " UWP")
endif()
endif()
if(CYGWIN)
if(CYGWIN)
string(APPEND _target_flags " CYGWIN")
string(APPEND _target_flags " CYGWIN")
endif()
endif()
if(DOS)
if(DOS)
string(APPEND _target_flags " DOS")
string(APPEND _target_flags " DOS")
endif()
endif()
if(AMIGA)
if(AMIGA)
string(APPEND _target_flags " AMIGA")
string(APPEND _target_flags " AMIGA")
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
string(APPEND _target_flags " GCC")
string(APPEND _target_flags " GCC")
endif()
endif()
if(MINGW)
if(MINGW)
string(APPEND _target_flags " MINGW")
string(APPEND _target_flags " MINGW")
endif()
endif()
if(MSVC)
if(MSVC)
string(APPEND _target_flags " MSVC-${MSVC_VERSION}")
string(APPEND _target_flags " MSVC-${MSVC_VERSION}")
endif()
endif()
if(VCPKG_TOOLCHAIN)
if(VCPKG_TOOLCHAIN)
string(APPEND _target_flags " VCPKG")
string(APPEND _target_flags " VCPKG")
endif()
endif()
if(CMAKE_CROSSCOMPILING)
if(CMAKE_CROSSCOMPILING)
string(APPEND _target_flags " CROSS")
string(APPEND _target_flags " CROSS")
endif()
endif()
message(STATUS "CMake platform flags:${_target_flags}")
message(STATUS "CMake platform flags:${_target_flags}")
if(CMAKE_CROSSCOMPILING)
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross-compiling: "
message(STATUS "Cross-compiling: "
"${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR} -> "
"${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR} -> "
"${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}")
"${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}")
endif()
endif()
if(CMAKE_C_COMPILER_TARGET)
if(CMAKE_C_COMPILER_TARGET)
set(CURL_OS "\"${CMAKE_C_COMPILER_TARGET}\"")
set(CURL_OS "\"${CMAKE_C_COMPILER_TARGET}\"")
else()
else()
set(CURL_OS "\"${CMAKE_SYSTEM_NAME}\"")
set(CURL_OS "\"${CMAKE_SYSTEM_NAME}\"")
endif()
endif()
set(LIB_NAME "libcurl")
set(LIB_NAME "libcurl")
set_property(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/include")
set_property(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/include")
if(NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE)
if(NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE)
set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
set(CMAKE_UNITY_BUILD_BATCH_SIZE 0)
endif()
endif()
# Having CMAKE_TRY_COMPILE_TARGET_TYPE set to STATIC_LIBRARY breaks certain
# Having CMAKE_TRY_COMPILE_TARGET_TYPE set to STATIC_LIBRARY breaks certain
# 'check_function_exists()' detections (possibly more), by detecting
# 'check_function_exists()' detections (possibly more), by detecting
# non-existing features. This happens by default when using 'ios.toolchain.cmake'.
# non-existing features. This happens by default when using 'ios.toolchain.cmake'.
# Work it around by setting this value to `EXECUTABLE`.
# Work it around by setting this value to `EXECUTABLE`.
if(CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "STATIC_LIBRARY")
if(CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "STATIC_LIBRARY")
message(STATUS "CMAKE_TRY_COMPILE_TARGET_TYPE was found set to STATIC_LIBRARY. "
message(STATUS "CMAKE_TRY_COMPILE_TARGET_TYPE was found set to STATIC_LIBRARY. "
"Overriding with EXECUTABLE for feature detections to work.")
"Overriding with EXECUTABLE for feature detections to work.")
set(_cmake_try_compile_target_type_save ${CMAKE_TRY_COMPILE_TARGET_TYPE})
set(_cmake_try_compile_target_type_save ${CMAKE_TRY_COMPILE_TARGET_TYPE})
set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")
set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")
endif()
endif()
option(CURL_WERROR "Turn compiler warnings into errors" OFF)
option(CURL_WERROR "Turn compiler warnings into errors" OFF)
option(PICKY_COMPILER "Enable picky compiler options" ON)
option(PICKY_COMPILER "Enable picky compiler options" ON)
option(BUILD_CURL_EXE "Build curl executable" ON)
option(BUILD_CURL_EXE "Build curl executable" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_STATIC_LIBS "Build static libraries" OFF)
option(BUILD_STATIC_LIBS "Build static libraries" OFF)
option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
option(ENABLE_ARES "Enable c-ares support" OFF)
option(ENABLE_ARES "Enable c-ares support" OFF)
option(CURL_DISABLE_INSTALL "Disable installation targets" OFF)
option(CURL_DISABLE_INSTALL "Disable installation targets" OFF)
if(WIN32)
if(WIN32)
option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF)
option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF)
if(WINDOWS_STORE OR WINCE)
if(WINDOWS_STORE OR WINCE)
set(ENABLE_UNICODE ON)
set(ENABLE_UNICODE ON)
endif()
endif()
if(ENABLE_UNICODE)
if(ENABLE_UNICODE)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "UNICODE" "_UNICODE")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "UNICODE" "_UNICODE")
if(MINGW AND NOT MINGW32CE)
if(MINGW AND NOT MINGW32CE)
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-municode")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-municode")
endif()
endif()
endif()
endif()
# Apply to all feature checks
# Apply to all feature checks
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN")
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN")
if(MSVC)
if(MSVC)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_CRT_NONSTDC_NO_DEPRECATE") # for strdup() detection
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_CRT_NONSTDC_NO_DEPRECATE") # for strdup() detection
endif()
endif()
set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
if(CURL_TARGET_WINDOWS_VERSION)
if(CURL_TARGET_WINDOWS_VERSION)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") # Apply to all feature checks
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}") # Apply to all feature checks
endif()
endif()
# Detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
# Detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
curl_internal_test(HAVE_WIN32_WINNT)
curl_internal_test(HAVE_WIN32_WINNT)
if(HAVE_WIN32_WINNT)
if(HAVE_WIN32_WINNT)
string(REGEX MATCH "_WIN32_WINNT=0x[0-9a-fA-F]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
string(REGEX MATCH "_WIN32_WINNT=0x[0-9a-fA-F]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
string(REGEX REPLACE "_WIN32_WINNT=" "" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
string(REGEX REPLACE "_WIN32_WINNT=" "" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") # pad to 4 digits
string(REGEX REPLACE "0x([0-9a-f][0-9a-f][0-9a-f])$" "0x0\\1" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}") # pad to 4 digits
string(TOLOWER "${CURL_TEST_OUTPUT}" HAVE_WIN32_WINNT)
string(TOLOWER "${CURL_TEST_OUTPUT}" HAVE_WIN32_WINNT)
message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
endif()
endif()
unset(HAVE_WIN32_WINNT CACHE) # Avoid storing in CMake cache
unset(HAVE_WIN32_WINNT CACHE) # Avoid storing in CMake cache
if(MINGW)
if(MINGW)
# Detect __MINGW64_VERSION_MAJOR, __MINGW64_VERSION_MINOR and store as MINGW64_VERSION
# Detect __MINGW64_VERSION_MAJOR, __MINGW64_VERSION_MINOR and store as MINGW64_VERSION
curl_internal_test(MINGW64_VERSION)
curl_internal_test(MINGW64_VERSION)
if(MINGW64_VERSION)
if(MINGW64_VERSION)
string(REGEX MATCH "MINGW64_VERSION=[0-9]+\.[0-9]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
string(REGEX MATCH "MINGW64_VERSION=[0-9]+\.[0-9]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
string(REGEX REPLACE "MINGW64_VERSION=" "" MINGW64_VERSION "${CURL_TEST_OUTPUT}")
string(REGEX REPLACE "MINGW64_VERSION=" "" MINGW64_VERSION "${CURL_TEST_OUTPUT}")
if(MINGW64_VERSION)
if(MINGW64_VERSION)
message(STATUS "Found MINGW64_VERSION=${MINGW64_VERSION}")
message(STATUS "Found MINGW64_VERSION=${MINGW64_VERSION}")
endif()
endif()
endif()
endif()
unset(MINGW64_VERSION CACHE) # Avoid storing in CMake cache
unset(MINGW64_VERSION CACHE) # Avoid storing in CMake cache
endif()
endif()
elseif(DOS OR AMIGA)
elseif(DOS OR AMIGA)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
set(BUILD_STATIC_LIBS ON)
endif()
endif()
option(CURL_LTO "Enable compiler Link Time Optimizations" OFF)
option(CURL_LTO "Enable compiler Link Time Optimizations" OFF)
if(NOT DOS AND NOT AMIGA)
if(NOT DOS AND NOT AMIGA)
# if c-ares is used, default the threaded resolver to OFF
# if c-ares is used, default the threaded resolver to OFF
if(ENABLE_ARES)
if(ENABLE_ARES)
set(_enable_threaded_resolver_default OFF)
set(_enable_threaded_resolver_default OFF)
else()
else()
set(_enable_threaded_resolver_default ON)
set(_enable_threaded_resolver_default ON)
endif()
endif()
option(ENABLE_THREADED_RESOLVER "Enable threaded DNS lookup" ${_enable_threaded_resolver_default})
option(ENABLE_THREADED_RESOLVER "Enable threaded DNS lookup" ${_enable_threaded_resolver_default})
endif()
endif()
include(PickyWarnings)
include(PickyWarnings)
if(CYGWIN OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CYGWIN OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_GNU_SOURCE") # Required for accept4(), pipe2(), sendmmsg()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_GNU_SOURCE") # Required for accept4(), pipe2(), sendmmsg()
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") # Apply to all feature checks
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") # Apply to all feature checks
endif()
endif()
option(ENABLE_DEBUG "Enable curl debug features (for developing curl itself)" OFF)
option(ENABLE_DEBUG "Enable curl debug features (for developing curl itself)" OFF)
if(ENABLE_DEBUG)
if(ENABLE_DEBUG)
message(WARNING "This curl build is Debug-enabled and insecure, do not use in production.")
message(WARNING "This curl build is Debug-enabled and insecure, do not use in production.")
endif()
endif()
option(ENABLE_CURLDEBUG "Enable TrackMemory debug feature" ${ENABLE_DEBUG})
option(ENABLE_CURLDEBUG "Enable TrackMemory debug feature" ${ENABLE_DEBUG})
set(CURL_DEBUG_MACROS "")
set(CURL_DEBUG_MACROS "")
if(ENABLE_DEBUG)
if(ENABLE_DEBUG)
list(APPEND CURL_DEBUG_MACROS "DEBUGBUILD")
list(APPEND CURL_DEBUG_MACROS "DEBUGBUILD")
endif()
endif()
if(ENABLE_CURLDEBUG)
if(ENABLE_CURLDEBUG)
list(APPEND CURL_DEBUG_MACROS "CURLDEBUG")
list(APPEND CURL_DEBUG_MACROS "CURLDEBUG")
endif()
endif()
option(CURL_CLANG_TIDY "Run the build through clang-tidy" OFF)
option(CURL_CLANG_TIDY "Run the build through clang-tidy" OFF)
if(CURL_CLANG_TIDY)
if(CURL_CLANG_TIDY)
set(CMAKE_UNITY_BUILD OFF) # clang-tidy is not looking into #included sources, thus not compatible with unity builds.
set(CMAKE_UNITY_BUILD OFF) # clang-tidy is not looking into #included sources, thus not compatible with unity builds.
set(_tidy_checks "")
set(_tidy_checks "")
list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.bzero") # for FD_ZERO() (seen on macOS)
list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.bzero") # for FD_ZERO() (seen on macOS)
list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.strcpy")
list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.strcpy")
list(APPEND _tidy_checks "-clang-analyzer-optin.performance.Padding")
list(APPEND _tidy_checks "-clang-analyzer-optin.performance.Padding")
list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling")
list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling")
string(REPLACE ";" "," _tidy_checks "${_tidy_checks}")
string(REPLACE ";" "," _tidy_checks "${_tidy_checks}")
find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED)
find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED)
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY}" "-checks=${_tidy_checks}" "-quiet")
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY}" "-checks=${_tidy_checks}" "-quiet")
unset(_tidy_checks)
unset(_tidy_checks)
if(CURL_WERROR)
if(CURL_WERROR)
list(APPEND CMAKE_C_CLANG_TIDY "--warnings-as-errors=*")
list(APPEND CMAKE_C_CLANG_TIDY "--warnings-as-errors=*")
endif()
endif()
if(CURL_CLANG_TIDYFLAGS)
if(CURL_CLANG_TIDYFLAGS)
list(APPEND CMAKE_C_CLANG_TIDY ${CURL_CLANG_TIDYFLAGS})
list(APPEND CMAKE_C_CLANG_TIDY ${CURL_CLANG_TIDYFLAGS})
endif()
endif()
endif()
endif()
# For debug libs and exes, add "-d" postfix
# For debug libs and exes, add "-d" postfix
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "-d")
set(CMAKE_DEBUG_POSTFIX "-d")
endif()
endif()
set(LIB_STATIC "libcurl_static")
set(LIB_STATIC "libcurl_static")
set(LIB_SHARED "libcurl_shared")
set(LIB_SHARED "libcurl_shared")
if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
set(BUILD_STATIC_LIBS ON)
set(BUILD_STATIC_LIBS ON)
endif()
endif()
if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
if(NOT BUILD_STATIC_CURL AND NOT BUILD_SHARED_LIBS)
set(BUILD_STATIC_CURL ON)
set(BUILD_STATIC_CURL ON)
elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
elseif(BUILD_STATIC_CURL AND NOT BUILD_STATIC_LIBS)
set(BUILD_STATIC_CURL OFF)
set(BUILD_STATIC_CURL OFF)
endif()
endif()
# Lib flavour selected for curl tool
# Lib flavour selected for curl tool
if(BUILD_STATIC_CURL)
if(BUILD_STATIC_CURL)
set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
set(LIB_SELECTED_FOR_EXE ${LIB_STATIC})
else()
else()
set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
set(LIB_SELECTED_FOR_EXE ${LIB_SHARED})
endif()
endif()
# Lib flavour selected for example and test programs.
# Lib flavour selected for example and test programs.
if(BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
set(LIB_SELECTED ${LIB_SHARED})
set(LIB_SELECTED ${LIB_SHARED})
else()
else()
set(LIB_SELECTED ${LIB_STATIC})
set(LIB_SELECTED ${LIB_STATIC})
endif()
endif()
if(WIN32)
if(WIN32)
option(CURL_STATIC_CRT "Build libcurl with static CRT with MSVC (/MT)" OFF)
option(CURL_STATIC_CRT "Build libcurl with static CRT with MSVC (/MT)" OFF)
if(CURL_STATIC_CRT AND MSVC)
if(CURL_STATIC_CRT AND MSVC)
if(MSVC_VERSION GREATER_EQUAL 1900 OR BUILD_STATIC_CURL OR NOT BUILD_CURL_EXE)
if(MSVC_VERSION GREATER_EQUAL 1900 OR BUILD_STATIC_CURL OR NOT BUILD_CURL_EXE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Release>:-MT>")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Release>:-MT>")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Debug>:-MTd>")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Debug>:-MTd>")
else()
else()
message(WARNING "Static CRT requires UCRT, static libcurl or no curl executable.")
message(WARNING "Static CRT requires UCRT, static libcurl or no curl executable.")
endif()
endif()
endif()
endif()
endif()
endif()
# Override to force-disable or force-enable the use of pkg-config.
# Override to force-disable or force-enable the use of pkg-config.
if((UNIX AND NOT ANDROID AND (NOT APPLE OR CMAKE_SYSTEM_NAME MATCHES "Darwin")) OR
if((UNIX AND NOT ANDROID AND (NOT APPLE OR CMAKE_SYSTEM_NAME MATCHES "Darwin")) OR
VCPKG_TOOLCHAIN OR
VCPKG_TOOLCHAIN OR
(MINGW AND NOT CMAKE_CROSSCOMPILING))
(MINGW AND NOT CMAKE_CROSSCOMPILING))
set(_curl_use_pkgconfig_default ON)
set(_curl_use_pkgconfig_default ON)
else()
else()
set(_curl_use_pkgconfig_default OFF)
set(_curl_use_pkgconfig_default OFF)
endif()
endif()
option(CURL_USE_PKGCONFIG "Enable pkg-config to detect dependencies" ${_curl_use_pkgconfig_default})
option(CURL_USE_PKGCONFIG "Enable pkg-config to detect dependencies" ${_curl_use_pkgconfig_default})
# Initialize variables collecting dependency libs, paths, pkg-config names.
# Initialize variables collecting dependency libs, paths, pkg-config names.
set(CURL_LIBS "")
set(CURL_LIBS "")
set(CURL_LIBDIRS "")
set(CURL_LIBDIRS "")
set(LIBCURL_PC_REQUIRES_PRIVATE "")
set(LIBCURL_PC_REQUIRES_PRIVATE "")
if(ENABLE_ARES)
if(ENABLE_ARES)
set(USE_ARES 1)
set(USE_ARES 1)
find_package(Cares REQUIRED)
find_package(Cares REQUIRED)
list(APPEND CURL_LIBS ${CARES_LIBRARIES})
list(APPEND CURL_LIBS ${CARES_LIBRARIES})
list(APPEND CURL_LIBDIRS ${CARES_LIBRARY_DIRS})
list(APPEND CURL_LIBDIRS ${CARES_LIBRARY_DIRS})
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${CARES_PC_REQUIRES})
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${CARES_PC_REQUIRES})
include_directories(SYSTEM ${CARES_INCLUDE_DIRS})
include_directories(SYSTEM ${CARES_INCLUDE_DIRS})
link_directories(${CARES_LIBRARY_DIRS})
link_directories(${CARES_LIBRARY_DIRS})
if(CARES_CFLAGS)
if(CARES_CFLAGS)
string(APPEND CMAKE_C_FLAGS " ${CARES_CFLAGS}")
string(APPEND CMAKE_C_FLAGS " ${CARES_CFLAGS}")
endif()
endif()
endif()
endif()
include(CurlSymbolHiding)
include(CurlSymbolHiding)
option(CURL_ENABLE_EXPORT_TARGET "Enable CMake export target" ON)
option(CURL_ENABLE_EXPORT_TARGET "Enable CMake export target" ON)
mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
mark_as_advanced(CURL_ENABLE_EXPORT_TARGET)
option(CURL_DISABLE_ALTSVC "Disable alt-svc support" OFF)
option(CURL_DISABLE_ALTSVC "Disable alt-svc support" OFF)
mark_as_advanced(CURL_DISABLE_ALTSVC)
mark_as_advanced(CURL_DISABLE_ALTSVC)
option(CURL_DISABLE_SRP "Disable TLS-SRP support" OFF)
option(CURL_DISABLE_SRP "Disable TLS-SRP support" OFF)
mark_as_advanced(CURL_DISABLE_SRP)
mark_as_advanced(CURL_DISABLE_SRP)
option(CURL_DISABLE_COOKIES "Disable cookies support" OFF)
option(CURL_DISABLE_COOKIES "Disable cookies support" OFF)
mark_as_advanced(CURL_DISABLE_COOKIES)
mark_as_advanced(CURL_DISABLE_COOKIES)
option(CURL_DISABLE_BASIC_AUTH "Disable Basic authentication" OFF)
option(CURL_DISABLE_BASIC_AUTH "Disable Basic authentication" OFF)
mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
option(CURL_DISABLE_BEARER_AUTH "Disable Bearer authentication" OFF)
option(CURL_DISABLE_BEARER_AUTH "Disable Bearer authentication" OFF)
mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
option(CURL_DISABLE_DIGEST_AUTH "Disable Digest authentication" OFF)
option(CURL_DISABLE_DIGEST_AUTH "Disable Digest authentication" OFF)
mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
option(CURL_DISABLE_KERBEROS_AUTH "Disable Kerberos authentication" OFF)
option(CURL_DISABLE_KERBEROS_AUTH "Disable Kerberos authentication" OFF)
mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
option(CURL_DISABLE_NEGOTIATE_AUTH "Disable negotiate authentication" OFF)
option(CURL_DISABLE_NEGOTIATE_AUTH "Disable negotiate authentication" OFF)
mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
option(CURL_DISABLE_AWS "Disable aws-sigv4" OFF)
option(CURL_DISABLE_AWS "Disable aws-sigv4" OFF)
mark_as_advanced(CURL_DISABLE_AWS)
mark_as_advanced(CURL_DISABLE_AWS)
option(CURL_DISABLE_DICT "Disable DICT" OFF)
option(CURL_DISABLE_DICT "Disable DICT" OFF)
mark_as_advanced(CURL_DISABLE_DICT)
mark_as_advanced(CURL_DISABLE_DICT)
option(CURL_DISABLE_DOH "Disable DNS-over-HTTPS" OFF)
option(CURL_DISABLE_DOH "Disable DNS-over-HTTPS" OFF)
mark_as_advanced(CURL_DISABLE_DOH)
mark_as_advanced(CURL_DISABLE_DOH)
option(CURL_DISABLE_FILE "Disable FILE" OFF)
option(CURL_DISABLE_FILE "Disable FILE" OFF)
mark_as_advanced(CURL_DISABLE_FILE)
mark_as_advanced(CURL_DISABLE_FILE)
option(CURL_DISABLE_FTP "Disable FTP" OFF)
option(CURL_DISABLE_FTP "Disable FTP" OFF)
mark_as_advanced(CURL_DISABLE_FTP)
mark_as_advanced(CURL_DISABLE_FTP)
option(CURL_DISABLE_GETOPTIONS "Disable curl_easy_options API for existing options to curl_easy_setopt" OFF)
option(CURL_DISABLE_GETOPTIONS "Disable curl_easy_options API for existing options to curl_easy_setopt" OFF)
mark_as_advanced(CURL_DISABLE_GETOPTIONS)
mark_as_advanced(CURL_DISABLE_GETOPTIONS)
option(CURL_DISABLE_GOPHER "Disable Gopher" OFF)
option(CURL_DISABLE_GOPHER "Disable Gopher" OFF)
mark_as_advanced(CURL_DISABLE_GOPHER)
mark_as_advanced(CURL_DISABLE_GOPHER)
option(CURL_DISABLE_HEADERS_API "Disable headers-api support" OFF)
option(CURL_DISABLE_HEADERS_API "Disable headers-api support" OFF)
mark_as_advanced(CURL_DISABLE_HEADERS_API)
mark_as_advanced(CURL_DISABLE_HEADERS_API)
option(CURL_DISABLE_HSTS "Disable HSTS support" OFF)
option(CURL_DISABLE_HSTS "Disable HSTS support" OFF)
mark_as_advanced(CURL_DISABLE_HSTS)
mark_as_advanced(CURL_DISABLE_HSTS)
option(CURL_DISABLE_HTTP "Disable HTTP" OFF)
option(CURL_DISABLE_HTTP "Disable HTTP" OFF)
mark_as_advanced(CURL_DISABLE_HTTP)
mark_as_advanced(CURL_DISABLE_HTTP)
option(CURL_DISABLE_HTTP_AUTH "Disable all HTTP authentication methods" OFF)
option(CURL_DISABLE_HTTP_AUTH "Disable all HTTP authentication methods" OFF)
mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
mark_as_advanced(CURL_DISABLE_HTTP_AUTH)
option(CURL_DISABLE_IMAP "Disable IMAP" OFF)
option(CURL_DISABLE_IMAP "Disable IMAP" OFF)
mark_as_advanced(CURL_DISABLE_IMAP)
mark_as_advanced(CURL_DISABLE_IMAP)
option(CURL_DISABLE_LDAP "Disable LDAP" OFF)
option(CURL_DISABLE_LDAP "Disable LDAP" OFF)
mark_as_advanced(CURL_DISABLE_LDAP)
mark_as_advanced(CURL_DISABLE_LDAP)
option(CURL_DISABLE_LDAPS "Disable LDAPS" ${CURL_DISABLE_LDAP})
option(CURL_DISABLE_LDAPS "Disable LDAPS" ${CURL_DISABLE_LDAP})
mark_as_advanced(CURL_DISABLE_LDAPS)
mark_as_advanced(CURL_DISABLE_LDAPS)
option(CURL_DISABLE_LIBCURL_OPTION "Disable --libcurl option from the curl tool" OFF)
option(CURL_DISABLE_LIBCURL_OPTION "Disable --libcurl option from the curl tool" OFF)
mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
mark_as_advanced(CURL_DISABLE_LIBCURL_OPTION)
option(CURL_DISABLE_MIME "Disable MIME support" OFF)
option(CURL_DISABLE_MIME "Disable MIME support" OFF)
mark_as_advanced(CURL_DISABLE_MIME)
mark_as_advanced(CURL_DISABLE_MIME)
cmake_dependent_option(CURL_DISABLE_FORM_API "Disable form-api"
cmake_dependent_option(CURL_DISABLE_FORM_API "Disable form-api"
OFF "NOT CURL_DISABLE_MIME"
OFF "NOT CURL_DISABLE_MIME"
ON)
ON)
mark_as_advanced(CURL_DISABLE_FORM_API)
mark_as_advanced(CURL_DISABLE_FORM_API)
option(CURL_DISABLE_MQTT "Disable MQTT" OFF)
option(CURL_DISABLE_MQTT "Disable MQTT" OFF)
mark_as_advanced(CURL_DISABLE_MQTT)
mark_as_advanced(CURL_DISABLE_MQTT)
option(CURL_DISABLE_BINDLOCAL "Disable local binding support" OFF)
option(CURL_DISABLE_BINDLOCAL "Disable local binding support" OFF)
mark_as_advanced(CURL_DISABLE_BINDLOCAL)
mark_as_advanced(CURL_DISABLE_BINDLOCAL)
option(CURL_DISABLE_NETRC "Disable netrc parser" OFF)
option(CURL_DISABLE_NETRC "Disable netrc parser" OFF)
mark_as_advanced(CURL_DISABLE_NETRC)
mark_as_advanced(CURL_DISABLE_NETRC)
option(CURL_DISABLE_NTLM "Disable NTLM support" OFF)
option(CURL_DISABLE_NTLM "Disable NTLM support" OFF)
mark_as_advanced(CURL_DISABLE_NTLM)
mark_as_advanced(CURL_DISABLE_NTLM)
option(CURL_DISABLE_PARSEDATE "Disable date parsing" OFF)
option(CURL_DISABLE_PARSEDATE "Disable date parsing" OFF)
mark_as_advanced(CURL_DISABLE_PARSEDATE)
mark_as_advanced(CURL_DISABLE_PARSEDATE)
option(CURL_DISABLE_POP3 "Disable POP3" OFF)
option(CURL_DISABLE_POP3 "Disable POP3" OFF)
mark_as_advanced(CURL_DISABLE_POP3)
mark_as_advanced(CURL_DISABLE_POP3)
option(CURL_DISABLE_PROGRESS_METER "Disable built-in progress meter" OFF)
option(CURL_DISABLE_PROGRESS_METER "Disable built-in progress meter" OFF)
mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
mark_as_advanced(CURL_DISABLE_PROGRESS_METER)
option(CURL_DISABLE_PROXY "Disable proxy support" OFF)
option(CURL_DISABLE_PROXY "Disable proxy support" OFF)
mark_as_advanced(CURL_DISABLE_PROXY)
mark_as_advanced(CURL_DISABLE_PROXY)
option(CURL_DISABLE_IPFS "Disable IPFS" OFF)
option(CURL_DISABLE_IPFS "Disable IPFS" OFF)
mark_as_advanced(CURL_DISABLE_IPFS)
mark_as_advanced(CURL_DISABLE_IPFS)
option(CURL_DISABLE_RTSP "Disable RTSP" OFF)
option(CURL_DISABLE_RTSP "Disable RTSP" OFF)
mark_as_advanced(CURL_DISABLE_RTSP)
mark_as_advanced(CURL_DISABLE_RTSP)
option(CURL_DISABLE_SHA512_256 "Disable SHA-512/256 hash algorithm" OFF)
option(CURL_DISABLE_SHA512_256 "Disable SHA-512/256 hash algorithm" OFF)
mark_as_advanced(CURL_DISABLE_SHA512_256)
mark_as_advanced(CURL_DISABLE_SHA512_256)
option(CURL_DISABLE_SHUFFLE_DNS "Disable shuffle DNS feature" OFF)
option(CURL_DISABLE_SHUFFLE_DNS "Disable shuffle DNS feature" OFF)
mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
mark_as_advanced(CURL_DISABLE_SHUFFLE_DNS)
option(CURL_DISABLE_SMB "Disable SMB" OFF)
option(CURL_DISABLE_SMB "Disable SMB" OFF)
mark_as_advanced(CURL_DISABLE_SMB)
mark_as_advanced(CURL_DISABLE_SMB)
option(CURL_DISABLE_SMTP "Disable SMTP" OFF)
option(CURL_DISABLE_SMTP "Disable SMTP" OFF)
mark_as_advanced(CURL_DISABLE_SMTP)
mark_as_advanced(CURL_DISABLE_SMTP)
option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF)
option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF)
mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
option(CURL_DISABLE_WEBSOCKETS "Disable WebSocket" OFF)
option(CURL_DISABLE_WEBSOCKETS "Disable WebSocket" OFF)
mark_as_advanced(CURL_DISABLE_WEBSOCKETS)
mark_as_advanced(CURL_DISABLE_WEBSOCKETS)
option(CURL_DISABLE_TELNET "Disable Telnet" OFF)
option(CURL_DISABLE_TELNET "Disable Telnet" OFF)
mark_as_advanced(CURL_DISABLE_TELNET)
mark_as_advanced(CURL_DISABLE_TELNET)
option(CURL_DISABLE_TFTP "Disable TFTP" OFF)
option(CURL_DISABLE_TFTP "Disable TFTP" OFF)
mark_as_advanced(CURL_DISABLE_TFTP)
mark_as_advanced(CURL_DISABLE_TFTP)
option(CURL_DISABLE_VERBOSE_STRINGS "Disable verbose strings" OFF)
option(CURL_DISABLE_VERBOSE_STRINGS "Disable verbose strings" OFF)
mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
if(CURL_DISABLE_HTTP)
if(CURL_DISABLE_HTTP)
set(CURL_DISABLE_IPFS ON)
set(CURL_DISABLE_IPFS ON)
set(CURL_DISABLE_RTSP ON)
set(CURL_DISABLE_RTSP ON)
set(CURL_DISABLE_ALTSVC ON)
set(CURL_DISABLE_ALTSVC ON)
set(CURL_DISABLE_HSTS ON)
set(CURL_DISABLE_HSTS ON)
endif()
endif()
# Corresponds to HTTP_ONLY in lib/curl_setup.h
# Corresponds to HTTP_ONLY in lib/curl_setup.h
option(HTTP_ONLY "Disable all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
option(HTTP_ONLY "Disable all protocols except HTTP (This overrides all CURL_DISABLE_* options)" OFF)
mark_as_advanced(HTTP_ONLY)
mark_as_advanced(HTTP_ONLY)
if(HTTP_ONLY)
if(HTTP_ONLY)
set(CURL_DISABLE_DICT ON)
set(CURL_DISABLE_DICT ON)
set(CURL_DISABLE_FILE ON)
set(CURL_DISABLE_FILE ON)
set(CURL_DISABLE_FTP ON)
set(CURL_DISABLE_FTP ON)
set(CURL_DISABLE_GOPHER ON)
set(CURL_DISABLE_GOPHER ON)
set(CURL_DISABLE_IMAP ON)
set(CURL_DISABLE_IMAP ON)
set(CURL_DISABLE_LDAP ON)
set(CURL_DISABLE_LDAP ON)
set(CURL_DISABLE_LDAPS ON)
set(CURL_DISABLE_LDAPS ON)
set(CURL_DISABLE_MQTT ON)
set(CURL_DISABLE_MQTT ON)
set(CURL_DISABLE_POP3 ON)
set(CURL_DISABLE_POP3 ON)
set(CURL_DISABLE_IPFS ON)
set(CURL_DISABLE_IPFS ON)
set(CURL_DISABLE_RTSP ON)
set(CURL_DISABLE_RTSP ON)
set(CURL_DISABLE_SMB ON)
set(CURL_DISABLE_SMB ON)
set(CURL_DISABLE_SMTP ON)
set(CURL_DISABLE_SMTP ON)
set(CURL_DISABLE_TELNET ON)
set(CURL_DISABLE_TELNET ON)
set(CURL_DISABLE_TFTP ON)
set(CURL_DISABLE_TFTP ON)
endif()
endif()
if(WINDOWS_STORE OR WINCE)
if(WINDOWS_STORE OR WINCE)
set(CURL_DISABLE_TELNET ON) # telnet code needs fixing to compile for UWP.
set(CURL_DISABLE_TELNET ON) # telnet code needs fixing to compile for UWP.
endif()
endif()
find_package(Perl)
find_package(Perl)
if(PERL_EXECUTABLE)
if(PERL_EXECUTABLE)
add_custom_target(curl-ca-bundle
add_custom_target(curl-ca-bundle
COMMENT "Generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL
COMMENT "Generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL
COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl" -b -l -u "lib/ca-bundle.crt"
COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl" -b -l -u "lib/ca-bundle.crt"
DEPENDS "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl"
DEPENDS "${PROJECT_SOURCE_DIR}/scripts/mk-ca-bundle.pl"
)
)
add_custom_target(curl-ca-firefox
add_custom_target(curl-ca-firefox
COMMENT "Generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL
COMMENT "Generating a fresh ca-bundle.crt" VERBATIM USES_TERMINAL
COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" "lib/ca-bundle.crt"
COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" "lib/ca-bundle.crt"
DEPENDS "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh"
DEPENDS "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh"
)
)
endif()
endif()
option(BUILD_LIBCURL_DOCS "Build libcurl man pages" ON)
option(BUILD_LIBCURL_DOCS "Build libcurl man pages" ON)
option(BUILD_MISC_DOCS "Build misc man pages (e.g. curl-config and mk-ca-bundle)" ON)
option(BUILD_MISC_DOCS "Build misc man pages (e.g. curl-config and mk-ca-bundle)" ON)
option(ENABLE_CURL_MANUAL "Build the man page for curl and enable its -M/--manual option" ON)
option(ENABLE_CURL_MANUAL "Build the man page for curl and enable its -M/--manual option" ON)
if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS)
if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS)
if(PERL_FOUND)
if(PERL_FOUND)
set(HAVE_MANUAL_TOOLS ON)
set(HAVE_MANUAL_TOOLS ON)
endif()
endif()
if(NOT HAVE_MANUAL_TOOLS)
if(NOT HAVE_MANUAL_TOOLS)
message(WARNING "Perl not found. Will not build manuals.")
message(WARNING "Perl not found. Will not build manuals.")
endif()
endif()
endif()
endif()
# If we are on AIX, do the _ALL_SOURCE magic
# If we are on AIX, do the _ALL_SOURCE magic
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_ALL_SOURCE")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_ALL_SOURCE")
endif()
endif()
# If we are on Haiku, make sure that the network library is brought in.
# If we are on Haiku, make sure that the network library is brought in.
if(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
if(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
list(APPEND CURL_LIBS "network")
list(APPEND CURL_LIBS "network")
elseif(AMIGA)
elseif(AMIGA)
list(APPEND CURL_LIBS "net" "m" "atomic")
list(APPEND CURL_LIBS "net" "m" "atomic")
list(APPEND CMAKE_REQUIRED_LIBRARIES "net" "m" "atomic")
list(APPEND CMAKE_REQUIRED_LIBRARIES "net" "m" "atomic")
endif()
endif()
# Include all the necessary files for macros
# Include all the necessary files for macros
include(CMakePushCheckState)
include(CMakePushCheckState)
include(CheckFunctionExists)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckTypeSize)
include(CheckCSourceCompiles)
include(CheckCSourceCompiles)
option(_CURL_PREFILL "Fast-track known feature detection results (Windows, some Apple)" "${WIN32}")
option(_CURL_PREFILL "Fast-track known feature detection results (Windows, some Apple)" "${WIN32}")
if(_CURL_PREFILL)
if(_CURL_PREFILL)
if(WIN32)
if(WIN32)
include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/win32-cache.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/win32-cache.cmake")
elseif(UNIX)
elseif(UNIX)
include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/unix-cache.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/unix-cache.cmake")
message(STATUS "Pre-filling feature detection results for UNIX")
message(STATUS "Pre-filling feature detection results for UNIX")
endif()
endif()
elseif(WIN32)
elseif(WIN32)
message(STATUS "Pre-filling feature detection results disabled.")
message(STATUS "Pre-filling feature detection results disabled.")
elseif(APPLE)
elseif(APPLE)
set(HAVE_EVENTFD 0)
set(HAVE_EVENTFD 0)
set(HAVE_GETPASS_R 0)
set(HAVE_GETPASS_R 0)
set(HAVE_WRITABLE_ARGV 1)
set(HAVE_WRITABLE_ARGV 1)
set(HAVE_SENDMMSG 0)
set(HAVE_SENDMMSG 0)
endif()
endif()
if(AMIGA)
if(AMIGA)
set(HAVE_GETADDRINFO 0) # Breaks the build when detected and used.
set(HAVE_GETADDRINFO 0) # Breaks the build when detected and used.
endif()
endif()
if(DOS OR AMIGA)
if(DOS OR AMIGA)
set(HAVE_TIME_T_UNSIGNED 1)
set(HAVE_TIME_T_UNSIGNED 1)
endif()
endif()
if(ENABLE_THREADED_RESOLVER)
if(ENABLE_THREADED_RESOLVER)
if(WIN32)
if(WIN32)
set(USE_THREADS_WIN32 ON)
set(USE_THREADS_WIN32 ON)
else()
else()
find_package(Threads REQUIRED)
find_package(Threads REQUIRED)
set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
list(APPEND CURL_LIBS ${CMAKE_THREAD_LIBS_INIT})
list(APPEND CURL_LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
endif()
endif()
endif()
# Check for all needed libraries
# Check for all needed libraries
if(WIN32)
if(WIN32)
if(WINCE)
if(WINCE)
set(_win32_winsock "ws2")
set(_win32_winsock "ws2")
else()
else()
set(_win32_winsock "ws2_32")
set(_win32_winsock "ws2_32")
endif()
endif()
set(_win32_crypt32 "crypt32")
set(_win32_crypt32 "crypt32")
set(_win32_secur32 "secur32")
set(_win32_secur32 "secur32")
if(MINGW32CE) # FIXME upstream: must specify the full path to avoid CMake converting "ws2" to "ws2.lib"
if(MINGW32CE) # FIXME upstream: must specify the full path to avoid CMake converting "ws2" to "ws2.lib"
set(_win32_winsock "${MINGW32CE_LIBRARY_DIR}/lib${_win32_winsock}.a")
set(_win32_winsock "${MINGW32CE_LIBRARY_DIR}/lib${_win32_winsock}.a")
set(_win32_crypt32 "${MINGW32CE_LIBRARY_DIR}/lib${_win32_crypt32}.a")
set(_win32_crypt32 "${MINGW32CE_LIBRARY_DIR}/lib${_win32_crypt32}.a")
set(_win32_secur32 "${MINGW32CE_LIBRARY_DIR}/lib${_win32_secur32}.a")
set(_win32_secur32 "${MINGW32CE_LIBRARY_DIR}/lib${_win32_secur32}.a")
endif()
endif()
elseif(DOS)
elseif(DOS)
if(WATT_ROOT)
if(WATT_ROOT)
set(USE_WATT32 ON)
set(USE_WATT32 ON)
# FIXME upstream: must specify the full path to avoid CMake converting "watt" to "watt.lib"
# FIXME upstream: must specify the full path to avoid CMake converting "watt" to "watt.lib"
list(APPEND CURL_LIBS "${WATT_ROOT}/lib/libwatt.a")
list(APPEND CURL_LIBS "${WATT_ROOT}/lib/libwatt.a")
include_directories(SYSTEM "${WATT_ROOT}/inc")
include_directories(SYSTEM "${WATT_ROOT}/inc")
list(APPEND CMAKE_REQUIRED_INCLUDES "${WATT_ROOT}/inc")
list(APPEND CMAKE_REQUIRED_INCLUDES "${WATT_ROOT}/inc")
else()
else()
message(FATAL_ERROR "Set WATT_ROOT variable to the root installation of Watt-32.")
message(FATAL_ERROR "Set WATT_ROOT variable to the root installation of Watt-32.")
endif()
endif()
elseif(AMIGA)
elseif(AMIGA)
if(AMISSL_INCLUDE_DIR AND AMISSL_STUBS_LIBRARY AND AMISSL_AUTO_LIBRARY)
if(AMISSL_INCLUDE_DIR AND AMISSL_STUBS_LIBRARY AND AMISSL_AUTO_LIBRARY)
set(USE_AMISSL ON)
set(USE_AMISSL ON)
list(APPEND CMAKE_REQUIRED_INCLUDES "${AMISSL_INCLUDE_DIR}")
list(APPEND CMAKE_REQUIRED_INCLUDES "${AMISSL_INCLUDE_DIR}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${AMISSL_STUBS_LIBRARY}" "${AMISSL_AUTO_LIBRARY}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${AMISSL_STUBS_LIBRARY}" "${AMISSL_AUTO_LIBRARY}")
set(OPENSSL_INCLUDE_DIR "${AMISSL_INCLUDE_DIR}")
set(OPENSSL_INCLUDE_DIR "${AMISSL_INCLUDE_DIR}")
set(OPENSSL_SSL_LIBRARY "${AMISSL_STUBS_LIBRARY}")
set(OPENSSL_SSL_LIBRARY "${AMISSL_STUBS_LIBRARY}")
set(OPENSSL_CRYPTO_LIBRARY "${AMISSL_AUTO_LIBRARY}")
set(OPENSSL_CRYPTO_LIBRARY "${AMISSL_AUTO_LIBRARY}")
set(CURL_USE_OPENSSL ON)
set(CURL_USE_OPENSSL ON)
add_definitions(-DCURL_DEFAULT_SSL_BACKEND="schannel")
set(CURL_CA_FALLBACK ON CACHE BOOL "")
set(CURL_CA_FALLBACK ON CACHE BOOL "")
endif()
endif()
elseif(NOT APPLE)
elseif(NOT APPLE)
check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
if(HAVE_LIBSOCKET)
if(HAVE_LIBSOCKET)
set(CURL_LIBS "socket" ${CURL_LIBS})
set(CURL_LIBS "socket" ${CURL_LIBS})
endif()
endif()
endif()
endif()
option(ENABLE_IPV6 "Enable IPv6 support" ON)
option(ENABLE_IPV6 "Enable IPv6 support" ON)
mark_as_advanced(ENABLE_IPV6)
mark_as_advanced(ENABLE_IPV6)
if(ENABLE_IPV6)
if(ENABLE_IPV6)
include(CheckStructHasMember)
include(CheckStructHasMember)
if(WIN32)
if(WIN32)
check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "winsock2.h;ws2tcpip.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "winsock2.h;ws2tcpip.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
else()
else()
check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
check_struct_has_member("struct sockaddr_in6" "sin6_ad