CMake: clean up and improve build procedures
- remove check for unsupported old CMake versions
- do not link to c-ares library twice
- modernize custom Find modules
- FindLibSSH2:
- pass version to FPHSA to show it in the output
- use LIBSSH2_VERSION define to extract the version number in
one shot. This variable exists in the header for 10 years.
- remove unneeded code
- FindNGHTTP2.cmake:
- drop needless FPHSA argument
- mark found variables as advanced
- FindNSS.cmake:
- show version number
- FindCARES.cmake:
- drop default paths
- use FPHSA instead of checking things by hand
- remove needless explict variable dereference
- simplify count_true()
- allow all policies up to version 3.16 to be set to NEW
- do not rerun check for -Wstrict-aliasing=3 every time
In contrast to every other compiler flag this has a = in it, which CMake
can't have in a variable name.
- only read the interesting strings from curlver.h
Reviewed-by: Peter Wu
Closes https://github.com/curl/curl/pull/4975
This commit is contained in:
parent
711f022c05
commit
fc9312f717
@ -11,13 +11,7 @@ if(CURL_HIDDEN_SYMBOLS)
|
|||||||
set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
|
set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
|
||||||
set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
|
set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCC)
|
elseif(CMAKE_COMPILER_IS_GNUCC)
|
||||||
if(NOT CMAKE_VERSION VERSION_LESS 2.8.10)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
|
||||||
set(GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
|
|
||||||
else()
|
|
||||||
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
|
|
||||||
OUTPUT_VARIABLE GCC_VERSION)
|
|
||||||
endif()
|
|
||||||
if(NOT GCC_VERSION VERSION_LESS 3.4)
|
|
||||||
# note: this is considered buggy prior to 4.0 but the autotools don't care, so let's ignore that fact
|
# note: this is considered buggy prior to 4.0 but the autotools don't care, so let's ignore that fact
|
||||||
set(SUPPORTS_SYMBOL_HIDING TRUE)
|
set(SUPPORTS_SYMBOL_HIDING TRUE)
|
||||||
set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
|
set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
|
||||||
|
|||||||
@ -7,34 +7,16 @@
|
|||||||
# also defined, but not for general use are
|
# also defined, but not for general use are
|
||||||
# CARES_LIBRARY, where to find the c-ares library.
|
# CARES_LIBRARY, where to find the c-ares library.
|
||||||
|
|
||||||
find_path(CARES_INCLUDE_DIR ares.h
|
find_path(CARES_INCLUDE_DIR ares.h)
|
||||||
/usr/local/include
|
|
||||||
/usr/include
|
|
||||||
)
|
|
||||||
|
|
||||||
set(CARES_NAMES ${CARES_NAMES} cares)
|
set(CARES_NAMES ${CARES_NAMES} cares)
|
||||||
find_library(CARES_LIBRARY
|
find_library(CARES_LIBRARY
|
||||||
NAMES ${CARES_NAMES}
|
NAMES ${CARES_NAMES}
|
||||||
PATHS /usr/lib /usr/local/lib
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(CARES_LIBRARY AND CARES_INCLUDE_DIR)
|
include(FindPackageHandleStandardArgs)
|
||||||
set(CARES_LIBRARIES ${CARES_LIBRARY})
|
find_package_handle_standard_args(CARES
|
||||||
set(CARES_FOUND "YES")
|
REQUIRED_VARS CARES_LIBRARY CARES_INCLUDE_DIR)
|
||||||
else()
|
|
||||||
set(CARES_FOUND "NO")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(CARES_FOUND)
|
|
||||||
if(NOT CARES_FIND_QUIETLY)
|
|
||||||
message(STATUS "Found c-ares: ${CARES_LIBRARIES}")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
if(CARES_FIND_REQUIRED)
|
|
||||||
message(FATAL_ERROR "Could not find c-ares library")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
mark_as_advanced(
|
mark_as_advanced(
|
||||||
CARES_LIBRARY
|
CARES_LIBRARY
|
||||||
|
|||||||
@ -5,31 +5,18 @@
|
|||||||
# LIBSSH2_INCLUDE_DIR - the libssh2 include directory
|
# LIBSSH2_INCLUDE_DIR - the libssh2 include directory
|
||||||
# LIBSSH2_LIBRARY - the libssh2 library name
|
# LIBSSH2_LIBRARY - the libssh2 library name
|
||||||
|
|
||||||
if(LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY)
|
find_path(LIBSSH2_INCLUDE_DIR libssh2.h)
|
||||||
set(LibSSH2_FIND_QUIETLY TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
find_path(LIBSSH2_INCLUDE_DIR libssh2.h
|
find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
|
||||||
)
|
|
||||||
|
|
||||||
find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2
|
|
||||||
)
|
|
||||||
|
|
||||||
if(LIBSSH2_INCLUDE_DIR)
|
if(LIBSSH2_INCLUDE_DIR)
|
||||||
file(STRINGS "${LIBSSH2_INCLUDE_DIR}/libssh2.h" libssh2_version_str REGEX "^#define[\t ]+LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9][0-9][0-9][0-9][0-9].*")
|
file(STRINGS "${LIBSSH2_INCLUDE_DIR}/libssh2.h" libssh2_version_str REGEX "^#define[\t ]+LIBSSH2_VERSION[\t ]+\"(.*)\"")
|
||||||
|
string(REGEX REPLACE "^.*\"([^\"]+)\"" "\\1" LIBSSH2_VERSION "${libssh2_version_str}")
|
||||||
string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_MAJOR "${libssh2_version_str}")
|
|
||||||
string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9]([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_MINOR "${libssh2_version_str}")
|
|
||||||
string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9][0-9][0-9]([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_PATCH "${libssh2_version_str}")
|
|
||||||
|
|
||||||
string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_MAJOR "${LIBSSH2_VERSION_MAJOR}")
|
|
||||||
string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_MINOR "${LIBSSH2_VERSION_MINOR}")
|
|
||||||
string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_PATCH "${LIBSSH2_VERSION_PATCH}")
|
|
||||||
|
|
||||||
set(LIBSSH2_VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(LibSSH2 DEFAULT_MSG LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY )
|
find_package_handle_standard_args(LibSSH2
|
||||||
|
REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR
|
||||||
|
VERSION_VAR LIBSSH2_VERSION)
|
||||||
|
|
||||||
mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY LIBSSH2_VERSION_MAJOR LIBSSH2_VERSION_MINOR LIBSSH2_VERSION_PATCH LIBSSH2_VERSION)
|
mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
|
||||||
|
|||||||
@ -10,9 +10,9 @@ find_package_handle_standard_args(NGHTTP2
|
|||||||
REQUIRED_VARS
|
REQUIRED_VARS
|
||||||
NGHTTP2_LIBRARY
|
NGHTTP2_LIBRARY
|
||||||
NGHTTP2_INCLUDE_DIR
|
NGHTTP2_INCLUDE_DIR
|
||||||
FAIL_MESSAGE
|
|
||||||
"Could NOT find NGHTTP2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR})
|
set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR})
|
||||||
set(NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY})
|
set(NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY})
|
||||||
|
|
||||||
|
mark_as_advanced(NGHTTP2_INCLUDE_DIRS NGHTTP2_LIBRARIES)
|
||||||
|
|||||||
@ -10,6 +10,8 @@ set(NSS_LIBRARIES ${PC_NSS_LINK_LIBRARIES})
|
|||||||
set(NSS_INCLUDE_DIRS ${PC_NSS_INCLUDE_DIRS})
|
set(NSS_INCLUDE_DIRS ${PC_NSS_INCLUDE_DIRS})
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(NSS DEFAULT_MSG NSS_INCLUDE_DIRS NSS_LIBRARIES)
|
find_package_handle_standard_args(NSS
|
||||||
|
REQUIRED_VARS NSS_LIBRARIES NSS_INCLUDE_DIRS
|
||||||
|
VERSION_VAR PC_NSS_VERSION)
|
||||||
|
|
||||||
mark_as_advanced(NSS_INCLUDE_DIRS NSS_LIBRARIES)
|
mark_as_advanced(NSS_INCLUDE_DIRS NSS_LIBRARIES)
|
||||||
|
|||||||
@ -32,7 +32,7 @@ int main(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}" curl_cv_recv)
|
}" curl_cv_recv)
|
||||||
if(curl_cv_recv)
|
if(curl_cv_recv)
|
||||||
if(NOT DEFINED curl_cv_func_recv_args OR "${curl_cv_func_recv_args}" STREQUAL "unknown")
|
if(NOT DEFINED curl_cv_func_recv_args OR curl_cv_func_recv_args STREQUAL "unknown")
|
||||||
foreach(recv_retv "int" "ssize_t" )
|
foreach(recv_retv "int" "ssize_t" )
|
||||||
foreach(recv_arg1 "SOCKET" "int" )
|
foreach(recv_arg1 "SOCKET" "int" )
|
||||||
foreach(recv_arg2 "char *" "void *" )
|
foreach(recv_arg2 "char *" "void *" )
|
||||||
@ -81,7 +81,7 @@ if(curl_cv_recv)
|
|||||||
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" RECV_TYPE_RETV "${curl_cv_func_recv_args}")
|
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" RECV_TYPE_RETV "${curl_cv_func_recv_args}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if("${curl_cv_func_recv_args}" STREQUAL "unknown")
|
if(curl_cv_func_recv_args STREQUAL "unknown")
|
||||||
message(FATAL_ERROR "Cannot find proper types to use for recv args")
|
message(FATAL_ERROR "Cannot find proper types to use for recv args")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
|
|||||||
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
# Returns a list of arguments that evaluate to true
|
# Returns a list of arguments that evaluate to true
|
||||||
function(count_true output_count_var)
|
function(count_true output_count_var)
|
||||||
set(lst)
|
set(lst_len 0)
|
||||||
foreach(option_var IN LISTS ARGN)
|
foreach(option_var IN LISTS ARGN)
|
||||||
if(${option_var})
|
if(${option_var})
|
||||||
list(APPEND lst ${option_var})
|
math(EXPR lst_len "${lst_len} + 1")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
list(LENGTH lst lst_len)
|
|
||||||
set(${output_count_var} ${lst_len} PARENT_SCOPE)
|
set(${output_count_var} ${lst_len} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@ -38,7 +38,8 @@
|
|||||||
# To check:
|
# To check:
|
||||||
# (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
|
# (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
|
||||||
# (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options.
|
# (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options.
|
||||||
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.0...3.16 FATAL_ERROR)
|
||||||
|
|
||||||
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)
|
||||||
@ -49,7 +50,7 @@ project(CURL C)
|
|||||||
|
|
||||||
message(WARNING "the curl cmake build system is poorly maintained. Be aware")
|
message(WARNING "the curl cmake build system is poorly maintained. Be aware")
|
||||||
|
|
||||||
file(READ ${CURL_SOURCE_DIR}/include/curl/curlver.h 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 \"[^\"]*"
|
string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
|
||||||
CURL_VERSION ${CURL_VERSION_H_CONTENTS})
|
CURL_VERSION ${CURL_VERSION_H_CONTENTS})
|
||||||
string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
|
string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
|
||||||
@ -104,8 +105,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
|
|||||||
foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -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 -Wno-sign-conversion -Wvla -Wdouble-promotion -Wno-system-headers -Wno-pedantic-ms-format)
|
foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -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 -Wno-sign-conversion -Wvla -Wdouble-promotion -Wno-system-headers -Wno-pedantic-ms-format)
|
||||||
# surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
|
# surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
|
||||||
# test result in.
|
# test result in.
|
||||||
check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
|
string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
|
||||||
if(OPT${_CCOPT})
|
check_c_compiler_flag(${_CCOPT} ${_optvarname})
|
||||||
|
if(${_optvarname})
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
@ -134,7 +136,6 @@ if(ENABLE_ARES)
|
|||||||
set(USE_ARES 1)
|
set(USE_ARES 1)
|
||||||
find_package(CARES REQUIRED)
|
find_package(CARES REQUIRED)
|
||||||
list(APPEND CURL_LIBS ${CARES_LIBRARY})
|
list(APPEND CURL_LIBS ${CARES_LIBRARY})
|
||||||
set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CurlSymbolHiding)
|
include(CurlSymbolHiding)
|
||||||
@ -1229,12 +1230,12 @@ endif()
|
|||||||
|
|
||||||
# Helper to populate a list (_items) with a label when conditions (the remaining
|
# Helper to populate a list (_items) with a label when conditions (the remaining
|
||||||
# args) are satisfied
|
# args) are satisfied
|
||||||
function(_add_if label)
|
macro(_add_if label)
|
||||||
# TODO need to disable policy CMP0054 (CMake 3.1) to allow this indirection
|
# needs to be a macro to allow this indirection
|
||||||
if(${ARGN})
|
if(${ARGN})
|
||||||
set(_items ${_items} "${label}" PARENT_SCOPE)
|
set(_items ${_items} "${label}")
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endmacro()
|
||||||
|
|
||||||
# Clear list and try to detect available features
|
# Clear list and try to detect available features
|
||||||
set(_items)
|
set(_items)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user