Commit 640382c7 authored by João Valverde's avatar João Valverde Committed by João Valverde

CMake: Allow setting per target compiler warnings

Setting our compiler warning flags in CMAKE_C_FLAGS does not allow
using different flags per target.

Allow for that possibility by setting the internal WS_WARNINGS_{C,CXX}_FLAGS
and using the COMPILE_OPTIONS property to set them.

This change is just setting mechanism and there should be no difference
in generated warnings.

The check_X_compiler_flag cmake test is changed to test each flag individually.
We need a list, not a space separated string, and the aggregate test is not
significant.

Change-Id: I59fc5cd7e130c7a5e001c598e3df3e13f83a6a25
Reviewed-on: https://code.wireshark.org/review/17150
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: default avatarPetri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: default avatarJoão Valverde <j@v6e.pt>
parent 505bcefd
......@@ -343,7 +343,20 @@ else()
endif()
endif()
set(WIRESHARK_COMMON_FLAGS
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
# avoid "argument unused during compilation" warnings
# (for example, when getting the -gsplit-dwarf option or
# when combining -fwrapv with -fno-strict-overflow)
-Qunused-arguments
)
else()
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
-fexcess-precision=fast
)
endif()
set(COMMON_WARN_FLAGS
# The following are for C and C++
# -O<X> and -g get set by the CMAKE_BUILD_TYPE
-Wall
......@@ -364,7 +377,7 @@ else()
-Wheader-guard
)
set(WIRESHARK_C_ONLY_FLAGS
set(C_WARN_FLAGS
# The following are C only, not C++
-Wc++-compat
-Wdeclaration-after-statement
......@@ -382,10 +395,10 @@ else()
-Wc99-extensions
)
set(WIRESHARK_CXX_ONLY_FLAGS
set(CXX_WARN_FLAGS
)
set(WIRESHARK_EXTRA_COMPILER_COMMON_FLAGS
set(COMMON_EXTRA_WARN_FLAGS
# The following are for C and C++
-Wpedantic
#
......@@ -440,7 +453,7 @@ else()
-fno-delete-null-pointer-checks
)
set(WIRESHARK_EXTRA_COMPILER_C_ONLY_FLAGS
set(C_EXTRA_WARN_FLAGS
# The following are C only, not C++
#
# Due to various places where APIs we don't control
......@@ -450,32 +463,13 @@ else()
-Wbad-function-cast
)
set(WIRESHARK_EXTRA_COMPILER_CXX_ONLY_FLAGS
set(CXX_EXTRA_WARN_FLAGS
)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
# avoid "argument unused during compilation" warnings
# (for example, when getting the -gsplit-dwarf option or
# when combining -fwrapv with -fno-strict-overflow)
-Qunused-arguments
)
set(WIRESHARK_CXX_ONLY_FLAGS ${WIRESHARK_CXX_ONLY_FLAGS}
)
else()
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
-fexcess-precision=fast
)
set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS}
)
endif()
if(ENABLE_EXTRA_COMPILER_WARNINGS) # This overrides -Werror
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_EXTRA_COMPILER_COMMON_FLAGS})
set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS} ${WIRESHARK_EXTRA_COMPILER_C_ONLY_FLAGS})
set(WIRESHARK_CXX_ONLY_FLAGS ${WIRESHARK_CXX_ONLY_FLAGS} ${WIRESHARK_EXTRA_COMPILER_CXX_ONLY_FLAGS})
set(COMMON_WARN_FLAGS ${COMMON_WARN_FLAGS} ${COMMON_EXTRA_WARN_FLAGS})
set(C_WARN_FLAGS ${C_WARN_FLAGS} ${C_EXTRA_WARN_FLAGS})
set(CXX_WARN_FLAGS ${CXX_WARN_FLAGS} ${CXX_EXTRA_WARN_FLAGS})
endif()
add_definitions(
......@@ -487,6 +481,9 @@ endif()
set( C_FLAG_TESTS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_C_ONLY_FLAGS} )
set( CXX_FLAG_TESTS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS} )
set( C_WARN_TESTS ${COMMON_WARN_FLAGS} ${C_WARN_FLAGS} )
set( CXX_WARN_TESTS ${COMMON_WARN_FLAGS} ${CXX_WARN_FLAGS} )
# Counterhack to work around some cache magic in CHECK_C_SOURCE_COMPILES
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
......@@ -526,6 +523,30 @@ foreach(THIS_FLAG ${CXX_FLAG_TESTS})
endforeach()
set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
foreach(THIS_FLAG ${C_WARN_TESTS})
string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
set(${F} ${THIS_FLAG})
set(V C_${F}_VALID)
message(STATUS "Checking for c-compiler flag: ${THIS_FLAG}")
check_c_compiler_flag("${C_FLAG_TESTS} ${${F}}" ${V})
if (${${V}})
set(ADDED_WARN_C_FLAGS ${ADDED_WARN_C_FLAGS} ${${F}})
endif()
endforeach()
set(WS_WARNINGS_C_FLAGS ${ADDED_WARN_C_FLAGS})
foreach(THIS_FLAG ${CXX_WARN_TESTS})
string( REGEX REPLACE "[^a-zA-Z0-9_]+" "_" F ${THIS_FLAG} )
set(${F} ${THIS_FLAG})
set(V CXX_${F}_VALID)
message(STATUS "Checking for c++-compiler flag: ${THIS_FLAG}")
check_cxx_compiler_flag("${CXX_FLAG_TESTS} ${${F}}" ${V})
if (${${V}})
set(ADDED_WARN_CXX_FLAGS ${ADDED_WARN_CXX_FLAGS} ${${F}})
endif()
endforeach()
set(WS_WARNINGS_CXX_FLAGS ${ADDED_WARN_CXX_FLAGS})
if(ENABLE_ASAN)
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
check_c_compiler_flag(-fsanitize=address C__fsanitize_address_VALID)
......@@ -1000,8 +1021,10 @@ if(ENABLE_CHECKHF_CONFLICT)
set(ENABLE_CHECK_FILTER 1)
endif()
message(STATUS "C-Flags: ${CMAKE_C_FLAGS}")
message(STATUS "CXX-Flags: ${CMAKE_CXX_FLAGS}")
string(REPLACE ";" " " _warnings_c_flags "${WS_WARNINGS_C_FLAGS}")
message(STATUS "C-Flags: ${CMAKE_C_FLAGS} ${_warnings_c_flags}")
string(REPLACE ";" " " _warnings_cxx_flags "${WS_WARNINGS_CXX_FLAGS}")
message(STATUS "CXX-Flags: ${CMAKE_CXX_FLAGS} ${_warnings_cxx_flags}")
message(STATUS "Warnings as errors: ${WERROR_COMMON_FLAGS}")
if(APPLE)
......@@ -1816,6 +1839,7 @@ if(BUILD_wireshark AND QT_FOUND)
add_executable(wireshark WIN32 MACOSX_BUNDLE wireshark-qt.cpp ${wireshark_FILES} ${EXTRA_BUNDLE_FILES})
add_dependencies(wireshark version)
set(PROGLIST ${PROGLIST} wireshark)
set_target_properties(wireshark PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_CXX_FLAGS}")
set_target_properties(wireshark PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(wireshark PROPERTIES FOLDER "Executables")
if(ENABLE_APPLICATION_BUNDLE OR WIN32)
......@@ -1894,6 +1918,7 @@ endif()
# Common properties for CLI executables
macro(set_extra_executable_properties _executable _folder)
set_target_properties(${_executable} PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER ${_folder}
)
......@@ -1921,6 +1946,7 @@ macro(set_extcap_executable_properties _executable)
if(WIN32)
set_target_properties(${_executable} PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/run/Debug/extcap
......@@ -1930,6 +1956,7 @@ macro(set_extcap_executable_properties _executable)
)
else()
set_target_properties(${_executable} PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
)
......@@ -1971,6 +1998,7 @@ if(BUILD_wireshark_gtk AND GTK_FOUND)
add_executable(wireshark-gtk WIN32 ${wireshark_FILES})
add_dependencies(wireshark-gtk version)
set(PROGLIST ${PROGLIST} wireshark-gtk)
set_target_properties(wireshark-gtk PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}")
set_target_properties(wireshark-gtk PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(wireshark-gtk PROPERTIES FOLDER "Executables")
target_link_libraries(wireshark-gtk ${wireshark_gtk_LIBS})
......
......@@ -45,6 +45,7 @@ add_library(capchild STATIC
)
set_target_properties(capchild PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "Libs")
......
......@@ -66,6 +66,7 @@ add_library(caputils STATIC
)
set_target_properties(caputils PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "Libs")
......
......@@ -33,6 +33,7 @@ macro(ADD_PLUGIN_LIBRARY _plugin)
set_target_properties(${_plugin} PROPERTIES
PREFIX ""
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "Plugins"
)
......
......@@ -61,6 +61,7 @@ set(FULL_SO_VERSION "0.0.0")
set_target_properties(wscodecs PROPERTIES
PREFIX "lib"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
VERSION ${FULL_SO_VERSION} SOVERSION 0
FOLDER "DLLs"
......
......@@ -55,6 +55,7 @@ add_library(echld ${LINK_MODE_LIB}
set(FULL_SO_VERSION "0.0.0")
set_target_properties(echld PROPERTIES COMPILE_DEFINITIONS "WS_BUILD_DLL")
set_target_properties(echld PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}")
set_target_properties(echld PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(echld PROPERTIES VERSION ${FULL_SO_VERSION} SOVERSION 0)
......
......@@ -245,6 +245,7 @@ add_dependencies(epan version)
set(FULL_SO_VERSION "0.0.0")
set_target_properties(epan PROPERTIES COMPILE_DEFINITIONS "WS_BUILD_DLL")
set_target_properties(epan PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}")
set_target_properties(epan PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(epan PROPERTIES VERSION ${FULL_SO_VERSION} SOVERSION 0)
......@@ -328,6 +329,7 @@ target_link_libraries(exntest ${GLIB2_LIBRARIES})
set_target_properties(exntest PROPERTIES
FOLDER "Tests"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
add_executable(oids_test EXCLUDE_FROM_ALL oids_test.c)
......@@ -335,6 +337,7 @@ target_link_libraries(oids_test epan ${ZLIB_LIBRARIES})
set_target_properties(oids_test PROPERTIES
FOLDER "Tests"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
add_executable(reassemble_test EXCLUDE_FROM_ALL reassemble_test.c)
......@@ -348,6 +351,7 @@ target_link_libraries(tvbtest epan)
set_target_properties(tvbtest PROPERTIES
FOLDER "Tests"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
CHECKAPI(
......
......@@ -50,6 +50,7 @@ add_library(crypt OBJECT
set_target_properties(crypt PROPERTIES
FOLDER "Libs/epan/crypt"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
CHECKAPI(
......
......@@ -67,6 +67,7 @@ add_library(dfilter OBJECT
set_target_properties(dfilter PROPERTIES
FOLDER "Libs/epan/dfilter"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
CHECKAPI(
......
......@@ -189,6 +189,7 @@ add_library(dissectors-corba OBJECT
set_target_properties(dissectors-corba PROPERTIES
FOLDER "Libs/epan/dissectors"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
if(WIN32 AND "${CMAKE_GENERATOR}" STREQUAL "Visual Studio 12 2013 Win64")
......@@ -1454,6 +1455,7 @@ add_library(dissectors OBJECT
set_target_properties(dissectors PROPERTIES
FOLDER "Libs/epan/dissectors"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
set(CHECKAPI_FILE_LIST "${CMAKE_CURRENT_BINARY_DIR}/files.txt")
......
......@@ -56,6 +56,7 @@ add_library(ftypes OBJECT
set_target_properties(ftypes PROPERTIES
FOLDER "Libs/epan/ftypes"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
CHECKAPI(
......
......@@ -50,6 +50,7 @@ add_library(nghttp2 OBJECT
set_target_properties(nghttp2 PROPERTIES
FOLDER "Libs/epan/nghttp2"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
#
......
......@@ -59,6 +59,7 @@ add_library(wmem OBJECT
set_target_properties(wmem PROPERTIES
FOLDER "Libs/epan/wmem"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
add_executable(wmem_test EXCLUDE_FROM_ALL wmem_test.c $<TARGET_OBJECTS:wmem>)
......@@ -68,6 +69,7 @@ target_link_libraries(wmem_test ${GLIB2_LIBRARIES} wsutil)
set_target_properties(wmem_test PROPERTIES
FOLDER "Tests"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
CHECKAPI(
......
......@@ -164,6 +164,7 @@ add_library(wslua OBJECT
set_target_properties(wslua PROPERTIES
FOLDER "Libs/epan/wslua"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
)
CHECKAPI(
......
......@@ -3339,7 +3339,7 @@ match_regex(capture_file *cf, frame_data *fdata, void *criterion _U_)
return MR_ERROR;
}
if (g_regex_match_full(cf->regex, ws_buffer_start_ptr(&cf->buf), fdata->cap_len,
if (g_regex_match_full(cf->regex, (const gchar *)ws_buffer_start_ptr(&cf->buf), fdata->cap_len,
0, (GRegexMatchFlags) 0, &match_info, NULL))
{
gint start_pos = 0, end_pos = 0;
......@@ -4024,7 +4024,7 @@ cf_set_frame_edited(capture_file *cf, frame_data *fd,
modified_frame_data *mfd = (modified_frame_data *)g_malloc(sizeof(modified_frame_data));
mfd->phdr = *phdr;
mfd->pd = pd;
mfd->pd = (char *)pd;
if (cf->edited_frames == NULL)
cf->edited_frames = g_tree_new_full(g_direct_compare_func, NULL, NULL,
......
......@@ -43,6 +43,7 @@ add_library(randpkt_core STATIC
)
set_target_properties(randpkt_core PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "Libs")
......
......@@ -41,5 +41,6 @@ set(lemon_LIBS
add_executable(lemon ${lemon_FILES})
set_target_properties(lemon PROPERTIES FOLDER "tools")
set_target_properties(lemon PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}")
target_link_libraries(lemon ${lemon_LIBS})
......@@ -94,6 +94,7 @@ add_library(ui STATIC
${GENERATED_FILES}
)
set_target_properties(ui PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}")
set_target_properties(ui PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(ui PROPERTIES FOLDER "UI")
......
......@@ -318,6 +318,7 @@ add_library(gtkui STATIC
${PIXBUF_SRC}
)
set_target_properties(gtkui PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "UI")
......
......@@ -530,6 +530,7 @@ add_library(qtui STATIC
wireshark-tap-register.c
)
add_dependencies(qtui translations)
set_target_properties(qtui PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_CXX_FLAGS}")
set_target_properties(qtui PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(qtui PROPERTIES FOLDER "UI")
......
......@@ -121,6 +121,7 @@ set(FULL_SO_VERSION "0.0.0")
set_target_properties(wiretap PROPERTIES
PREFIX "lib"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
VERSION ${FULL_SO_VERSION} SOVERSION 0
FOLDER "DLLs"
......
......@@ -41,5 +41,6 @@ add_library(writecap STATIC
)
set_target_properties(writecap PROPERTIES
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
FOLDER "Libs")
......@@ -227,6 +227,7 @@ set(FULL_SO_VERSION "0.0.0")
set_target_properties(wsutil PROPERTIES
PREFIX "lib"
COMPILE_DEFINITIONS "WS_BUILD_DLL"
COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}"
LINK_FLAGS "${WS_LINK_FLAGS}"
VERSION ${FULL_SO_VERSION} SOVERSION 0
FOLDER "DLLs")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment