Browse Source

Cleanup cmake, move warnings to own files

Kajetan Johannes Hammerle 10 months ago
parent
commit
ee8fb7bc35
3 changed files with 126 additions and 76 deletions
  1. 13 76
      CMakeLists.txt
  2. 45 0
      cmake/clang_warnings.cmake
  3. 68 0
      cmake/gcc_warnings.cmake

+ 13 - 76
CMakeLists.txt

@@ -52,101 +52,38 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
     set(COMPILE_OPTIONS -flto)
     set(LINK_OPTIONS -flto)
     set(LOG_LEVEL 2)
-    if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
-        set(DEFINITIONS bool=_Bool true=1 false=0 nullptr=0 static_assert=_Static_assert)
-    else()
-        set(DEFINITIONS "")
-    endif()
+    set(DEFINITIONS "")
 else()
+    set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY)
     if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
         set(COMPILE_OPTIONS --coverage)
         set(LINK_OPTIONS gcov)
-        set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY bool=_Bool true=1 false=0 nullptr=0 static_assert=_Static_assert)
-    else()
+    elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
         set(COMPILE_OPTIONS -fprofile-instr-generate -fcoverage-mapping)
         set(LINK_OPTIONS ${COMPILE_OPTIONS})
-        set(DEFINITIONS ERROR_SIMULATOR CORE_CHECK_MEMORY)
     endif()
     set(LOG_LEVEL 4)
     list(APPEND SRC "src/ErrorSimulator.c")
 endif()
 
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
-    set(MORE_WARNINGS
-        -Walloc-zero
-        -Wanalyzer-too-complex
-        -Warith-conversion
-        -Warray-bounds=2
-        -Wattribute-alias=2
-        -Wbidi-chars=any
-        -Wcast-align=strict
-        -Wduplicated-branches
-        -Wduplicated-cond
-        -Wformat-overflow=2
-        -Wformat-signedness
-        -Wformat-truncation=2
-        -Wimplicit-fallthrough=5
-        -Wjump-misses-init
-        -Wlogical-op
-        -Wnormalized=nfkc
-        -Wshift-overflow=2
-        -Wstack-usage=8388608
-        -Wstringop-overflow=4
-        -Wtrampolines
-        -Wtrivial-auto-var-init
-        -Wunused-const-variable=2
-        -Wuse-after-free=3
+    include("cmake/gcc_warnings.cmake")
+    set(DEFINITIONS ${DEFINITIONS}
+        bool=_Bool
+        true=1
+        false=0
+        nullptr=0
+        static_assert=_Static_assert
     )
+elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+    include("cmake/clang_warnings.cmake")
 endif()
 
 add_library(core STATIC ${SRC})
 target_compile_options(core PUBLIC
     ${COMPILE_OPTIONS}
-    -Wall
-    -Walloca
-    -Warray-parameter
-    -Wbad-function-cast
-    -Wcast-qual
-    -Wconversion
-    -Wdate-time
-    -Wdisabled-optimization
-    -Wdouble-promotion
-    -Wenum-compare
-    -Wenum-conversion
-    -Werror
-    -Wextra
-    -Wfloat-equal
-    -Wformat=2
-    -Wframe-larger-than=8388608
-    -Winfinite-recursion
-    -Winit-self
-    -Winvalid-pch
-    -Wlarger-than=1073741824
-    -Wmissing-braces
-    -Wmissing-declarations
-    -Wmissing-include-dirs
-    -Wmissing-prototypes
-    -Wmultichar
-    -Wnarrowing
-    -Wnested-externs
-    -Wnull-dereference
-    -Wold-style-definition
-    -Woverlength-strings
-    -Wredundant-decls
-    -Wshadow
-    -Wsign-conversion
-    -Wstack-protector
-    -Wstrict-overflow=2
-    -Wstrict-prototypes
-    -Wswitch-enum
-    -Wundef
-    -Wunreachable-code
-    -Wvla
-    -Wwrite-strings
+    ${WARNINGS}
     -fdiagnostics-color=always
-    -pedantic
-    -pedantic-errors
-    ${MORE_WARNINGS}
 )
 target_compile_definitions(core 
     PUBLIC CORE_LOG_LEVEL=${LOG_LEVEL}

+ 45 - 0
cmake/clang_warnings.cmake

@@ -0,0 +1,45 @@
+set(WARNINGS
+    -Wall
+    -Walloca
+    -Warray-parameter
+    -Wbad-function-cast
+    -Wcast-qual
+    -Wconversion
+    -Wdate-time
+    -Wdisabled-optimization
+    -Wdouble-promotion
+    -Wenum-compare
+    -Wenum-conversion
+    -Werror
+    -Wextra
+    -Wfloat-equal
+    -Wformat=2
+    -Wframe-larger-than=8388608
+    -Winfinite-recursion
+    -Winit-self
+    -Winvalid-pch
+    -Wlarger-than=1073741824
+    -Wmissing-braces
+    -Wmissing-declarations
+    -Wmissing-include-dirs
+    -Wmissing-prototypes
+    -Wmultichar
+    -Wnarrowing
+    -Wnested-externs
+    -Wnull-dereference
+    -Wold-style-definition
+    -Woverlength-strings
+    -Wredundant-decls
+    -Wshadow
+    -Wsign-conversion
+    -Wstack-protector
+    -Wstrict-overflow=2
+    -Wstrict-prototypes
+    -Wswitch-enum
+    -Wundef
+    -Wunreachable-code
+    -Wvla
+    -Wwrite-strings
+    -pedantic
+    -pedantic-errors
+)

+ 68 - 0
cmake/gcc_warnings.cmake

@@ -0,0 +1,68 @@
+set(WARNINGS
+    -Wall
+    -Walloc-zero
+    -Walloca
+    -Wanalyzer-too-complex
+    -Warith-conversion
+    -Warray-bounds=2
+    -Warray-parameter
+    -Wattribute-alias=2
+    -Wbad-function-cast
+    -Wbidi-chars=any
+    -Wcast-align=strict
+    -Wcast-qual
+    -Wconversion
+    -Wdate-time
+    -Wdisabled-optimization
+    -Wdouble-promotion
+    -Wduplicated-branches
+    -Wduplicated-cond
+    -Wenum-compare
+    -Wenum-conversion
+    -Werror
+    -Wextra
+    -Wfloat-equal
+    -Wformat-overflow=2
+    -Wformat-signedness
+    -Wformat-truncation=2
+    -Wformat=2
+    -Wframe-larger-than=8388608
+    -Wimplicit-fallthrough=5
+    -Winfinite-recursion
+    -Winit-self
+    -Winvalid-pch
+    -Wjump-misses-init
+    -Wlarger-than=1073741824
+    -Wlogical-op
+    -Wmissing-braces
+    -Wmissing-declarations
+    -Wmissing-include-dirs
+    -Wmissing-prototypes
+    -Wmultichar
+    -Wnarrowing
+    -Wnested-externs
+    -Wnormalized=nfkc
+    -Wnull-dereference
+    -Wold-style-definition
+    -Woverlength-strings
+    -Wredundant-decls
+    -Wshadow
+    -Wshift-overflow=2
+    -Wsign-conversion
+    -Wstack-protector
+    -Wstack-usage=8388608
+    -Wstrict-overflow=2
+    -Wstrict-prototypes
+    -Wstringop-overflow=4
+    -Wswitch-enum
+    -Wtrampolines
+    -Wtrivial-auto-var-init
+    -Wundef
+    -Wunreachable-code
+    -Wunused-const-variable=2
+    -Wuse-after-free=3
+    -Wvla
+    -Wwrite-strings
+    -pedantic
+    -pedantic-errors
+)