Author: brane Date: Mon Jun 30 23:14:02 2025 New Revision: 1926877 URL: http://svn.apache.org/viewvc?rev=1926877&view=rev Log: 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. Modified: serf/trunk/CMakeLists.txt serf/trunk/test/CMakeLists.txt serf/trunk/test/MockHTTPinC/CMakeLists.txt Modified: serf/trunk/CMakeLists.txt URL: http://svn.apache.org/viewvc/serf/trunk/CMakeLists.txt?rev=1926877&r1=1926876&r2=1926877&view=diff ============================================================================== --- serf/trunk/CMakeLists.txt (original) +++ serf/trunk/CMakeLists.txt Mon Jun 30 23:14:02 2025 @@ -356,32 +356,32 @@ set(CMAKE_C_STANDARD_REQUIRED TRUE) if(NOT MSVC) if(CC_LIKE_GNUC) - string(APPEND CMAKE_C_FLAGS " -Wall") - string(APPEND CMAKE_C_FLAGS " -Wdeclaration-after-statement") - string(APPEND CMAKE_C_FLAGS " -Wmissing-prototypes") + list(APPEND SERF_C_WARNINGS "-Wall") + list(APPEND SERF_C_WARNINGS "-Wdeclaration-after-statement") + list(APPEND SERF_C_WARNINGS "-Wmissing-prototypes") string(APPEND CMAKE_C_FLAGS_DEBUG " -O0") if(SERF_MAINTAINER_MODE) # Additional warning flags for more pedantic checks - string(APPEND CMAKE_C_FLAGS " -Wimplicit-function-declaration") - string(APPEND CMAKE_C_FLAGS " -Wmissing-variable-declarations") - string(APPEND CMAKE_C_FLAGS " -Wunreachable-code") - string(APPEND CMAKE_C_FLAGS " -Wshorten-64-to-32") - string(APPEND CMAKE_C_FLAGS " -Wno-system-headers") - string(APPEND CMAKE_C_FLAGS " -Wextra-tokens") - string(APPEND CMAKE_C_FLAGS " -Wnewline-eof") + list(APPEND SERF_C_WARNINGS "-Wimplicit-function-declaration") + list(APPEND SERF_C_WARNINGS "-Wmissing-variable-declarations") + list(APPEND SERF_C_WARNINGS "-Wunreachable-code") + list(APPEND SERF_C_WARNINGS "-Wshorten-64-to-32") + list(APPEND SERF_C_WARNINGS "-Wno-system-headers") + list(APPEND SERF_C_WARNINGS "-Wextra-tokens") + list(APPEND SERF_C_WARNINGS "-Wnewline-eof") endif() endif() else() # Warning level 4, no unused argument warnings - string(APPEND CMAKE_C_FLAGS " /W4 /wd4100") + list(APPEND SERF_C_WARNINGS "/W4" "/wd4100") # Conditional expression is constant - string(APPEND CMAKE_C_FLAGS " /wd4127") + list(APPEND SERF_C_WARNINGS "/wd4127") # Assignment within conditional expression - string(APPEND CMAKE_C_FLAGS " /wd4706") + list(APPEND SERF_C_WARNINGS "/wd4706") # 'function' undefined; assuming extern returning int - string(APPEND CMAKE_C_FLAGS " /we4013") + list(APPEND SERF_C_WARNINGS "/we4013") add_compile_definitions( "WIN32" "WIN32_LEAN_AND_MEAN" @@ -400,7 +400,9 @@ endif(NOT MSVC) # Define all targets if(NOT SKIP_SHARED) add_library(serf_shared SHARED ${SOURCES} ${SHARED_SOURCES}) - target_compile_options(serf_shared PUBLIC ${APR_CFLAGS}) + target_compile_options(serf_shared + PUBLIC ${APR_CFLAGS} + PRIVATE ${SERF_C_WARNINGS}) target_include_directories(serf_shared PUBLIC ${SERF_SOURCE_DIR}) target_link_libraries(serf_shared PRIVATE ${SERF_PRIVATE_TARGETS} @@ -431,7 +433,9 @@ endif() if(NOT SKIP_STATIC) add_library(serf_static STATIC ${SOURCES}) - target_compile_options(serf_static PUBLIC ${APR_CFLAGS}) + target_compile_options(serf_static + PUBLIC ${APR_CFLAGS} + PRIVATE ${SERF_C_WARNINGS}) target_include_directories(serf_static PUBLIC ${SERF_SOURCE_DIR}) target_link_libraries(serf_static ${SERF_PRIVATE_TARGETS} Modified: serf/trunk/test/CMakeLists.txt URL: http://svn.apache.org/viewvc/serf/trunk/test/CMakeLists.txt?rev=1926877&r1=1926876&r2=1926877&view=diff ============================================================================== --- serf/trunk/test/CMakeLists.txt (original) +++ serf/trunk/test/CMakeLists.txt Mon Jun 30 23:14:02 2025 @@ -54,11 +54,13 @@ set(SIMPLE_TEST_TARGETS foreach(TEST_TARGET ${SIMPLE_TEST_TARGETS}) add_executable(${TEST_TARGET} "${TEST_TARGET}.c") add_dependencies(${TEST_TARGET} serf_static) + target_compile_options(${TEST_TARGET} PRIVATE ${SERF_C_WARNINGS}) target_link_libraries(${TEST_TARGET} serf_static) endforeach() add_executable(test_all ${TEST_ALL_SOURCES}) add_dependencies(test_all serf_static mockhttpinc) +target_compile_options(test_all PRIVATE ${SERF_C_WARNINGS}) target_include_directories(test_all SYSTEM BEFORE PRIVATE ${SERF_DEPENDENCY_INCLUDES}) target_link_libraries(test_all serf_static mockhttpinc) Modified: serf/trunk/test/MockHTTPinC/CMakeLists.txt URL: http://svn.apache.org/viewvc/serf/trunk/test/MockHTTPinC/CMakeLists.txt?rev=1926877&r1=1926876&r2=1926877&view=diff ============================================================================== --- serf/trunk/test/MockHTTPinC/CMakeLists.txt (original) +++ serf/trunk/test/MockHTTPinC/CMakeLists.txt Mon Jun 30 23:14:02 2025 @@ -27,24 +27,21 @@ set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED TRUE) # Update compiler options for this library. -if(CC_LIKE_GNUC) - # Also silence all warnings. - if(NOT SHOW_MockHTTPinC_WARNINGS) - string(REGEX REPLACE " *-W[a-z][a-z-]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) - string(APPEND CMAKE_C_FLAGS " -w") - endif() -elseif(MSVC) - # Silence warnings from Microsoft's compiler... - # - # ... of course, somewhere, somehow CMake adds the /W1 warning option - # to the command line and then MSVC complains that we're overriding /W1 - # with /w. But it's more fun this way, or at least more #$@^&@%! - # Or maybe that's just MSBuild doing its magic, and it depends on the - # build generator. What would life be without its little mysteries? - if(NOT SHOW_MockHTTPinC_WARNINGS) - string(REGEX REPLACE " */(W|w[de])[0-9]+" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) - string(APPEND CMAKE_C_FLAGS " /w") +if(NOT SHOW_MockHTTPinC_WARNINGS) + if(CC_LIKE_GNUC) + set(MockHTTPinC_WARNINGS "-w") + elseif(MSVC) + # Silence warnings from Microsoft's compiler... + # + # ... of course, somewhere, somehow CMake adds the /W1 warning option + # to the command line and then MSVC complains that we're overriding /W1 + # with /w. But it's more fun this way, or at least more #$@^&@%! + # Or maybe that's just MSBuild doing its magic, and it depends on the + # build generator. What would life be without its little mysteries? + set(MockHTTPinC_WARNINGS "/w") endif() +else() + set(MockHTTPinC_WARNINGS ${SERF_C_WARNINGS}) endif() mark_as_advanced(SHOW_MockHTTPinC_WARNINGS) @@ -54,6 +51,7 @@ list(REMOVE_ITEM _cdef "OPENSSL_NO_DEPRE set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${_cdef}") add_library(mockhttpinc STATIC ${MockHTTPinC_SOURCES}) +target_compile_options(mockhttpinc PRIVATE ${MockHTTPinC_WARNINGS}) target_compile_definitions(mockhttpinc PUBLIC "MOCKHTTP_OPENSSL") target_include_directories(mockhttpinc SYSTEM BEFORE PRIVATE ${APR_INCLUDES} ${APRUTIL_INCLUDES})