]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: more small tidy-ups and fixes
authorViktor Szakats <commit@vsz.me>
Wed, 7 Aug 2024 22:53:38 +0000 (00:53 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 8 Aug 2024 11:48:28 +0000 (13:48 +0200)
- tidy up two `MATCHES` expression by avoiding macros expansion and
  adding quotes. Then convert then to `STREQUAL` to match other places
  in the code doing the same checks.

- fix setting `_ALL_SOURCE` for AIX to match what autotools does.

- delete stray `_ALL_SOURCE` reference from `lib/config_riscos.h`

- simplify/fix two `STREQUAL ""` checks.
  The one in the `openssl_check_symbol_exists()` macro succeeded
  regardless of the value. The other could return TRUE when
  `CMAKE_OSX_SYSROOT` was undefined.

- delete code for CMake versions (<3.7) we no longer support.

- prefer `LIST(APPEND ...)` to extend `CURL_LIBS`.

- use `CURL_LIBS` to add the `network` lib for Haiku.
  Before this patch it was done via raw C flags. I could not test this.

- move `_WIN32_WINNT`-related code next to each other.
  It also moves detection to the top, allowing more code to use
  the result.

- merge two `WIN32` blocks.

- rename internal variables to underscore + lowercase.

- unwrap a line, indent, whitespace.

Closes #14450

CMake/CurlSymbolHiding.cmake
CMake/cmake_uninstall.cmake.in
CMakeLists.txt
lib/config-riscos.h
lib/curl_config.h.cmake
tests/CMakeLists.txt

index a44ad995cae83ee09f5043646ee0b29623bbe96e..cda552a15e1ab46797f934054b4d5eabae35fe2c 100644 (file)
@@ -34,52 +34,47 @@ if(WIN32 AND (ENABLE_DEBUG OR ENABLE_CURLDEBUG))
 endif()
 
 if(CURL_HIDDEN_SYMBOLS)
-  set(SUPPORTS_SYMBOL_HIDING FALSE)
+  set(_supports_symbol_hiding FALSE)
 
   if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
-    set(SUPPORTS_SYMBOL_HIDING TRUE)
-    set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
-    set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
+    set(_supports_symbol_hiding TRUE)
+    set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
+    set(_cflag_symbols_hide "-fvisibility=hidden")
   elseif(CMAKE_COMPILER_IS_GNUCC)
     if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
       # Note: This is considered buggy prior to 4.0 but the autotools do not care, so let us ignore that fact
-      set(SUPPORTS_SYMBOL_HIDING TRUE)
-      set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
-      set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
+      set(_supports_symbol_hiding TRUE)
+      set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
+      set(_cflag_symbols_hide "-fvisibility=hidden")
     endif()
   elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
-    set(SUPPORTS_SYMBOL_HIDING TRUE)
-    set(_SYMBOL_EXTERN "__global")
-    set(_CFLAG_SYMBOLS_HIDE "-xldscope=hidden")
+    set(_supports_symbol_hiding TRUE)
+    set(_symbol_extern "__global")
+    set(_cflag_symbols_hide "-xldscope=hidden")
   elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
     # Note: This should probably just check for version 9.1.045 but I am not 100% sure
     #       so let us do it the same way autotools do.
-    set(SUPPORTS_SYMBOL_HIDING TRUE)
-    set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
-    set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
+    set(_supports_symbol_hiding TRUE)
+    set(_symbol_extern "__attribute__ ((__visibility__ (\"default\")))")
+    set(_cflag_symbols_hide "-fvisibility=hidden")
     check_c_source_compiles("#include <stdio.h>
-      int main (void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
+      int main(void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
     if(NOT _no_bug)
-      set(SUPPORTS_SYMBOL_HIDING FALSE)
-      set(_SYMBOL_EXTERN "")
-      set(_CFLAG_SYMBOLS_HIDE "")
+      set(_supports_symbol_hiding FALSE)
+      set(_symbol_extern "")
+      set(_cflag_symbols_hide "")
     endif()
   elseif(MSVC)
-    set(SUPPORTS_SYMBOL_HIDING TRUE)
+    set(_supports_symbol_hiding TRUE)
   endif()
 
-  set(HIDES_CURL_PRIVATE_SYMBOLS ${SUPPORTS_SYMBOL_HIDING})
-elseif(MSVC)
-  if(NOT CMAKE_VERSION VERSION_LESS 3.7)
-    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) #present since 3.4.3 but broken
-    set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
-  else()
-    message(WARNING "Hiding private symbols regardless CURL_HIDDEN_SYMBOLS being disabled.")
-    set(HIDES_CURL_PRIVATE_SYMBOLS TRUE)
-  endif()
+  set(HIDES_CURL_PRIVATE_SYMBOLS ${_supports_symbol_hiding})
 else()
+  if(MSVC)
+    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+  endif()
   set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
 endif()
 
-set(CURL_CFLAG_SYMBOLS_HIDE ${_CFLAG_SYMBOLS_HIDE})
-set(CURL_EXTERN_SYMBOL ${_SYMBOL_EXTERN})
+set(CURL_CFLAG_SYMBOLS_HIDE ${_cflag_symbols_hide})
+set(CURL_EXTERN_SYMBOL ${_symbol_extern})
index e15997063250159569019d685ba8a313b07e56cd..d1f746fc096ee617a38a6fabb19aa4673fa5183b 100644 (file)
@@ -39,7 +39,7 @@ foreach(_file ${_files})
       "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${_file}\""
       OUTPUT_VARIABLE rm_out
       RETURN_VALUE rm_retval
-      )
+    )
     if(NOT "${rm_retval}" STREQUAL 0)
       message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${_file}")
     endif()
index 45385412183a1a327b500dedbef07cf2d0a75986..2167e5f44c21da3aa873d9e54949e5d082d9dced 100644 (file)
@@ -123,19 +123,33 @@ option(CURL_DISABLE_INSTALL "Set to ON to disable installation targets" OFF)
 
 if(WIN32)
   option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
+
   option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
+  if(ENABLE_UNICODE)
+    add_definitions("-DUNICODE" "-D_UNICODE")
+    if(MINGW)
+      add_compile_options(-municode)
+    endif()
+  endif()
+
   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}")
     list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
     set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
   endif()
-  if(ENABLE_UNICODE)
-    add_definitions("-DUNICODE" "-D_UNICODE")
-    if(MINGW)
-      add_compile_options(-municode)
-    endif()
+
+  # Detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
+  curl_internal_test(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 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(TOLOWER "${CURL_TEST_OUTPUT}" HAVE_WIN32_WINNT)
+    message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
   endif()
+  # Avoid storing HAVE_WIN32_WINNT in CMake cache
+  unset(HAVE_WIN32_WINNT CACHE)
 endif()
 option(CURL_LTO "Turn on compiler Link Time Optimizations" OFF)
 
@@ -370,13 +384,13 @@ if(BORLAND)
 endif()
 
 # If we are on AIX, do the _ALL_SOURCE magic
-if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
-  set(_ALL_SOURCE 1)
+if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+  add_definitions("-D_ALL_SOURCE")
 endif()
 
 # If we are on Haiku, make sure that the network library is brought in.
-if(${CMAKE_SYSTEM_NAME} MATCHES Haiku)
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnetwork")
+if(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
+  list(APPEND CURL_LIBS "network")
 endif()
 
 # Include all the necessary files for macros
@@ -401,7 +415,7 @@ if(ENABLE_THREADED_RESOLVER)
     find_package(Threads REQUIRED)
     set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
     set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
-    set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+    list(APPEND CURL_LIBS ${CMAKE_THREAD_LIBS_INIT})
   endif()
 endif()
 
@@ -505,15 +519,9 @@ if(CURL_USE_OPENSSL)
   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 OpenSSL::SSL OpenSSL::Crypto)
-  else()
-    list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
-    include_directories(${OPENSSL_INCLUDE_DIR})
-  endif()
+  # Depend on OpenSSL via imported targets. This allows our dependents to
+  # get our dependencies transitively.
+  list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)
   list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "openssl")
 
   if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "openssl")
@@ -608,15 +616,9 @@ if(ZLIB_FOUND)
   set(HAVE_LIBZ ON)
   set(USE_ZLIB ON)
 
-  # Depend on ZLIB 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 ZLIB::ZLIB)
-  else()
-    list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
-    include_directories(${ZLIB_INCLUDE_DIRS})
-  endif()
+  # Depend on ZLIB via imported targets. This allows our dependents to
+  # get our dependencies transitively.
+  list(APPEND CURL_LIBS ZLIB::ZLIB)
   list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "zlib")
   list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
 endif()
@@ -673,9 +675,7 @@ macro(openssl_check_symbol_exists _symbol _files _variable _extra_libs)
     endif()
     list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_UINTPTR_T")  # to pull in stdint.h (as of wolfSSL v5.5.4)
   endif()
-  if(NOT _extra_libs STREQUAL "")
-    list(APPEND CMAKE_REQUIRED_LIBRARIES "${_extra_libs}")
-  endif()
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${_extra_libs}")
   check_symbol_exists("${_symbol}" "${_files}" "${_variable}")
   cmake_pop_check_state()
 endmacro()
@@ -1266,20 +1266,6 @@ if(WIN32)
   set(CURL_INCLUDES ${CURL_INCLUDES} "winsock2.h")
   set(CURL_INCLUDES ${CURL_INCLUDES} "ws2tcpip.h")
   set(CURL_INCLUDES ${CURL_INCLUDES} "windows.h")
-endif()
-
-if(WIN32)
-  # Detect actual value of _WIN32_WINNT and store as HAVE_WIN32_WINNT
-  curl_internal_test(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 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(TOLOWER "${CURL_TEST_OUTPUT}" HAVE_WIN32_WINNT)
-    message(STATUS "Found _WIN32_WINNT=${HAVE_WIN32_WINNT}")
-  endif()
-  # Avoid storing HAVE_WIN32_WINNT in CMake cache
-  unset(HAVE_WIN32_WINNT CACHE)
 
   if(HAVE_WIN32_WINNT)
     if(HAVE_WIN32_WINNT LESS 0x0501)
@@ -1817,8 +1803,8 @@ if(NOT CURL_DISABLE_INSTALL)
     list(SORT _items)
   endif()
   string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
-  string(TOLOWER "${SUPPORT_PROTOCOLS}" SUPPORT_PROTOCOLS_LOWER)
-  message("Protocols: ${SUPPORT_PROTOCOLS_LOWER}")
+  string(TOLOWER "${SUPPORT_PROTOCOLS}" _support_protocols_lower)
+  message("Protocols: ${_support_protocols_lower}")
 
   # Clear list and try to detect available features
   set(_items)
@@ -2070,7 +2056,6 @@ if(NOT CURL_DISABLE_INSTALL)
       IMMEDIATE @ONLY)
 
     add_custom_target(curl_uninstall
-      COMMAND ${CMAKE_COMMAND} -P
-      "${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake")
+      COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake")
   endif()
 endif()
index 056f55405b0c17bbc10385c1e42996b3a3557b4f..2303f129417f853b699233ad3ab299f465c16717 100644 (file)
 /* Version number of package */
 #undef VERSION
 
-/* Define if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
-#ifndef _ALL_SOURCE
-# undef _ALL_SOURCE
-#endif
-
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS
 
index 0dd9bf5b3cec051251072b9159cc78ddd6c3607f..aa89c600ddd48fea4d51e417e3c511d1c1d0237e 100644 (file)
@@ -768,11 +768,6 @@ ${SIZEOF_TIME_T_CODE}
 /* Version number of package */
 #cmakedefine VERSION ${VERSION}
 
-/* Define to 1 if OS is AIX. */
-#ifndef _ALL_SOURCE
-#  undef _ALL_SOURCE
-#endif
-
 /* Number of bits in a file offset, on hosts where this is settable. */
 #cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS}
 
index f6c234c8780baedf88937e4232cc1ec8065d4981..cdebf3092923e8121592b70dfea0d6ba86e6c658 100644 (file)
@@ -56,7 +56,7 @@ endfunction()
 # Create configurehelp.pm, used by tests needing to run the C preprocessor.
 if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
   set(_cpp_cmd "\"${CMAKE_C_COMPILER}\" -E")
-  if(APPLE AND NOT CMAKE_OSX_SYSROOT STREQUAL "")
+  if(APPLE AND CMAKE_OSX_SYSROOT)
     set(_cpp_cmd "${_cpp_cmd} -isysroot ${CMAKE_OSX_SYSROOT}")
   endif()
   # Add header directories, like autotools builds do.