Skip to content

Commit 67c88b5

Browse files
committed
On the SERF-195 branch: sync with trunk r1926882.
git-svn-id: https://svn.apache.org/repos/asf/serf/branches/SERF-195@1926883 13f79535-47bb-0310-9956-ffa450edef68
2 parents 8beae36 + 5aa95c5 commit 67c88b5

File tree

5 files changed

+202
-65
lines changed

5 files changed

+202
-65
lines changed

CMakeLists.txt

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ if(SERF_WINDOWS)
222222
"secur32.lib"
223223
"ws2_32.lib"
224224
)
225-
add_compile_definitions("SERF_HAVE_SSPI")
225+
list(APPEND SERF_C_DEFINES "SERF_HAVE_SSPI")
226226
endif()
227227

228228
# Process build options for dependency search
@@ -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+
list(APPEND SERF_C_DEFINES "OPENSSL_NO_DEPRECATED")
246+
247+
# Hide OpenSSL's _fp() API.
248+
list(APPEND SERF_C_DEFINES "OPENSSL_NO_STDIO")
249+
244250
# Find optional dependencies
245251
find_package(Brotli)
246252
if(NOT SERF_WINDOWS)
@@ -259,7 +265,7 @@ if(Brotli_FOUND)
259265
list(APPEND SERF_PRIVATE_TARGETS Brotli::Decode)
260266
endif()
261267
if(GSSAPI_FOUND)
262-
add_compile_definitions("SERF_HAVE_GSSAPI")
268+
list(APPEND SERF_C_DEFINES "SERF_HAVE_GSSAPI")
263269
list(APPEND SERF_PRIVATE_TARGETS KRB5::GSSAPI)
264270
endif()
265271

@@ -319,8 +325,7 @@ CheckType("OSSL_HANDSHAKE_STATE" "openssl/ssl.h" "SERF_HAVE_OSSL_HANDSHAKE_STATE
319325
if(Brotli_FOUND)
320326
CheckType("BrotliDecoderResult" "brotli/decode.h" "SERF_HAVE_BROTLI_DECODER_RESULT" ${BROTLI_INCLUDES})
321327
# Check for the function only if the type check succeeded.
322-
get_directory_property(_cdef COMPILE_DEFINITIONS)
323-
if("SERF_HAVE_BROTLI_DECODER_RESULT" IN_LIST _cdef)
328+
if("SERF_HAVE_BROTLI_DECODER_RESULT" IN_LIST SERF_C_DEFINES)
324329
CheckFunction("BrotliDecoderTakeOutput" "NULL, NULL" "SERF_HAVE_BROTLI"
325330
"brotli/decode.h" ${BROTLI_INCLUDES}
326331
Brotli::Decode ${SERF_STANDARD_LIBRARIES})
@@ -333,59 +338,59 @@ endif()
333338

334339
# Process other build options
335340
if(DEBUG)
336-
add_compile_definitions("DEBUG" "_DEBUG")
341+
list(APPEND SERF_C_DEFINES "DEBUG" "_DEBUG")
337342
endif()
338343

339344
if(DISABLE_LOGGING)
340-
add_compile_definitions("SERF_DISABLE_LOGGING")
345+
list(APPEND SERF_C_DEFINES "SERF_DISABLE_LOGGING")
341346
endif()
342347

343348
if(ENABLE_SLOW_TESTS)
344-
add_compile_definitions("SERF_TEST_DEFLATE_4GBPLUS_BUCKETS")
349+
list(APPEND SERF_C_DEFINES "SERF_TEST_DEFLATE_4GBPLUS_BUCKETS")
345350
endif()
346351

347-
# Define OPENSSL_NO_STDIO to prevent using _fp() API.
348-
add_compile_definitions("OPENSSL_NO_STDIO")
349-
350352
# Set common compiler flags
353+
set(CMAKE_C_STANDARD 90) # Use C90. MockHTTP overrides this.
354+
set(CMAKE_C_EXTENSIONS OFF)
355+
set(CMAKE_C_STANDARD_REQUIRED TRUE)
356+
351357
if(NOT MSVC)
352358
if(CC_LIKE_GNUC)
353-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
354-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdeclaration-after-statement")
355-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes")
356-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89")
359+
list(APPEND SERF_C_WARNINGS "-Wall")
360+
list(APPEND SERF_C_WARNINGS "-Wdeclaration-after-statement")
361+
list(APPEND SERF_C_WARNINGS "-Wmissing-prototypes")
357362

358-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
363+
string(APPEND CMAKE_C_FLAGS_DEBUG " -O0")
359364

360365
if(SERF_MAINTAINER_MODE)
361366
# Additional warning flags for more pedantic checks
362-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wimplicit-function-declaration")
363-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-variable-declarations")
364-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunreachable-code")
365-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshorten-64-to-32")
366-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-system-headers")
367-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra-tokens")
368-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wnewline-eof")
367+
list(APPEND SERF_C_WARNINGS "-Wimplicit-function-declaration")
368+
list(APPEND SERF_C_WARNINGS "-Wmissing-variable-declarations")
369+
list(APPEND SERF_C_WARNINGS "-Wunreachable-code")
370+
list(APPEND SERF_C_WARNINGS "-Wshorten-64-to-32")
371+
list(APPEND SERF_C_WARNINGS "-Wno-system-headers")
372+
list(APPEND SERF_C_WARNINGS "-Wextra-tokens")
373+
list(APPEND SERF_C_WARNINGS "-Wnewline-eof")
369374
endif()
370375
endif()
371376
else()
372377
# Warning level 4, no unused argument warnings
373-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /wd4100")
378+
list(APPEND SERF_C_WARNINGS "/W4" "/wd4100")
374379
# Conditional expression is constant
375-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
380+
list(APPEND SERF_C_WARNINGS "/wd4127")
376381
# Assignment within conditional expression
377-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706")
382+
list(APPEND SERF_C_WARNINGS "/wd4706")
378383
# 'function' undefined; assuming extern returning int
379-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4013")
384+
list(APPEND SERF_C_WARNINGS "/we4013")
380385

381-
add_compile_definitions(
386+
list(APPEND SERF_C_DEFINES
382387
"WIN32" "WIN32_LEAN_AND_MEAN"
383388
"NOUSER" "NOGDI" "NONLS" "NOCRYPT"
384389
"_CRT_SECURE_NO_WARNINGS"
385390
"_CRT_NONSTDC_NO_WARNINGS"
386391
)
387392
if(SERF_WIN64)
388-
add_compile_definitions("WIN64")
393+
list(APPEND SERF_C_DEFINES "WIN64")
389394
endif()
390395

391396
set(CMAKE_IMPORT_LIBRARY_PREFIX "${SERF_INSTALL_LIBRARIES}")
@@ -395,7 +400,10 @@ endif(NOT MSVC)
395400
# Define all targets
396401
if(NOT SKIP_SHARED)
397402
add_library(serf_shared SHARED ${SOURCES} ${SHARED_SOURCES})
398-
target_compile_options(serf_shared PUBLIC ${APR_CFLAGS})
403+
target_compile_options(serf_shared
404+
PUBLIC ${APR_CFLAGS}
405+
PRIVATE ${SERF_C_WARNINGS})
406+
target_compile_definitions(serf_shared PRIVATE ${SERF_C_DEFINES})
399407
target_include_directories(serf_shared PUBLIC ${SERF_SOURCE_DIR})
400408
target_link_libraries(serf_shared
401409
PRIVATE ${SERF_PRIVATE_TARGETS}
@@ -426,7 +434,10 @@ endif()
426434

427435
if(NOT SKIP_STATIC)
428436
add_library(serf_static STATIC ${SOURCES})
429-
target_compile_options(serf_static PUBLIC ${APR_CFLAGS})
437+
target_compile_options(serf_static
438+
PUBLIC ${APR_CFLAGS}
439+
PRIVATE ${SERF_C_WARNINGS})
440+
target_compile_definitions(serf_static PRIVATE ${SERF_C_DEFINES})
430441
target_include_directories(serf_static PUBLIC ${SERF_SOURCE_DIR})
431442
target_link_libraries(serf_static
432443
${SERF_PRIVATE_TARGETS}
@@ -520,14 +531,13 @@ if(DOT_CLANGD)
520531
set(_gen_dot_clangd ON)
521532
endif()
522533

523-
get_directory_property(_cdef COMPILE_DEFINITIONS)
524-
if("SERF_HAVE_BROTLI" IN_LIST _cdef)
534+
if("SERF_HAVE_BROTLI" IN_LIST SERF_C_DEFINES)
525535
set(_have_brotli ON)
526536
endif()
527-
if("SERF_HAVE_GSSAPI" IN_LIST _cdef)
537+
if("SERF_HAVE_GSSAPI" IN_LIST SERF_C_DEFINES)
528538
set(_have_gssapi ON)
529539
endif()
530-
if("SERF_HAVE_SSPI" IN_LIST _cdef)
540+
if("SERF_HAVE_SSPI" IN_LIST SERF_C_DEFINES)
531541
set(_have_sspi ON)
532542
endif()
533543

README

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,42 @@ Fetch the scons-local package:
3737

3838
To build serf:
3939

40-
$ scons APR=/path/to/apr APU=/path/to/apu OPENSSL=/openssl/base PREFIX=/path/to/prefix
40+
$ scons PREFIX=/path/to/prefix \
41+
APR=/path/to/apr APU=/path/to/apr-util \
42+
OPENSSL=/path/to/openssl ZLIB=/path/to/zlib \
43+
BROTLI=/path/to/brotli GSSAPI=/path/to/kerberos
4144

4245
The switches are recorded into .saved_config, so they only need to be
4346
specified the first time scons is run.
4447

4548
PREFIX should specify where serf should be installed. PREFIX defaults to
4649
/usr/local.
4750

48-
The default for the other three switches (APR, APU, OPENSSL) is /usr.
51+
The default for the mandatory dependencies (APR, APU, OPENSSL, ZLIB) is /usr.
4952

5053
The build system looks for apr-1-config at $APR/bin/apr-1-config, or
5154
the path should indicate apr-1-config itself. Similarly for the path
52-
to apu-1-config.
55+
to apu-1-config in $APU or $APU/bin/apu-1-config.
56+
57+
OPENSSL should specify the root of the install (e.g., /opt/local). The
58+
includes will be found $OPENSSL/include/openssl and libraries at $OPENSSL/lib.
59+
60+
OPENSSL should specify the root of the install. The includes will be found
61+
$ZLIB/include and libraries at $ZLIB/lib.
62+
63+
The BROTLI and GSSAPI dependencies are optional.
64+
65+
BROTLI should be the path to the installation of the Brotli compression
66+
library; for example, BROTLI=/usr/local. The includes will be found
67+
in $BROTLI/include/brotli and the libraries in $BROTLI/lib.
68+
69+
GSSAPI should be the path to the installation of a package that provides
70+
the GSSAPI implementation such as Kerberos5 or Heimdal. SCons will look
71+
for the configuration program $GSSAPI/bin/krb5-config.
72+
73+
NOTE: Do not use the GSSAPI switch on Windows; it provides the SSPI API
74+
which Serf uses by default on that platform.
5375

54-
OPENSSL should specify the root of the install (eg. /opt/local). The
55-
includes will be found OPENSSL/include and libraries at OPENSSL/lib.
5676

5777
If you wish to use VPATH-style builds (where objects are created in a
5878
distinct directory from the source), you can use:
@@ -103,13 +123,17 @@ $ scons -c
103123

104124
Get the sources, either a release tarball or by checking out the
105125
official repository. The CMake build system currently only exists in
106-
/trunk and it will be included in the 1.4 release.
126+
trunk and it will be included in the 1.4 release.
107127

108128
The process for building on Unix and Windows is the same.
109129

110130
$ cmake -B out [build options]
111131
$ cmake --build out
112132

133+
or, with a multi-config generator:
134+
135+
$ cmake --build out --config Release
136+
113137
"out" in the commands above is the build directory used by CMake.
114138

115139
Build options can be added, for example:
@@ -120,7 +144,30 @@ Build options can be listed using:
120144

121145
$ cmake -LH
122146

123-
Windows tricks:
147+
By default, CMake will look for dependencies in ${CMAKE_SEARCH_PREFIX}, which
148+
you can override on the command line, e.g.::
149+
150+
$ cmake -DCMAKE_SEARCH_PREFIX=/opt
151+
152+
The search for each the five dependencies can be modified by setting their
153+
*_ROOT CMake variables:
154+
155+
$ cmake -DAPR_ROOR=/path/to/apr \
156+
-DAPRUtil_ROOT=/path/to/apr-util \
157+
-DOPENSSL_ROOT_DIR=/path/to/openssl \
158+
-DZLIB_ROOT=/path/to/zlib \
159+
-DBrotli_ROOT=/path/to/brotli \
160+
-DGSSAPI_ROOT=/path/to/kerberos5
161+
162+
163+
1.2.2 MacOS specifics
164+
165+
The CMake build system can search for dependencies from Homebrew or
166+
MacPorts: use 'cmake -DUSE_HOMEBREW=ON' to search for Homebrew packages,
167+
or 'cmake -DUSE_MACPORTS=ON' to search installed MacPorts. Just not both.
168+
169+
170+
1.2.3 Windows tricks
124171

125172
- Modern versions of Microsoft Visual Studio provide support for
126173
CMake projects out-of-box, including intellisense, integrated
@@ -154,15 +201,33 @@ Windows tricks:
154201

155202
<VCPKG_ROOT>/scripts/buildsystems/vcpkg.cmake
156203

157-
1.2.1 Running the test suite
158204

159-
$ cd out
160-
$ ctest
161-
# this only seems to run part of the testsuite?
162-
$ ./test/test_all
163-
# fails due to missing certificates
164-
$ cp ../test/*.pem ../test/certs test/
165-
$ ./test/test_all
166-
# Succeeds?
205+
1.2.4 Running the test suite
206+
207+
To run the test suite, go to the CMake output directory, then:
208+
209+
$ ctest
210+
211+
or, with a multi-config generator:
212+
213+
$ ctest -C Release
214+
215+
This is equivalent to
216+
217+
$ cmake --build out --target test
218+
219+
or
220+
221+
$ cmake --build out --config Release --target test
222+
223+
(or, on Windows using the Visual Studio generator, which always has to be
224+
special and different for no discernible benefit:
225+
226+
$ cmake --build out --config Release --target run_tests
227+
)
228+
229+
230+
1.2.5 Installing Apache Serf
167231

168-
This should be described in detail.
232+
$ cmake --build out --target install
233+
$ cmake --build out --config Release --target install

build/SerfChecks.cmake

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

24+
list(TRANSFORM SERF_C_DEFINES PREPEND "-D" OUTPUT_VARIABLE cdef_)
25+
2426
function(_CheckFunction var_ name_ args_ header_ includes_ libraries_)
27+
set(CMAKE_REQUIRED_DEFINITIONS ${cdef_})
2528
if(libraries_)
2629
set(CMAKE_REQUIRED_LIBRARIES "${libraries_}")
2730
else()
@@ -61,26 +64,28 @@ function(_CheckFunction var_ name_ args_ header_ includes_ libraries_)
6164

6265
unset(CMAKE_REQUIRED_INCLUDES)
6366
unset(CMAKE_REQUIRED_LIBRARIES)
67+
unset(CMAKE_REQUIRED_DEFINITIONS)
6468
endfunction(_CheckFunction)
6569

6670
macro(CheckFunction name_ args_ symbol_ header_ includes_)
6771
_CheckFunction("serf_feature_CheckFunction_${name_}_"
6872
"${name_}" "${args_}" "${header_}" "${includes_}" "${ARGN}")
6973
if("${serf_feature_CheckFunction_${name_}_}")
70-
add_compile_definitions("${symbol_}")
74+
list(APPEND SERF_C_DEFINES "${symbol_}")
7175
endif()
7276
endmacro(CheckFunction)
7377

7478
macro(CheckNotFunction name_ args_ symbol_ header_ includes_)
7579
_CheckFunction("serf_feature_CheckNotFunction_${name_}_"
7680
"${name_}" "${args_}" "${header_}" "${includes_}" "${ARGN}")
7781
if(NOT "${serf_feature_CheckNotFunction_${name_}_}")
78-
add_compile_definitions("${symbol_}")
82+
list(APPEND SERF_C_DEFINES "${symbol_}")
7983
endif()
8084
endmacro(CheckNotFunction)
8185

8286

8387
function(_CheckHeader var_ name_ includes_)
88+
set(CMAKE_REQUIRED_DEFINITIONS ${cdef_})
8489
if(includes_)
8590
set(CMAKE_REQUIRED_INCLUDES "${includes_}")
8691
else()
@@ -94,17 +99,19 @@ function(_CheckHeader var_ name_ includes_)
9499
set("${var_}" FALSE PARENT_SCOPE)
95100
endif()
96101
unset(CMAKE_REQUIRED_INCLUDES)
102+
unset(CMAKE_REQUIRED_DEFINITIONS)
97103
endfunction(_CheckHeader)
98104

99105
macro(CheckHeader name_ symbol_)
100106
_CheckHeader("serf_feature_CheckHeader_${name_}_" "${name_}" "${ARGN}")
101107
if("${serf_feature_CheckHeader_${name_}_}")
102-
add_compile_definitions("${symbol_}")
108+
list(APPEND SERF_C_DEFINES "${symbol_}")
103109
endif()
104110
endmacro(CheckHeader)
105111

106112

107113
function(_CheckType var_ name_ header_ includes_)
114+
set(CMAKE_REQUIRED_DEFINITIONS ${cdef_})
108115
if(includes_)
109116
set(CMAKE_REQUIRED_INCLUDES "${includes_}")
110117
else()
@@ -125,11 +132,12 @@ function(_CheckType var_ name_ header_ includes_)
125132
endif()
126133
unset(CMAKE_REQUIRED_INCLUDES)
127134
unset(CMAKE_EXTRA_INCLUDE_FILES)
135+
unset(CMAKE_REQUIRED_DEFINITIONS)
128136
endfunction(_CheckType)
129137

130138
macro(CheckType name_ header_ symbol_)
131139
_CheckType("serf_feature_CheckType_${name_}_" "${name_}" "${header_}" "${ARGN}")
132140
if("${serf_feature_CheckType_${name_}_}")
133-
add_compile_definitions("${symbol_}")
141+
list(APPEND SERF_C_DEFINES "${symbol_}")
134142
endif()
135143
endmacro(CheckType)

0 commit comments

Comments
 (0)