CMakeList: Check that compiler supports -Wimplicit-fallthrough
authorFlorian Fainelli <f.fainelli@gmail.com>
Wed, 12 Sep 2018 00:14:19 +0000 (17:14 -0700)
committerFlorian Fainelli <f.fainelli@gmail.com>
Wed, 12 Sep 2018 00:14:19 +0000 (17:14 -0700)
This is a GCC >= 7 feature, not all compilers support it.

Fixes: 908a9f4f1027 ("CMakeLists.txt: add -Wimplicit-fallthrough to the compiler flags")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
CMakeLists.txt

index 50f62bd3ceae698c36e2bcc5e34b9b4aad927222..d6203aac3a8f5e55451a7bf6b0663ea15da44ff3 100644 (file)
@@ -1,7 +1,17 @@
 cmake_minimum_required(VERSION 2.6)
 
 PROJECT(netifd C)
-ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-unknown-warning-option -Wno-format-truncation -Wimplicit-fallthrough)
+
+IF(NOT ${CMAKE_VERSION} LESS 3.0)
+  include(CheckCCompilerFlag)
+  check_c_compiler_flag(-Wimplicit-fallthrough HAS_IMPLICIT_FALLTHROUGH)
+ENDIF()
+
+ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-unknown-warning-option -Wno-format-truncation)
+
+IF(HAS_IMPLICIT_FALLTHROUGH)
+  ADD_DEFINITIONS(-Wimplicit-fallthrough)
+ENDIF()
 
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")