C++ Utilities  4.16.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Build system

Documents variables to control the build system and provided CMake modules

Variables passable as CMake arguments

Useful variables provided by CMake itself

Custom variables

The following variables are read by the CMake modules provided by c++utilities and qtutilities.

None of these are enabled or set by default, unless stated otherwise.

Variables for specifying location of 3rd party dependencies

The build script tries to find the required dependencies at standard loctions using the CMake functions find_library and find_package. The behaviour of those functions can be controlled by setting some variables, eg. using a toolchain file. Checkout the CMake documentation for this.

If the detection does not work as expected or a library from a non-standard location should be used, the following variables can be used to specify the location of libraries and include directories directly:

Note about Qt: Qt modules are always configured using the CMake packages via find_package. So using the variables described above to specify a custom location does not work. Instead, the variables CMAKE_FIND_ROOT_PATH or CMAKE_PREFIX_PATH can be used to specify the install prefix of the Qt build to use. Set QT_LINKAGE to STATIC if it is a static build of Qt.

Examples

Example of passing location of dynamic iconv and zlib to CMake:

/opt/osxcross/bin/x86_64-apple-darwin15-cmake \
-Diconv_DYNAMIC_LIB:FILEPATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/lib/libiconv.2.tbd \
-Diconv_DYNAMIC_INCLUDE_DIR:PATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/include \
-Dz_DYNAMIC_LIB:FILEPATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/lib/libz.1.tbd \
-Dz_DYNAMIC_INCLUDE_DIR:PATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/include \
...

Here's an example of passing the location of the Android SDK/NDK to compile for Android. This time the iconv library is located by specifying its install prefix via CMAKE_FIND_ROOT_PATH. The include directories are not automatically added for that library, so this must still be done manually:

_android_arch=arm64-v8a
cmake \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=21 \
-DCMAKE_ANDROID_ARCH_ABI=$_android_arch \
-DCMAKE_ANDROID_NDK=/opt/android-ndk \
-DCMAKE_ANDROID_SDK=/opt/android-sdk \
-DCMAKE_ANDROID_STL_TYPE=gnustl_shared \
-DCMAKE_INSTALL_PREFIX=/opt/android-libs/$_android_arch \
-DCMAKE_FIND_ROOT_PATH="/opt/android-ndk/sysroot;/opt/android-libs/$_android_arch" \
-Diconv_DYNAMIC_INCLUDE_DIR="/opt/android-libs/$_android_arch/include" \
-Diconv_STATIC_INCLUDE_DIR="/opt/android-libs/$_android_arch/include" \
...

Windows specific

MacOS specific

Qt specific

Variables to be set in project file

The following variables are read by the CMake modules provided by c++utilities and qtutilities.

Meta data

Files

Additional build variables

Provided modules

c++utilities and qtutilities provide CMake modules to reduce boilerplate code in the CMake files of my projects. Those modules implement the functionality controlled by the variables documented above. Most important modules are:

Since those modules make use of the variables explained above, the modules must be included after setting those variables. The inclusion order of the modules matters as well.

For an example, checkout the project file of c++utilities itself. The project files of Syncthing Tray should cover everything (library, plugin, application, tests, desktop file, Qt resources and translations, ...).