cmake: minor tidy-ups

- show `OpenSSL v3+` when detected (as in `./configure`).
  (this string also makes its way to `curl-config`.)
- prefer `unset(VAR)` over `set(VAR)`.
  Same effect, but `unset()` tells the intent unambiguously.
  https://cmake.org/cmake/help/latest/command/set.html
- drop "implementation" from an `option()` description.
- FindGSS: replace legacy keyword alias with modern alternative.
  https://cmake.org/cmake/help/latest/command/get_filename_component.html
- move `CURL_STATIC_CRT` logic next to its `option()`.
- improve order of `libcurl.pc`/`curl-config` variable init lines.
- tests: drop/shorten custom target names.
  They inflated generated make files by 550KB.
  Keep target name logic for sync between code snippets.
  Follow-up to a2ef5d36b3 #14660
- clear a variable after use.
- restore `STATUS` for `Features:`/`Protocols:` `message()`s:
  Without it the output goes to stderr, and appears in red in CMake GUI.
  It doesn't seem possible to show a line on stdout without leading
  underscores to match `curl -V` and `./configure` output.
  Partial revert of acbc6b703f #14197
- WindowsCache: move `HAVE_LINUX_TCP_H` into the header group.
- move strings to the same line as their `STRING` keyword.
- formatting in generated code.
- delete bogus comment.
- unfold lines for readability.
- fix a too long line. (for cmakelint)
- missing quotes, whitespace, comments.

Closes #14610
This commit is contained in:
Viktor Szakats 2024-08-19 21:05:25 +02:00
parent 5d4d1c712f
commit 8b09138083
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
10 changed files with 65 additions and 67 deletions

View File

@ -210,7 +210,7 @@ if(NOT _GSS_FOUND) # Not found by pkg-config. Let us take more traditional appr
if(GSS_FLAVOUR)
set(_gss_libdir_suffixes "")
set(_gss_libdir_hints ${_gss_root_hints})
get_filename_component(_gss_calculated_potential_root "${_GSS_INCLUDE_DIRS}" PATH)
get_filename_component(_gss_calculated_potential_root "${_GSS_INCLUDE_DIRS}" DIRECTORY)
list(APPEND _gss_libdir_hints ${_gss_calculated_potential_root})
if(WIN32)

View File

@ -35,7 +35,7 @@ endmacro()
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
if(NOT DEFINED HAVE_STRUCT_SOCKADDR_STORAGE)
set(CMAKE_EXTRA_INCLUDE_FILES)
unset(CMAKE_EXTRA_INCLUDE_FILES)
if(WIN32)
set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
set(CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN")

View File

@ -138,6 +138,7 @@ set(HAVE_SYS_UTIME_H 1)
set(HAVE_TERMIOS_H 0)
set(HAVE_TERMIO_H 0)
set(HAVE_UTIME_H 0) # mingw-w64 has it (wrapper to sys/utime.h)
set(HAVE_LINUX_TCP_H 0)
set(HAVE_DIRENT_H 0)
set(HAVE_OPENDIR 0)
@ -161,7 +162,6 @@ set(HAVE_GMTIME_R 0)
set(HAVE_GETHOSTBYNAME_R 0)
set(HAVE_SIGNAL 1)
set(HAVE_SIGACTION 0)
set(HAVE_LINUX_TCP_H 0)
set(HAVE_GLIBC_STRERROR_R 0)
set(HAVE_MACH_ABSOLUTE_TIME 0)
set(HAVE_GETIFADDRS 0)

View File

@ -24,7 +24,7 @@
@PACKAGE_INIT@
if(NOT DEFINED CURL_USE_PKGCONFIG)
if(UNIX OR (MSVC AND VCPKG_TOOLCHAIN)) # Keep this in sync with root CMakeLists.txt
if(UNIX OR (MSVC AND VCPKG_TOOLCHAIN)) # Keep in sync with root CMakeLists.txt
set(CURL_USE_PKGCONFIG ON)
else()
set(CURL_USE_PKGCONFIG OFF)

View File

@ -54,7 +54,7 @@ include(CheckCCompilerFlag)
project(CURL C)
set(_flags)
unset(_flags)
if(APPLE)
set(_flags "${_flags} APPLE")
endif()
@ -83,10 +83,12 @@ if(VCPKG_TOOLCHAIN)
set(_flags "${_flags} VCPKG")
endif()
message(STATUS "CMake platform flags:${_flags}")
set(_flags)
unset(_flags)
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross-compiling: ${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR} -> ${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Cross-compiling: "
"${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR} -> "
"${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}")
endif()
function(curl_dumpvars) # Dump all defined variables with their values
@ -98,13 +100,12 @@ function(curl_dumpvars) # Dump all defined variables with their values
message("::endgroup::")
endfunction()
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})
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 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})
unset(_curl_version_h_contents)
message(STATUS "curl version=[${CURL_VERSION}]")
@ -131,6 +132,11 @@ option(CURL_DISABLE_INSTALL "Disable installation targets" OFF)
if(WIN32)
option(CURL_STATIC_CRT "Build libcurl with static CRT on Windows (/MT)" OFF)
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()
option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF)
if(ENABLE_UNICODE)
@ -214,7 +220,7 @@ else()
endif()
# Override to force-disable or force-enable the use of pkg-config.
if(UNIX OR (MSVC AND VCPKG_TOOLCHAIN)) # Keep this in sync with CMake/curl-config.cmake.in
if(UNIX OR (MSVC AND VCPKG_TOOLCHAIN)) # Keep in sync with CMake/curl-config.cmake.in
set(_curl_use_pkgconfig_default ON)
else()
set(_curl_use_pkgconfig_default OFF)
@ -360,8 +366,7 @@ if(ENABLE_IPV6 AND NOT WIN32)
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 "Enable IPv6 support" FORCE)
set(ENABLE_IPV6 OFF CACHE BOOL "Enable IPv6 support" FORCE)
endif()
if(APPLE AND NOT ENABLE_ARES)
@ -395,12 +400,6 @@ if(ENABLE_CURL_MANUAL OR BUILD_LIBCURL_DOCS)
endif()
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-")
@ -940,7 +939,7 @@ if(NOT CURL_DISABLE_LDAP)
include_directories(${CMAKE_LDAP_INCLUDE_DIR})
endif()
set(NEED_LBER_H ON)
set(_header_list)
unset(_header_list)
if(WIN32)
list(APPEND _header_list "windows.h")
endif()
@ -1115,7 +1114,7 @@ if(NOT USE_LIBSSH2 AND NOT USE_LIBSSH AND CURL_USE_WOLFSSH)
endif()
endif()
option(CURL_USE_GSASL "Use libgsasl implementation" OFF)
option(CURL_USE_GSASL "Use libgsasl" OFF)
mark_as_advanced(CURL_USE_GSASL)
if(CURL_USE_GSASL)
find_package(Libgsasl REQUIRED)
@ -1250,14 +1249,14 @@ endif()
# CA handling
#
if(_curl_ca_bundle_supported)
set(CURL_CA_BUNDLE "auto" CACHE STRING
"Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(CURL_CA_BUNDLE "auto" CACHE
STRING "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(CURL_CA_FALLBACK OFF CACHE BOOL
"Set ON to use built-in CA store of TLS backend. Defaults to OFF")
set(CURL_CA_PATH "auto" CACHE STRING
"Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(CURL_CA_EMBED "" CACHE STRING
"Path to the CA bundle to embed into the curl tool.")
set(CURL_CA_PATH "auto" CACHE
STRING "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(CURL_CA_EMBED "" CACHE
STRING "Path to the CA bundle to embed into the curl tool.")
if(CURL_CA_BUNDLE STREQUAL "")
message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
@ -1303,8 +1302,8 @@ if(_curl_ca_bundle_supported)
"/etc/ssl/cert.pem")
if(EXISTS "${_search_ca_bundle_path}")
message(STATUS "Found CA bundle: ${_search_ca_bundle_path}")
set(CURL_CA_BUNDLE "${_search_ca_bundle_path}" CACHE STRING
"Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(CURL_CA_BUNDLE "${_search_ca_bundle_path}" CACHE
STRING "Path to the CA bundle. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(_curl_ca_bundle_set TRUE CACHE BOOL "Path to the CA bundle has been set")
break()
endif()
@ -1317,8 +1316,8 @@ if(_curl_ca_bundle_supported)
if(_curl_ca_files_found)
unset(_curl_ca_files_found)
message(STATUS "Found CA path: ${_search_ca_path}")
set(CURL_CA_PATH "${_search_ca_path}" CACHE STRING
"Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(CURL_CA_PATH "${_search_ca_path}" CACHE
STRING "Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
set(_curl_ca_path_set TRUE CACHE BOOL "Path to the CA bundle has been set")
endif()
endif()
@ -1584,7 +1583,7 @@ if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
}" HAVE_WRITABLE_ARGV)
endif()
set(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_FLAGS)
option(ENABLE_WEBSOCKETS "Enable WebSockets (experimental)" OFF)
@ -1649,7 +1648,7 @@ if(HAVE_FIONBIO OR
HAVE_IOCTLSOCKET OR
HAVE_IOCTLSOCKET_CASE OR
HAVE_O_NONBLOCK)
set(HAVE_DISABLED_NONBLOCKING)
unset(HAVE_DISABLED_NONBLOCKING)
endif()
if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
@ -1741,7 +1740,7 @@ function(transform_makefile_inc _input_file _output_file)
string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" _makefile_inc_text ${_makefile_inc_text})
string(REGEX REPLACE "\\\\\n" "!π!α!" _makefile_inc_text ${_makefile_inc_text})
string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" _makefile_inc_text ${_makefile_inc_text})
string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "set(\\1 \\2)" _makefile_inc_text ${_makefile_inc_text})
string(REPLACE "!π!α!" "\n" _makefile_inc_text ${_makefile_inc_text})
# Replace $() with ${}
@ -1815,7 +1814,7 @@ if(NOT CURL_DISABLE_INSTALL)
endif()
# Clear list and try to detect available protocols
set(_items)
unset(_items)
_add_if("HTTP" NOT CURL_DISABLE_HTTP)
_add_if("IPFS" NOT CURL_DISABLE_HTTP)
_add_if("IPNS" NOT CURL_DISABLE_HTTP)
@ -1855,10 +1854,10 @@ if(NOT CURL_DISABLE_INSTALL)
endif()
string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
string(TOLOWER "${SUPPORT_PROTOCOLS}" _support_protocols_lower)
message("Protocols: ${_support_protocols_lower}")
message(STATUS "Protocols: ${_support_protocols_lower}")
# Clear list and try to detect available features
set(_items)
unset(_items)
_add_if("SSL" _ssl_enabled)
_add_if("IPv6" ENABLE_IPV6)
_add_if("UnixSockets" USE_UNIX_SOCKETS)
@ -1907,12 +1906,13 @@ if(NOT CURL_DISABLE_INSTALL)
endif()
endif()
string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
message("Features: ${SUPPORT_FEATURES}")
message(STATUS "Features: ${SUPPORT_FEATURES}")
# Clear list and collect SSL backends
set(_items)
unset(_items)
_add_if("Schannel" _ssl_enabled AND USE_SCHANNEL)
_add_if("OpenSSL" _ssl_enabled AND USE_OPENSSL)
_add_if("OpenSSL" _ssl_enabled AND USE_OPENSSL AND OPENSSL_VERSION VERSION_LESS 3.0.0)
_add_if("OpenSSL v3+" _ssl_enabled AND USE_OPENSSL AND NOT OPENSSL_VERSION VERSION_LESS 3.0.0)
_add_if("Secure Transport" _ssl_enabled AND USE_SECTRANSP)
_add_if("mbedTLS" _ssl_enabled AND USE_MBEDTLS)
_add_if("BearSSL" _ssl_enabled AND USE_BEARSSL)
@ -1938,16 +1938,21 @@ if(NOT CURL_DISABLE_INSTALL)
# TODO: probably put a -D... options here?
set(CONFIGURE_OPTIONS "")
set(CURLVERSION "${CURL_VERSION}")
set(VERSIONNUM "${CURL_VERSION_NUM}")
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
set(includedir "\${prefix}/include")
set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
set(LIBCURL_PC_LIBS_PRIVATE "")
set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
# "a" (Linux) or "lib" (Windows)
string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(LIBCURL_PC_LIBS_PRIVATE "")
# For processing full path libraries into -L and -l ld options,
# the directories that go with the -L option are cached, so they
# only get added once per such directory.
set(_libcurl_libs_dirs)
unset(_libcurl_libs_dirs)
# To avoid getting unnecessary -L options for known system directories,
# _libcurl_libs_dirs is seeded with them.
foreach(_libdir IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
@ -2009,7 +2014,6 @@ if(NOT CURL_DISABLE_INSTALL)
endif()
endforeach()
# Export a .pc file for client projects not using CMake
if(LIBCURL_PC_REQUIRES_PRIVATE)
string(REPLACE ";" "," LIBCURL_PC_REQUIRES_PRIVATE "${LIBCURL_PC_REQUIRES_PRIVATE}")
endif()
@ -2017,27 +2021,23 @@ if(NOT CURL_DISABLE_INSTALL)
# Merge pkg-config private fields into public ones when static-only
if(BUILD_SHARED_LIBS)
set(ENABLE_SHARED "yes")
set(LIBCURL_PC_REQUIRES "")
set(LIBCURL_PC_LIBS "")
set(LIBCURL_PC_CFLAGS "")
set(ENABLE_SHARED "yes")
set(LIBCURL_PC_REQUIRES "")
set(LIBCURL_PC_LIBS "")
set(LIBCURL_PC_CFLAGS "")
else()
set(ENABLE_SHARED "no")
set(LIBCURL_PC_REQUIRES "${LIBCURL_PC_REQUIRES_PRIVATE}")
set(LIBCURL_PC_LIBS "${LIBCURL_PC_LIBS_PRIVATE}")
set(LIBCURL_PC_CFLAGS "${LIBCURL_PC_CFLAGS_PRIVATE}")
set(ENABLE_SHARED "no")
set(LIBCURL_PC_REQUIRES "${LIBCURL_PC_REQUIRES_PRIVATE}")
set(LIBCURL_PC_LIBS "${LIBCURL_PC_LIBS_PRIVATE}")
set(LIBCURL_PC_CFLAGS "${LIBCURL_PC_CFLAGS_PRIVATE}")
endif()
if(BUILD_STATIC_LIBS)
set(ENABLE_STATIC "yes")
set(ENABLE_STATIC "yes")
else()
set(ENABLE_STATIC "no")
set(ENABLE_STATIC "no")
endif()
# "a" (Linux) or "lib" (Windows)
string(REPLACE "." "" libext "${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(prefix "${CMAKE_INSTALL_PREFIX}")
# Set this to "yes" to append all libraries on which -lcurl is dependent
set(REQUIRE_LIB_DEPS "no")
set(VERSIONNUM "${CURL_VERSION_NUM}")
# Finally generate a "curl-config" matching this config.
# Consumed variables:

View File

@ -95,8 +95,7 @@ if(SHARE_LIB_OBJECT)
# exported libcurl symbols. We handle exports via libcurl.def instead.
# Except with symbol hiding disabled or debug mode enabled, when we export
# _all_ symbols from libcurl DLL, without using libcurl.def.
set_property(TARGET ${LIB_OBJECT} APPEND
PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
endif()
target_link_libraries(${LIB_OBJECT} PRIVATE ${CURL_LIBS})
set_target_properties(${LIB_OBJECT} PROPERTIES
@ -126,8 +125,7 @@ if(BUILD_STATIC_LIBS)
add_library(${LIB_STATIC} STATIC ${LIB_SOURCE})
add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC})
if(WIN32)
set_property(TARGET ${LIB_OBJECT} APPEND
PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
endif()
target_link_libraries(${LIB_STATIC} PRIVATE ${CURL_LIBS})
# Remove the "lib" prefix since the library is already named "libcurl".

View File

@ -27,7 +27,7 @@ transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
foreach(_target IN LISTS check_PROGRAMS)
set(_target_name "curl-test-client-${_target}")
set(_target_name "curlt-client-${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
add_dependencies(testdeps ${_target_name})
target_include_directories(${_target_name} PRIVATE

View File

@ -39,7 +39,7 @@ foreach(_target IN LISTS noinst_PROGRAMS)
endif()
string(TOUPPER ${_target} _upper_target)
set(_target_name "curl-test-${_target}")
set(_target_name "${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL ${_sources})
add_dependencies(testdeps ${_target_name})
target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})

View File

@ -27,7 +27,7 @@ transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
foreach(_target IN LISTS noinst_PROGRAMS)
set(_target_name "curl-test-server-${_target}")
set(_target_name "${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL ${${_target}_SOURCES})
add_dependencies(testdeps ${_target_name})
target_include_directories(${_target_name} PRIVATE

View File

@ -27,7 +27,7 @@ transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
foreach(_target IN LISTS UNITPROGS)
set(_target_name "curl-test-${_target}")
set(_target_name "${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c" ${UNITFILES})
add_dependencies(testdeps ${_target_name})
target_link_libraries(${_target_name} curltool curlu)