CetCompilerSettings¶
include(CetCompilerSettings)
Sets CET Build Modes, Compiler Flags and Properties when included.
Include this module to configure your project to use the CET standard build modes and C/C++/Fortran compiler flags. CMake options and functions are provided to manage language standards, warning levels, debugging format, symbol resolution policy, architecture level optimization and assertion activation.
CET Base Compiler Flags and Build Types¶
Base flags for a language, that is CMAKE_<LANG>_FLAGS
are always
set by prepending any required to the existing value of the CMAKE_<LANG>_FLAGS
variable. This enables a project or environment to override or extend
flags by setting CMAKE_<LANG>_FLAGS
in their own CMake scripts before
including this module.
Additional flags are added depending on the build mode being used, and CET uses the same set as defined by vanilla CMake:
None
: Base language flags onlyRelease
: Highest optimization possible, debugging informationDebug
: No optimization, debugging informationMinSizeRel
: Highest optimization possible, debugging information plus frame pointerRelWithDebInfo
: Moderate optimization, debugging info
For the GNU, Clang and Intel C/C++ compilers, these correspond to flags for optimization and debugging of:
Release
:-O3 -g
Debug
:-O0 -g
MinSizeRel
:-O3 -g -fno-omit-frame-pointer
RelWithDebInfo
:-O2 -g
When building for single mode generators like Make and Ninja,
the build type defaults to RelWithDebInfo
if it is not already
set. Note that the Release
and MinSizeRel
modes are identical
to the CET-defined OPT
and PROF
modes.
Options for Controlling the Language Standard¶
The following CMake variables are set by default when including this module to enforce availability and uniformity of the requested C++ Standard:
CMAKE_CXX_STANDARD_REQUIRED
: ON- Prevent decay to an earlier standard if the compiler in use does not support the requested standard.
CMAKE_CXX_EXTENSIONS
: OFF- Prevent use of vendor specific language extensions. For example, when using the
GNU compiler with C++14, the flag
-std=c++14
with be used rather than-std=gnu++14
.
- Prevent use of vendor specific language extensions. For example, when using the
GNU compiler with C++14, the flag
To configure the specific C++ standard against which the project will be built, the following variables and options are available:
-
CET_COMPILER_CXX_STANDARD_MINIMUM
¶ Internal variable that should be set by the project before inclusion of this module to specify the minimum C++ Standard (11, 14, 17, 2a) required by the project’s source code. For example
set(CET_COMPILER_CXX_STANDARD_MINIMUM 14) include(CetCompilerSettings)
Todo
Review this pattern of use, and whether the minimum can be set after inclusion, e.g. via a function to configure the
enum_option
used to select the standard.In UPS/cetbuildtools, standard is selected based on UPS Qualifiers, and specifially the primary qualifier. This is mostly a specification of compiler vendor, version and C++ Standard. If we provide a UPS compatibility layer, then need to use this info, but it can be as a basic check/translation that things match up (see
report_product_info
program etc, though these still rely on setup_for_development writing files to buildir).
-
CET_COMPILER_CXX_STANDARD
¶ Option to select the actual C++ Standard to compile the project against. The default is
11
, or the value ofCET_COMPILER_CXX_STANDARD_MINIMUM
if the project has set that. The set of possible valid values are11
,14
17
and2a
.If the configured Compiler/CMake version does not know how to set up this version of the standard, a
FATAL_ERROR
will be emitted.Todo
Document how to add support for a new compiler/version not known to CMake via the compile features/options functionality.
Options for Controlling Compiler Warnings¶
-
CET_COMPILER_DIAGNOSTIC_LEVEL
¶ Option to select the level of compiler diagnostics to add to flags. The warnings checked for by the compiler are defined in CET by four levels, with the following flags prepended to
CMAKE_C_FLAGS
andCMAKE_CXX_FLAGS
. At present, diagnostic selection is only enabled for C and C++ languages and when using the GNU, Clang or Intel compilers. The following values may be selected:CAVALIER
- No additional flags added for any compiler
CAUTIOUS
(default)- All
CAVALIER
flags for the compiler in use, plus - GNU/Intel compilers:
-Wall -Werror=return-type
- Clang compilers:
-Wall -Werror=return-type -Wno-mismatched-tags -Wno-missing-braces
- All
VIGILANT
- All
CAUTIOUS
flags for the compiler in use, plus - GNU/Clang compilers:
-Wextra -Wno-long-long -Winit-self -Wno-unused-local-typedefs
- Intel compilers:
-Wextra -Wno-long-long -Winit-self
- GNU/Clang/Intel C++ compilers also add:
-Woverloaded-virtual
- All
PARANOID
- All
VIGILANT
flags for the compiler in use, plus - GNU/Clang/Intel compilers:
-pedantic -Wformat-y2k -Wswitch-default -Wsync-nand -Wtrampolines -Wlogical-op -Wshadow -Wcast-qual
- NB: these are known to be GNU specific at present, but are retained until a good set for each compiler can be developed.
- All
-
CET_COMPILER_WARNINGS_ARE_ERRORS
¶ Option to turn compiler warnings into hard errors.
ON
by default.
-
CET_COMPILER_ALLOW_DEPRECATIONS
¶ Option to ignore deprecation warnings.
ON
by default. It only has an effect ifCET_COMPILER_WARNINGS_ARE_ERRORS
is activated (this matches upstream cetbuildtools behaviour.
Options for Controlling Debugging Output¶
For compatible compilers, the version and strictness of DWARF debugging output may be controlled
-
CET_COMPILER_DWARF_STRICT
¶ Option to only emit DWARF debugging info at the level set by
CET_COMPILER_DWARF_VERSION
.ON
by default, but currently only supported for GCC compiler.
Todo
Current flags are GCC dependent.
Options for Controlling Symbol Resolution¶
Linkers may have different default policies for symbol resolution. CET prefer to fully resolved symbols.
-
CET_COMPILER_NO_UNDEFINED_SYMBOLS
¶ Option to control whether the linker must fully resolve symbols for shared libraries.
ON
by default.
Architecture Level Optimizations¶
Things like SSE/Vectorization…
-
CET_COMPILER_ENABLE_SSE2
¶ Enable specific optimizations for SSE2.
OFF
by default.Note that this does not check that the system you are building for supports this instruction set.
Todo
Review options here for further checks and/or arch-specific optimizations.
Assertion Management¶
Cetbuildtools2 allows fine control over assertions by managing their
deactivation (passing NDEBUG
as a preprocessor define) on a
directory-by-directory basis.
The default policy is to only disable assertions in the Release and MinSizeRel build types.
Todo
Describe directory property behaviour
-
cet_default_asserts
¶ cet_default_asserts([DIRECTORY <dir>])
Disable assertions (i.e. pass
NDEBUG
as a preprocessor define) for Release and MinSizeRel build modes in the current directory (CMAKE_CURRENT_LIST_DIR
) and all its children.If
DIRECTORY
is passed, disable assertions for Release and MinSizeRel build modes in<dir>
and all its children.
-
cet_enable_asserts
¶ cet_enable_asserts([DIRECTORY <dir>])
Enable assertions (i.e. do not pass
NDEBUG
as a preprocessor define) for all build modes in the current directory (CMAKE_CURRENT_LIST_DIR
) and all its children.If
DIRECTORY
is passed, enable assertions for all build modes in<dir>
and all its children.
-
cet_disable_asserts
¶ cet_disable_asserts([DIRECTORY <dir>])
Disable assertions (i.e. pass
NDEBUG
as a preprocessor define) for all build types in the current directory (CMAKE_CURRENT_LIST_DIR
) and all its children.If
DIRECTORY
is passed, disable assertions for all build types in<dir>
and all its children.