From ebd356b7d81656d60211fcced597573aef13f39b Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 8 Jan 2020 15:33:08 -0500 Subject: [PATCH 1/3] Fix #24: Add strict warning flags Add extra compile options for mission scope and arch scope. These are separated to support cross compile environments that do not/cannot use the same flags on both builds. For "mission" build the targets are never cross compiled, only built for the native host machine. It should be safe to assume a compiler in the GCC family and the strict warnings should _always_ be applicable here. For "arch" build the options are compiler vendor dependent. The file as-supplied can only be used if all the target cross compilers are in the same family and support the same warning options. However, this file can be modified without affecting the options used for the host side tools. --- cmake/sample_defs/arch_build.cmake | 37 +++++++++++++++++++++++++++ cmake/sample_defs/mission_build.cmake | 27 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 cmake/sample_defs/arch_build.cmake create mode 100644 cmake/sample_defs/mission_build.cmake diff --git a/cmake/sample_defs/arch_build.cmake b/cmake/sample_defs/arch_build.cmake new file mode 100644 index 000000000..aa0c1ec35 --- /dev/null +++ b/cmake/sample_defs/arch_build.cmake @@ -0,0 +1,37 @@ +# +# Example arch_build.cmake +# ------------------------- +# +# This file will be automatically included in the arch-specific build scope +# +# Definitions and options specified here will be used when cross-compiling +# _all_ FSW code for _all_ targets defined in targets.cmake. +# +# Avoid machine-specific code generation options in this file (e.g. -f,-m options); such +# options should be localized to the toolchain file such that they will only be +# included on the machines where they apply. +# +# CAUTION: In heterogeneous environments where different cross compilers are +# used for different CPUs, particularly if from different vendors, it is likely +# that compile options will need to be different as well. +# +# In general, options in this file can only be used in cases where all CPUs use a +# compiler from the same vendor and/or are all GCC based such that they accept similar +# command line options. +# +# This file can alternatively be named as "arch_build_${TARGETSYSTEM}.cmake" +# where ${TARGETSYSTEM} represents the system type, matching the toolchain. +# +# These example options assume a GCC-style toolchain is used for cross compilation, +# and uses the same warning options that are applied at the mission level. +# +add_compile_options( + -std=c99 # Target the C99 standard (without gcc extensions) + -pedantic # Issue all the warnings demanded by strict ISO C + -Wall # Warn about most questionable operations + -Wstrict-prototypes # Warn about missing prototypes + -Wwrite-strings # Warn if not treating string literals as "const" + -Wpointer-arith # Warn about suspicious pointer operations + -Werror # Treat warnings as errors (code should be clean) +) + diff --git a/cmake/sample_defs/mission_build.cmake b/cmake/sample_defs/mission_build.cmake new file mode 100644 index 000000000..0cd78732e --- /dev/null +++ b/cmake/sample_defs/mission_build.cmake @@ -0,0 +1,27 @@ +# +# Example mission_build.cmake +# --------------------------- +# +# This file will be automatically included in the top level ("mission") build scope +# +# Definitions and options specified here will be used when building local tools and +# other code that runs on the development host, but do _NOT_ apply to flight software +# (embedded) code or anything built for the target machine. +# +# These options assume a GCC toolchain but a similar set should be applicable to clang. +# +add_compile_options( + -std=c99 # Target the C99 standard (without gcc extensions) + -pedantic # Issue all the warnings demanded by strict ISO C + -Wall # Warn about most questionable operations + -Wstrict-prototypes # Warn about missing prototypes + -Wwrite-strings # Warn if not treating string literals as "const" + -Wpointer-arith # Warn about suspicious pointer operations + -Werror # Treat warnings as errors (code should be clean) +) + +# The _XOPEN_SOURCE directive is required for glibc to enable conformance with the +# the X/Open standard version 6, which includes POSIX.1c as well as SUSv2/UNIX98 extensions. +add_definitions( + -D_XOPEN_SOURCE=600 +) From 7a2f49b58ba114b5b0925d805f8ac4175a359933 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 9 Jan 2020 12:16:03 -0500 Subject: [PATCH 2/3] Issue #24: Add _custom suffix to extension files Add a _custom suffix to differentiate the customization file from the base file in the cmake directory. --- CMakeLists.txt | 6 +++--- .../{arch_build.cmake => arch_build_custom.cmake} | 6 +++--- .../{mission_build.cmake => mission_build_custom.cmake} | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename cmake/sample_defs/{arch_build.cmake => arch_build_custom.cmake} (91%) rename cmake/sample_defs/{mission_build.cmake => mission_build_custom.cmake} (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b859fee3a..84fd2a502 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,10 +97,10 @@ read_targetconfig() # The custom script may override functions such as the # cfe_exec_do_install() and cfe_app_do_install() functions for this if (IS_CFS_ARCH_BUILD) - include("${MISSION_DEFS}/arch_build.cmake" OPTIONAL) - include("${MISSION_DEFS}/arch_build_${TARGETSYSTEM}.cmake" OPTIONAL) + include("${MISSION_DEFS}/arch_build_custom.cmake" OPTIONAL) + include("${MISSION_DEFS}/arch_build_custom_${TARGETSYSTEM}.cmake" OPTIONAL) elseif (IS_CFS_MISSION_BUILD) - include("${MISSION_DEFS}/mission_build.cmake" OPTIONAL) + include("${MISSION_DEFS}/mission_build_custom.cmake" OPTIONAL) endif (IS_CFS_ARCH_BUILD) # Call the prepare function defined by the sub-script diff --git a/cmake/sample_defs/arch_build.cmake b/cmake/sample_defs/arch_build_custom.cmake similarity index 91% rename from cmake/sample_defs/arch_build.cmake rename to cmake/sample_defs/arch_build_custom.cmake index aa0c1ec35..14d41a517 100644 --- a/cmake/sample_defs/arch_build.cmake +++ b/cmake/sample_defs/arch_build_custom.cmake @@ -1,6 +1,6 @@ # -# Example arch_build.cmake -# ------------------------- +# Example arch_build_custom.cmake +# ------------------------------- # # This file will be automatically included in the arch-specific build scope # @@ -19,7 +19,7 @@ # compiler from the same vendor and/or are all GCC based such that they accept similar # command line options. # -# This file can alternatively be named as "arch_build_${TARGETSYSTEM}.cmake" +# This file can alternatively be named as "arch_build_custom_${TARGETSYSTEM}.cmake" # where ${TARGETSYSTEM} represents the system type, matching the toolchain. # # These example options assume a GCC-style toolchain is used for cross compilation, diff --git a/cmake/sample_defs/mission_build.cmake b/cmake/sample_defs/mission_build_custom.cmake similarity index 94% rename from cmake/sample_defs/mission_build.cmake rename to cmake/sample_defs/mission_build_custom.cmake index 0cd78732e..ae256ba9b 100644 --- a/cmake/sample_defs/mission_build.cmake +++ b/cmake/sample_defs/mission_build_custom.cmake @@ -1,6 +1,6 @@ # -# Example mission_build.cmake -# --------------------------- +# Example mission_build_custom.cmake +# ---------------------------------- # # This file will be automatically included in the top level ("mission") build scope # From c5625fc1bcd9aeca4650ed3ac6faf998cb757f22 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 15 Jan 2020 14:53:32 -0500 Subject: [PATCH 3/3] Update #24: Also enable cast-align warning Include in the basic warning set. Note that at this time the CFE does not build cleanly on all architectures with this warning enabled, pending resolution of issue #313. --- cmake/sample_defs/arch_build_custom.cmake | 1 + cmake/sample_defs/mission_build_custom.cmake | 1 + 2 files changed, 2 insertions(+) diff --git a/cmake/sample_defs/arch_build_custom.cmake b/cmake/sample_defs/arch_build_custom.cmake index 14d41a517..ac1dd99b4 100644 --- a/cmake/sample_defs/arch_build_custom.cmake +++ b/cmake/sample_defs/arch_build_custom.cmake @@ -32,6 +32,7 @@ add_compile_options( -Wstrict-prototypes # Warn about missing prototypes -Wwrite-strings # Warn if not treating string literals as "const" -Wpointer-arith # Warn about suspicious pointer operations + -Wcast-align # Warn about casts that increase alignment requirements -Werror # Treat warnings as errors (code should be clean) ) diff --git a/cmake/sample_defs/mission_build_custom.cmake b/cmake/sample_defs/mission_build_custom.cmake index ae256ba9b..92506bc9a 100644 --- a/cmake/sample_defs/mission_build_custom.cmake +++ b/cmake/sample_defs/mission_build_custom.cmake @@ -17,6 +17,7 @@ add_compile_options( -Wstrict-prototypes # Warn about missing prototypes -Wwrite-strings # Warn if not treating string literals as "const" -Wpointer-arith # Warn about suspicious pointer operations + -Wcast-align # Warn about casts that increase alignment requirements -Werror # Treat warnings as errors (code should be clean) )