Skip to content

Commit 58f11ba

Browse files
committed
In the CMake build, set warning flags per target to simplify manipulation.
* CMakeLists.txt (CMAKE_C_WARNINGS): New list for warning flags, move them here from the global CMAKE_C_FLAGS. (serf_shared, serf_static): Add CMAKE_C_WARNINGS to compile options. * test/CMakeLists.txt: Add CMAKE_C_WARNINGS to all compile options. * test/MockHTTPinC/CMakeLists.txt: Override warning flags for MockHTTPinC. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1926877 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4afba87 commit 58f11ba

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

CMakeLists.txt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -356,32 +356,32 @@ set(CMAKE_C_STANDARD_REQUIRED TRUE)
356356

357357
if(NOT MSVC)
358358
if(CC_LIKE_GNUC)
359-
string(APPEND CMAKE_C_FLAGS " -Wall")
360-
string(APPEND CMAKE_C_FLAGS " -Wdeclaration-after-statement")
361-
string(APPEND CMAKE_C_FLAGS " -Wmissing-prototypes")
359+
list(APPEND SERF_C_WARNINGS "-Wall")
360+
list(APPEND SERF_C_WARNINGS "-Wdeclaration-after-statement")
361+
list(APPEND SERF_C_WARNINGS "-Wmissing-prototypes")
362362

363363
string(APPEND CMAKE_C_FLAGS_DEBUG " -O0")
364364

365365
if(SERF_MAINTAINER_MODE)
366366
# Additional warning flags for more pedantic checks
367-
string(APPEND CMAKE_C_FLAGS " -Wimplicit-function-declaration")
368-
string(APPEND CMAKE_C_FLAGS " -Wmissing-variable-declarations")
369-
string(APPEND CMAKE_C_FLAGS " -Wunreachable-code")
370-
string(APPEND CMAKE_C_FLAGS " -Wshorten-64-to-32")
371-
string(APPEND CMAKE_C_FLAGS " -Wno-system-headers")
372-
string(APPEND CMAKE_C_FLAGS " -Wextra-tokens")
373-
string(APPEND 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")
374374
endif()
375375
endif()
376376
else()
377377
# Warning level 4, no unused argument warnings
378-
string(APPEND CMAKE_C_FLAGS " /W4 /wd4100")
378+
list(APPEND SERF_C_WARNINGS "/W4" "/wd4100")
379379
# Conditional expression is constant
380-
string(APPEND CMAKE_C_FLAGS " /wd4127")
380+
list(APPEND SERF_C_WARNINGS "/wd4127")
381381
# Assignment within conditional expression
382-
string(APPEND CMAKE_C_FLAGS " /wd4706")
382+
list(APPEND SERF_C_WARNINGS "/wd4706")
383383
# 'function' undefined; assuming extern returning int
384-
string(APPEND CMAKE_C_FLAGS " /we4013")
384+
list(APPEND SERF_C_WARNINGS "/we4013")
385385

386386
add_compile_definitions(
387387
"WIN32" "WIN32_LEAN_AND_MEAN"
@@ -400,7 +400,9 @@ endif(NOT MSVC)
400400
# Define all targets
401401
if(NOT SKIP_SHARED)
402402
add_library(serf_shared SHARED ${SOURCES} ${SHARED_SOURCES})
403-
target_compile_options(serf_shared PUBLIC ${APR_CFLAGS})
403+
target_compile_options(serf_shared
404+
PUBLIC ${APR_CFLAGS}
405+
PRIVATE ${SERF_C_WARNINGS})
404406
target_include_directories(serf_shared PUBLIC ${SERF_SOURCE_DIR})
405407
target_link_libraries(serf_shared
406408
PRIVATE ${SERF_PRIVATE_TARGETS}
@@ -431,7 +433,9 @@ endif()
431433

432434
if(NOT SKIP_STATIC)
433435
add_library(serf_static STATIC ${SOURCES})
434-
target_compile_options(serf_static PUBLIC ${APR_CFLAGS})
436+
target_compile_options(serf_static
437+
PUBLIC ${APR_CFLAGS}
438+
PRIVATE ${SERF_C_WARNINGS})
435439
target_include_directories(serf_static PUBLIC ${SERF_SOURCE_DIR})
436440
target_link_libraries(serf_static
437441
${SERF_PRIVATE_TARGETS}

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ set(SIMPLE_TEST_TARGETS
5454
foreach(TEST_TARGET ${SIMPLE_TEST_TARGETS})
5555
add_executable(${TEST_TARGET} "${TEST_TARGET}.c")
5656
add_dependencies(${TEST_TARGET} serf_static)
57+
target_compile_options(${TEST_TARGET} PRIVATE ${SERF_C_WARNINGS})
5758
target_link_libraries(${TEST_TARGET} serf_static)
5859
endforeach()
5960

6061
add_executable(test_all ${TEST_ALL_SOURCES})
6162
add_dependencies(test_all serf_static mockhttpinc)
63+
target_compile_options(test_all PRIVATE ${SERF_C_WARNINGS})
6264
target_include_directories(test_all SYSTEM BEFORE PRIVATE ${SERF_DEPENDENCY_INCLUDES})
6365
target_link_libraries(test_all serf_static mockhttpinc)
6466

test/MockHTTPinC/CMakeLists.txt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,21 @@ set(CMAKE_C_STANDARD 99)
2727
set(CMAKE_C_STANDARD_REQUIRED TRUE)
2828

2929
# Update compiler options for this library.
30-
if(CC_LIKE_GNUC)
31-
# Also silence all warnings.
32-
if(NOT SHOW_MockHTTPinC_WARNINGS)
33-
string(REGEX REPLACE " *-W[a-z][a-z-]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
34-
string(APPEND CMAKE_C_FLAGS " -w")
35-
endif()
36-
elseif(MSVC)
37-
# Silence warnings from Microsoft's compiler...
38-
#
39-
# ... of course, somewhere, somehow CMake adds the /W1 warning option
40-
# to the command line and then MSVC complains that we're overriding /W1
41-
# with /w. But it's more fun this way, or at least more #$@^&@%!
42-
# Or maybe that's just MSBuild doing its magic, and it depends on the
43-
# build generator. What would life be without its little mysteries?
44-
if(NOT SHOW_MockHTTPinC_WARNINGS)
45-
string(REGEX REPLACE " */(W|w[de])[0-9]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
46-
string(APPEND CMAKE_C_FLAGS " /w")
30+
if(NOT SHOW_MockHTTPinC_WARNINGS)
31+
if(CC_LIKE_GNUC)
32+
set(MockHTTPinC_WARNINGS "-w")
33+
elseif(MSVC)
34+
# Silence warnings from Microsoft's compiler...
35+
#
36+
# ... of course, somewhere, somehow CMake adds the /W1 warning option
37+
# to the command line and then MSVC complains that we're overriding /W1
38+
# with /w. But it's more fun this way, or at least more #$@^&@%!
39+
# Or maybe that's just MSBuild doing its magic, and it depends on the
40+
# build generator. What would life be without its little mysteries?
41+
set(MockHTTPinC_WARNINGS "/w")
4742
endif()
43+
else()
44+
set(MockHTTPinC_WARNINGS ${SERF_C_WARNINGS})
4845
endif()
4946
mark_as_advanced(SHOW_MockHTTPinC_WARNINGS)
5047

@@ -54,6 +51,7 @@ list(REMOVE_ITEM _cdef "OPENSSL_NO_DEPRECATED")
5451
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${_cdef}")
5552

5653
add_library(mockhttpinc STATIC ${MockHTTPinC_SOURCES})
54+
target_compile_options(mockhttpinc PRIVATE ${MockHTTPinC_WARNINGS})
5755
target_compile_definitions(mockhttpinc PUBLIC "MOCKHTTP_OPENSSL")
5856
target_include_directories(mockhttpinc SYSTEM BEFORE
5957
PRIVATE ${APR_INCLUDES} ${APRUTIL_INCLUDES})

0 commit comments

Comments
 (0)