CMakeModules bundles CMake modules and toolchain files.
Table of Contents
CPM.cmake is a cross-platform CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper around CMake's FetchContent module that adds version control, caching, a simple API and more. The CPM module gets implicitly included.
# Use CPM to add a package
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
Adds a custom target specifically used to run clang-format.
add_clang_format_target(<name> OPTIONS [options...] FILES [files...])
# e.g.
add_clang_format_target(FormatTarget OPTIONS -i --style=llvm FILES main.cpp func.cpp)
Wrapper around add_compile_options and add_link_options. Simply invokes both commands with all arguments.
Build Qt6 from source. For more information, please read the article Building Qt 6 from Git on the official wiki.
build_qt(<version> MODULES [modules...] CMAKE_OPTIONS [cmake_options...])
build_qt(
6.6.1
MODULES
qtbase
qtsvg
CMAKE_OPTIONS
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=ON)
Macro which conditionally adds Qt6 or Qt5 components depending on which version is already present in the configuration. If neither Qt6 nor Qt5 is found, the macro tries to add Qt6 first and if this fails, Qt5. This allows libraries to integrate Qt components without having to know the version.
find_qt(REQUIRED COMPONENTS Charts Core DataVisualization Widgets)
Minify HTML code by removing comments, newlines and whitespaces.
minify_html(index.html ${CMAKE_BINARY_DIR}/index.html)
Add -fsanitize options starting from current directory and above.
sanitize(address,undefined)
Wrapper around target_compile_options which adds a bunch of useful compiler warnings to a target. Can also be called without any further arguments.
Wrapper around target_compile_options and target_link_options. Simply invokes both commands with all arguments.
Enables the UNITY_BUILD target property and sets UNITY_BUILD_BATCH_SIZE 0.
The function uses the output of git describe --tags
to generate a MAJOR.MINOR.PATCH version string. This project versions itself with it.
version_from_git()
project(CMakeModules VERSION ${VERSION_FROM_GIT})
It sets the following variables:
- VERSION_FROM_GIT
- VERSION_MAJOR_FROM_GIT
- VERSION_MINOR_FROM_GIT
- VERSION_PATCH_FROM_GIT
- IDENTIFIERS_FROM_GIT
- METADATA_FROM_GIT
Important
GitHub actions/checkout@v4 does not automatically checkout tags. You'll need to manually specify that, e.g.
- uses: actions/checkout@v4
with:
fetch-depth: 0
CQtDeployer is like a cross-platform version of windeployqt. It helps you to extract all libraries your executable depends on and to create a launch script (or installer) for your application.
# Fetch CQtDeployer for Linux
find_package(CQtDeployer 1.6.2337 REQUIRED COMPONENTS Linux)
# Use CQtDeployer to deploy a target
add_custom_command(
TARGET YourTarget
POST_BUILD
COMMAND ${CQTDEPLOYER_EXECUTABLE} -bin $<TARGET_FILE:YourTarget>)
Toolchain file to build ARM target with Clang. CMAKE_SYSTEM_NAME
gets set to Generic
. Build types are defined as follows
Build type | Flags |
---|---|
Debug | -Og -g |
Release | -DNDEBUG -Os -g |
RelWithDebug | -Os -g |
MinSizeRel | -DNDEBUG -Os -g |
Toolchain file to build ARM target with arm-none-eabi-gcc. CMAKE_SYSTEM_NAME
gets set to Generic
. Build types are defined as follows
Build type | Flags |
---|---|
Debug | -Og -g |
Release | -DNDEBUG -Os -g |
RelWithDebug | -Os -g |
MinSizeRel | -DNDEBUG -Os -g |
Toolchain file to build x86_64 target with Clang.
Toolchain file to build x86_64 target with GCC / GCC 12.
Toolchain file to cross-compile x86_64 target with mingw-w64. This file specifically targets Ubuntu 22.04.