This is the common set of CMake based modules used by all C++ projects at
Netlify. For the most part, these include FindXXX.cmake
files, but also
support a few specific functions. Some of these will be removed in the future
once Netlify migrates to using IXM for its projects, and this will instead work
as a Project Blueprint for Netlify's internal projects.
These are the only settings where these modules are used.
- Ubuntu 20.04
- Clang 10
- C++2a
- CMake 3.16
Any other compilers, operating systems, or languages are not guaranteed to be supported.
The following features are not yet (fully) implemented, but are currently planned
- Better IXM Integration (This is reliant on IXM being released)
- Custom Toolchain File (To ensure Clang, LLD, libc++, etc.)
- Profile Guidance Code Generation
- Sanitizer Support
This project is intended to be acquired via FetchContent. Thus, the
following code should go at the top of every project's root CMakeLists.txt
file.
cmake_minimum_required(VERSION 3.16)
include(FetchContent)
FetchContent_Declare(cmake GIT_REPOSITORY https://github.com/netlify/cmake GIT_TAG main)
FetchContent_MakeAvailable(cmake)
This will pull in the Netlify CMake Library, set several internal values, prepare various properties, etc.
If using additional CMake libraries via FetchContent
, simply declare more
of them before calling FetchContent_MakeAvailable
.
Most projects will do the following
cmake_minimum_required(VERSION 3.16)
include(FetchContent)
FetchContent_Declare(cmake GIT_REPOSITORY https://github.com/netlify/cmake GIT_TAG main)
FetchContent_MakeAvailable(cmake)
set(CMAKE_PROJECT_INCLUDE ${NETLIFY_PROJECT_PRELUDE})
project(<project-name-here> LANGUAGES CXX)
This will attempt to set and find the most common flags and variables for our given target.
Netlify's CMake modules perform the following operations when first included. This is done to ensure that we have a guaranteed behavior across all of our projects. However, this might disrupt others workflows. The changes these modules do are mentioned below:
- CTest is included, but the CDash related targets are disabled.
CMAKE_EXPORT_COMPILE_COMMANDS
is set toYES
.CMAKE_POLICY_DEFAULT_CMP0077
is set toNEW
.- In-Source builds are disabled with a hard error
- The
Catch2
Unit Testing library is declared. - Color diagnostics are enabled by default.
-Og
and-ggdb
are enabled by default for Debug based builds.