From ebd356b7d81656d60211fcced597573aef13f39b Mon Sep 17 00:00:00 2001 From: Joseph Hickey <joseph.p.hickey@nasa.gov> Date: Wed, 8 Jan 2020 15:33:08 -0500 Subject: [PATCH] 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 +)