flomesh-io / pipy

Pipy is a programmable proxy for the cloud, edge and IoT.
https://flomesh.io/pipy
Other
743 stars 70 forks source link

Updated cmake version and added modules #35

Closed naqvis closed 2 years ago

naqvis commented 2 years ago

C++ Standards cmake/c++-standards.cmake

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.

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, 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

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:

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.

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.