Skip to content

ZIMO-Elektronik/CMakeModules

Repository files navigation

CMakeModules

tests

CMakeModules bundles CMake modules and toolchain files.

Table of Contents
  1. Modules
  2. Find<PackageName> Files
  3. Toolchain Files

Modules

CPM.cmake

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")

add_clang_format_target

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)

add_compile_link_options

Wrapper around add_compile_options and add_link_options. Simply invokes both commands with all arguments.

build_qt

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)

find_qt

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

Minify HTML code by removing comments, newlines and whitespaces.

minify_html(index.html ${CMAKE_BINARY_DIR}/index.html)

sanitize

Add -fsanitize options starting from current directory and above.

sanitize(address,undefined)

target_common_warnings

Wrapper around target_compile_options which adds a bunch of useful compiler warnings to a target. Can also be called without any further arguments.

target_compile_link_options

Wrapper around target_compile_options and target_link_options. Simply invokes both commands with all arguments.

target_unity_build

Enables the UNITY_BUILD target property and sets UNITY_BUILD_BATCH_SIZE 0.

version_from_git

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

Find<PackageName> Files

FindCQtDeployer

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 Files

toolchain-arm-clang

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-arm-none-eabi-gcc

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

Toolchain file to build x86_64 target with Clang.

toolchain-gcc / toolchain-gcc-12

Toolchain file to build x86_64 target with GCC / GCC 12.

toolchain-x86_64-w64-mingw32-gcc

Toolchain file to cross-compile x86_64 target with mingw-w64. This file specifically targets Ubuntu 22.04.

About

Bundles CMake modules and toolchain files

Resources

License

Stars

Watchers

Forks