Skip to content

Commit ef10e25

Browse files
committed
In the CMake build, do not use deprecated OpenSSL API. This fixes the
"static function not used" warnings in ssl_buckets. * CMakeLists.txt: Define OPENSSL_NO_DEPRECATED and OPENSSL_NO_STDIO before running the feature checks. * build/SerfChecks.cmake: Use the current compile definitions to restrict the OpenSSL API in the checks. Currently this means no locking callbacks and no explicit library initialization with OpenSSL 3. * test/MockHTTPinC/CMakeLists.txt: MockHTTP needs the deprecated APIs. This is a bit of a hack, but works for now. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1926875 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1719c58 commit ef10e25

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ find_package(ZLIB REQUIRED)
241241
find_package(APR REQUIRED)
242242
find_package(APRUtil REQUIRED)
243243

244+
# We do not want or need OpenSSL's compatibility macros.
245+
add_compile_definitions("OPENSSL_NO_DEPRECATED")
246+
247+
# Hide OpenSSL's _fp() API.
248+
add_compile_definitions("OPENSSL_NO_STDIO")
249+
244250
# Find optional dependencies
245251
find_package(Brotli)
246252
if(NOT SERF_WINDOWS)
@@ -344,9 +350,6 @@ if(ENABLE_SLOW_TESTS)
344350
add_compile_definitions("SERF_TEST_DEFLATE_4GBPLUS_BUCKETS")
345351
endif()
346352

347-
# Define OPENSSL_NO_STDIO to prevent using _fp() API.
348-
add_compile_definitions("OPENSSL_NO_STDIO")
349-
350353
# Set common compiler flags
351354
if(NOT MSVC)
352355
if(CC_LIKE_GNUC)

build/SerfChecks.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ include(CheckCSourceCompiles)
2121
include(CheckIncludeFile)
2222
include(CheckTypeSize)
2323

24+
25+
# CMake doesn't use current directory properties in the compile checks.
26+
get_directory_property(cdef_ COMPILE_DEFINITIONS)
27+
list(TRANSFORM cdef_ PREPEND "-D")
28+
2429
function(_CheckFunction var_ name_ args_ header_ includes_ libraries_)
30+
set(CMAKE_REQUIRED_DEFINITIONS ${cdef_})
2531
if(libraries_)
2632
set(CMAKE_REQUIRED_LIBRARIES "${libraries_}")
2733
else()
@@ -61,6 +67,7 @@ function(_CheckFunction var_ name_ args_ header_ includes_ libraries_)
6167

6268
unset(CMAKE_REQUIRED_INCLUDES)
6369
unset(CMAKE_REQUIRED_LIBRARIES)
70+
unset(CMAKE_REQUIRED_DEFINITIONS)
6471
endfunction(_CheckFunction)
6572

6673
macro(CheckFunction name_ args_ symbol_ header_ includes_)
@@ -81,6 +88,7 @@ endmacro(CheckNotFunction)
8188

8289

8390
function(_CheckHeader var_ name_ includes_)
91+
set(CMAKE_REQUIRED_DEFINITIONS ${cdef_})
8492
if(includes_)
8593
set(CMAKE_REQUIRED_INCLUDES "${includes_}")
8694
else()
@@ -94,6 +102,7 @@ function(_CheckHeader var_ name_ includes_)
94102
set("${var_}" FALSE PARENT_SCOPE)
95103
endif()
96104
unset(CMAKE_REQUIRED_INCLUDES)
105+
unset(CMAKE_REQUIRED_DEFINITIONS)
97106
endfunction(_CheckHeader)
98107

99108
macro(CheckHeader name_ symbol_)
@@ -105,6 +114,7 @@ endmacro(CheckHeader)
105114

106115

107116
function(_CheckType var_ name_ header_ includes_)
117+
set(CMAKE_REQUIRED_DEFINITIONS ${cdef_})
108118
if(includes_)
109119
set(CMAKE_REQUIRED_INCLUDES "${includes_}")
110120
else()
@@ -125,6 +135,7 @@ function(_CheckType var_ name_ header_ includes_)
125135
endif()
126136
unset(CMAKE_REQUIRED_INCLUDES)
127137
unset(CMAKE_EXTRA_INCLUDE_FILES)
138+
unset(CMAKE_REQUIRED_DEFINITIONS)
128139
endfunction(_CheckType)
129140

130141
macro(CheckType name_ header_ symbol_)

test/MockHTTPinC/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ elseif(MSVC)
4646
endif()
4747
mark_as_advanced(SHOW_MockHTTPinC_WARNINGS)
4848

49+
# MockHTTP needs deprecated OpenSSL APIs
50+
get_directory_property(_cdef COMPILE_DEFINITIONS)
51+
list(REMOVE_ITEM _cdef "OPENSSL_NO_DEPRECATED")
52+
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${_cdef}")
53+
4954
add_library(mockhttpinc STATIC ${MockHTTPinC_SOURCES})
5055
target_compile_definitions(mockhttpinc PUBLIC "MOCKHTTP_OPENSSL")
5156
target_include_directories(mockhttpinc SYSTEM BEFORE

0 commit comments

Comments
 (0)