From 62d3b6ee10e23bc9f8b0bcf6b4c86cfe790132b0 Mon Sep 17 00:00:00 2001 From: Joshua Anderson Date: Mon, 20 Sep 2021 16:21:23 -0700 Subject: [PATCH] Compile test project with pedantic --- .github/actions/spelling/expect.txt | 1 + CMakeLists.txt | 49 +++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 54054b4ff4..c098ea934f 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -1732,6 +1732,7 @@ virtualbox virtualenv virtualization virtualized +vla vlist vm VMIN diff --git a/CMakeLists.txt b/CMakeLists.txt index fd9fa667a3..ae62d4c29b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,19 +9,48 @@ set(FPRIME_FRAMEWORK_PATH "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Location of F set(FPRIME_PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Root path of F prime project" FORCE) # This cmake project is only intended to be used by CI and developers to test F-prime. We enable -# -Wall and -Wextra on this particular project as a canary to warn about compilation errors without -# impacting real projects, where a warning from an untested compiler could break the build. +# -Wall and -Wextra on this particular project as a canary to warn about compilation +# errors without impacting real projects, where a warning from an untested compiler could break the +# build. + +add_compile_options( + -Wall + -Wextra + -Werror + $<$:-Wold-style-cast> + -Wno-unused-parameter +) + +# Turn on pedantic checks for clang, but disable specific checks that F' doesn't comply with. +# GCC doesn't support disabling specific pedantic checks, so skip pedantic on GCC for now. # -# Disable the unused parameter warning for now. F' has a lot of interfaces, so unused method -# parameters are common in the F prime code base. Eventually all intentionally unused parameters -# should be annotated to avoid this error. -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wold-style-cast -Wno-unused-parameter") +# -Wno-unused-parameter: Disable the unused parameter warning for now. F' has a lot of interfaces, +# so unused method parameters are common in the F prime code base. Eventually all intentionally +# unused parameters should be annotated to avoid this error. +# +# -Wno-gnu-zero-variadic-macro-arguments: gnu extension required to allow FW_ASSERT to support 0+ +# optional arguments +# +# -Wno-vla-extension: Variable length arrays are required to support sending to async serializable +# ports. https://github.com/nasa/fprime/issues/945 +# +# -Wno-zero-length-array: maximum port message size calculated by using sizeof on an array the size +# of all the port's arguments. When port has no argument array is zero sized. Array is used at +# compile time only. +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options( + -pedantic + -Wno-gnu-zero-variadic-macro-arguments + $<$:-Wno-vla-extension> + $<$:-Wno-zero-length-array> + ) +endif() # For this testing cmake project, enable AddressSanitizer, a runtime memory sanitizer, on all unit tests -set (CMAKE_C_FLAGS_TESTING "${CMAKE_C_FLAGS_TESTING} -fno-omit-frame-pointer -fsanitize=address") -set (CMAKE_CXX_FLAGS_TESTING "${CMAKE_CXX_FLAGS_TESTING} -fno-omit-frame-pointer -fsanitize=address") -set (CMAKE_LINKER_FLAGS_TESTING "${CMAKE_LINKER_FLAGS_TESTING} -fno-omit-frame-pointer -fsanitize=address") +if (CMAKE_BUILD_TYPE STREQUAL "Testing" OR CMAKE_BUILD_TYPE STREQUAL "TESTING") + add_compile_options(-fno-omit-frame-pointer -fsanitize=address) + add_link_options(-fno-omit-frame-pointer -fsanitize=address) +endif() # Include the build for F prime. include("${CMAKE_CURRENT_LIST_DIR}/cmake/FPrime.cmake")