Using the functions cxx_11(), cxx_14(), cxx_17() or cxx_20() this adds the appropriate flags for both unix and MSVC compilers, even for those before 3.11 with improper support.
These obviously force the standard to be required, and also disables compiler-specific extensions, ie --std=gnu++11. This helps to prevent fragmenting the code base with items not available elsewhere, adhering to the agreed C++ standards only.
There are two callable objects here, link_time_optimization which applies LTO/IPO for all following targets, and target_link_time_optimization which applies it to a specified target.
Doesn't work with GCC.
Optional Arguments
REQUIRED
If this is passed in, CMake configuration will fail with an error if LTO/IPO is not supported
Allows for easy use of some pre-made compiler options for the major compilers.
Using -DENABLE_ALL_WARNINGS=ON will enable almost all of the warnings available for a compiler:
Compiler
Options
MSVC
/W4
GCC
-Wall -Wextra
Clang
-Wall -Wextra
Using -DENABLE_EFFECTIVE_CXX=ON adds the -Weffc++ for both GCC and clang.
Using -DGENERATE_DEPENDENCY_DATA=ON generates .d files along with regular object files on a per-source file basis on GCC/Clang compilers. These files contains the list of all header files used during compilation of that compilation unit.
Sanitizers are tools that perform checks during a program’s runtime and returns issues, and as such, along with unit testing, code coverage and static analysis, is another tool to add to the programmers toolbox. And of course, like the previous tools, are tragically simple to add into any project using CMake, allowing any project and developer to quickly and easily use.
A quick rundown of the tools available, and what they do:
LeakSanitizer detects memory leaks, or issues where memory is allocated and never deallocated, causing programs to slowly consume more and more memory, eventually leading to a crash.
AddressSanitizer is a fast memory error detector. It is useful for detecting most issues dealing with memory, such as:
These are used by declaring the USE_SANITIZER CMake variable as string containing any of:
Address
Memory
MemoryWithOrigins
Undefined
Thread
Leak
Multiple values are allowed, e.g. -DUSE_SANITIZER=Address,Leak but some sanitizers cannot be combined together, e.g.-DUSE_SANITIZER=Address,Memory will result in configuration error. The delimeter character is not required and -DUSE_SANITIZER=AddressLeak would work as well.
3.10
C++ 11
version requirementC++ Standards
cmake/c++-standards.cmake
Using the functions
cxx_11()
,cxx_14()
,cxx_17()
orcxx_20()
this adds the appropriate flags for both unix and MSVC compilers, even for those before 3.11 with improper support.These obviously force the standard to be required, and also disables compiler-specific extensions, ie
--std=gnu++11
. This helps to prevent fragmenting the code base with items not available elsewhere, adhering to the agreed C++ standards only.Link Time Optimization / Interprocedural Optimization
cmake/link-time-optimization.cmake
There are two callable objects here,
link_time_optimization
which applies LTO/IPO for all following targets, andtarget_link_time_optimization
which applies it to a specified target.Doesn't work with GCC.
Optional Arguments
REQUIRED
If this is passed in, CMake configuration will fail with an error if LTO/IPO is not supported
Compiler Options
cmake/compiler-options.cmake
Allows for easy use of some pre-made compiler options for the major compilers.
Using
-DENABLE_ALL_WARNINGS=ON
will enable almost all of the warnings available for a compiler:Using
-DENABLE_EFFECTIVE_CXX=ON
adds the-Weffc++
for both GCC and clang.Using
-DGENERATE_DEPENDENCY_DATA=ON
generates.d
files along with regular object files on a per-source file basis on GCC/Clang compilers. These files contains the list of all header files used during compilation of that compilation unit.Sanitizer Builds
cmake/sanitizers.cmake
Sanitizers are tools that perform checks during a program’s runtime and returns issues, and as such, along with unit testing, code coverage and static analysis, is another tool to add to the programmers toolbox. And of course, like the previous tools, are tragically simple to add into any project using CMake, allowing any project and developer to quickly and easily use.
A quick rundown of the tools available, and what they do:
These are used by declaring the
USE_SANITIZER
CMake variable as string containing any of:Multiple values are allowed, e.g.
-DUSE_SANITIZER=Address,Leak
but some sanitizers cannot be combined together, e.g.-DUSE_SANITIZER=Address,Memory
will result in configuration error. The delimeter character is not required and-DUSE_SANITIZER=AddressLeak
would work as well.