The proper way to set compiler flags in cmake is not by using
authorJörg Mayer <jmayer@loplof.de>
Thu, 23 Aug 2012 12:30:16 +0000 (12:30 -0000)
committerJörg Mayer <jmayer@loplof.de>
Thu, 23 Aug 2012 12:30:16 +0000 (12:30 -0000)
add_definitions() but the variables CMAKE_C{,XX}_FLAGS. Set these
flags correctly at the toplevel, so no hack in the ui/qt/ subdir
is required anymore.

svn path=/trunk/; revision=44633

CMakeLists.txt
ui/qt/CMakeLists.txt

index dfbbab1a0c474509103b66074050891b8fc26593..edd7619f0eec0400807fca699497541a6516e74d 100644 (file)
@@ -115,7 +115,9 @@ set(WIRESHARK_C_FLAGS
        -Wcast-align
        -Wformat-security
        -fexcess-precision=fast
+)
 
+set(WIRESHARK_C_ONLY_FLAGS
        # The following are C only, not C++
        -Wdeclaration-after-statement
        -Wno-pointer-sign
@@ -150,6 +152,9 @@ set(WIRESHARK_EXTRA_C_FLAGS
        # More cleanup needed for this on LP64
        -Wshorten-64-to-32
 
+)
+
+set(WIRESHARK_EXTRA_C_ONLY_FLAGS
        # The following are C only, not C++
        -Wbad-function-cast
        -Wc++-compat
@@ -162,6 +167,7 @@ set(WIRESHARK_EXTRA_C_FLAGS
 
 if(ENABLE_EXTRA_GCC_CHECKS)   # This overrides -Werror
        set(WIRESHARK_C_FLAGS ${WIRESHARK_C_FLAGS} ${WIRESHARK_EXTRA_C_FLAGS})
+       set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS} ${WIRESHARK_EXTRA_C_ONLY_FLAGS})
 endif()
 
 add_definitions(
@@ -180,10 +186,23 @@ foreach(THIS_FLAG ${WIRESHARK_C_FLAGS})
        set(V WS_C_FLAG_VALID${C})
        check_c_compiler_flag(${${F}} ${V})
        if (${${V}})
-               add_definitions(${${F}})
+               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${F}}")
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${F}}")
+       endif()
+       math(EXPR C "${C} + 1")
+endforeach()
+# Continue increasing C from previous loop
+foreach(THIS_FLAG ${WIRESHARK_C_ONLY_FLAGS})
+       set(F WS_C_FLAG_${C})
+       set(${F} ${THIS_FLAG})
+       set(V WS_C_FLAG_VALID${C})
+       check_c_compiler_flag(${${F}} ${V})
+       if (${${V}})
+               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${F}}")
        endif()
        math(EXPR C "${C} + 1")
 endforeach()
+message(STATUS "C-Flags: ${CMAKE_C_FLAGS}\nCXX-Flags: ${CMAKE_CXX_FLAGS}")
 
 if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_GCC_CHECKS)
        check_c_compiler_flag(-Werror WERROR)
index 2b686a658d57ed3d2f7261f865c04c1de1ba719a..e7971f0cc06d74223910e9f355ab5d86dba71fdd 100644 (file)
@@ -137,13 +137,6 @@ endif()
 
 add_definitions(${QT_DEFINITIONS})
 
-# Get rid of C-only compile flags
-remove_definitions(
-       -Wdeclaration-after-statement
-       -Wno-pointer-sign
-       -Wold-style-definition
-)
-
 add_library(qtui STATIC
        ${QTSHARK_SRC}
        ${QTSHARK_UI_SRC}