@@ -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" )
226226endif ()
227227
228228# Process build options for dependency search
@@ -241,6 +241,12 @@ find_package(ZLIB REQUIRED)
241241find_package (APR REQUIRED)
242242find_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
245251find_package (Brotli)
246252if (NOT SERF_WINDOWS)
@@ -259,7 +265,7 @@ if(Brotli_FOUND)
259265 list (APPEND SERF_PRIVATE_TARGETS Brotli::Decode)
260266endif ()
261267if (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)
264270endif ()
265271
@@ -319,8 +325,7 @@ CheckType("OSSL_HANDSHAKE_STATE" "openssl/ssl.h" "SERF_HAVE_OSSL_HANDSHAKE_STATE
319325if (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
335340if (DEBUG)
336- add_compile_definitions ( "DEBUG" "_DEBUG" )
341+ list ( APPEND SERF_C_DEFINES "DEBUG" "_DEBUG" )
337342endif ()
338343
339344if (DISABLE_LOGGING)
340- add_compile_definitions ( "SERF_DISABLE_LOGGING" )
345+ list ( APPEND SERF_C_DEFINES "SERF_DISABLE_LOGGING" )
341346endif ()
342347
343348if (ENABLE_SLOW_TESTS)
344- add_compile_definitions ( "SERF_TEST_DEFLATE_4GBPLUS_BUCKETS" )
349+ list ( APPEND SERF_C_DEFINES "SERF_TEST_DEFLATE_4GBPLUS_BUCKETS" )
345350endif ()
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+
351357if (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 ()
371376else ()
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
396401if (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
427435if (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 )
521532endif ()
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 )
526536endif ()
527- if ("SERF_HAVE_GSSAPI" IN_LIST _cdef )
537+ if ("SERF_HAVE_GSSAPI" IN_LIST SERF_C_DEFINES )
528538 set (_have_gssapi ON )
529539endif ()
530- if ("SERF_HAVE_SSPI" IN_LIST _cdef )
540+ if ("SERF_HAVE_SSPI" IN_LIST SERF_C_DEFINES )
531541 set (_have_sspi ON )
532542endif ()
533543
0 commit comments