C++ Utilities 5.26.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Documents variables to control the build system and provided CMake modules.
CMAKE_INSTALL_PREFIX=path
: specifies the final install prefix (temporary install prefix is set via make
argument DESTDIR=path
)CMAKE_BUILD_TYPE=Release/Debug
: specifies whether to do a debug or a release buildBUILD_SHARED_LIBS=ON/OFF
: whether to build shared libraries (ON
) or static libraries (OFF
); it is not possible to build both at the same time within the same build processCMAKE_SKIP_BUILD_RPATH=OFF
: ensures the rpath is set in the build treeCMAKE_INSTALL_RPATH=rpath
: sets the rpath used when installingCMAKE_CXX_FLAGS
: sets flags to be passed to the C++ compilerCMAKE_FIND_LIBRARY_SUFFIXES
: sets the library suffixes the build script will consider, e.g. set to .a;.lib
to prefer static Windows libraries or to .dll;.dll.a
to prefer shared Windows librariesCMAKE_FIND_DEBUG_MODE=ON/OFF
or --debug-find
flag: whether verbose debug output for finding libraries should be enabledThe 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.
LIB_SUFFIX=suffix
: suffix for library install directoryLIB_SUFFIX_32=suffix
: suffix for library install directoryLIB_SUFFIX
when building for 32-bit platformsLIB_SUFFIX_64=suffix
: suffix for library install directoryLIB_SUFFIX
when building for 64-bit platformsSHELL_COMPLETION_ENABLED=ON/OFF
: enables shell completion in general (enabled by default)BASH_COMPLETION_ENABLED=ON/OFF
: enables Bash completion (enabled by default)LOGGING_ENABLED=ON/OFF
: enables further logging in some applicationsFORCE_OLD_ABI=ON/OFF
: forces use of old C++ ABI_GLIBCXX_USE_CXX11_ABI=0
EXCLUDE_TESTS_FROM_ALL=ON/OFF
: excludes tests from the all target (enabled by default)APPEND_GIT_REVISION=ON/OFF
: whether the build script should attempt to append the Git revision and the latest commit ID to the version--help
CLANG_FORMAT_ENABLED=ON/OFF
: enables tidy target for code formatting via clang-format
META_NO_TIDY
in the project filecheck
targetCMAKE_FORMAT_ENABLED=ON/OFF
: enables tidy target for code formatting via cmake-format
META_NO_TIDY
in the project fileMETA_CMAKE_FORMAT_OPTIONS
in the project fileCLANG_TIDY_ENABLED=ON/OFF
: enables target static-check
for static code analysis with clang-tidy
META_NO_STATIC_ANALYSIS
in the project fileCLANG_SOURCE_BASED_COVERAGE_ENABLED=ON/OFF
: enables coverage
target to determine source-based test coverage using Clang/llvmENABLE_INSTALL_TARGETS=ON/OFF
: enables creation of install targets (enabled by default)ENABLE_ESCAPE_CODES_BY_DEAULT=ON/OFF
: enables use of escape codes for formatted output by defaultc++utilities
; projects using that build of c++utilities
will then use this defaultUSE_NATIVE_FILE_BUFFER=ON/OFF
: use native functions to open file streamsc++utilities
and other libraries exposing that ABI (eg. tagparser
and passwordfile
).c++utilities
, so the option must be specified when building c++utilities
. Specifying it only when building eg. tagparser
has no effect.USE_STANDARD_FILESYSTEM=ON/OFF
: enables use of std::filesystem
(default)USER_DEFINED_ADDITIONAL_LIBRARIES
: specifies additional libraries to link against (added after any other libraries to the linker line)std::filesystem
is covered by use_standard_filesystem(). However, it makes no sense to add such a function for every specific platform/feature. For instance it seems to be required to add "-latomic" to the linker line for armv7-none-linux-androideabi/libc++/clang (not for aarch64-none-linux-androidabi) but it is better to cover such details on packaging-level and only allow to pass such flags here.CMAKE_EXE_LINKER_FLAGS
or CMAKE_SHARED_LINKER_FLAGS
is often not helpful because the additional flags need to be added at the end of the linker line most of the time.CONFIGURATION_NAME
: specifies a name to be incorporated into install paths as a suffixCONFIGURATION_TARGET_SUFFIX
in accordance so library names are affected as well.CONFIGURATION_PACKAGE_SUFFIX
when building consuming libraries to use libraries (and their headers and other files) built with CONFIGURATION_NAME
.NAMESPACE
: specifies a name to be incorporated into install paths as a prefixNAMESPACE=martchus
for c++utilities and qtutilities. Supposedly this should be avoided for developer-facing packaging like vcpkg as it is likely not expected by those users.PACKAGE_NAMESPACE_PREFIX
when building consuming libraries to use libraries (and their headers and other files) built with NAMESPACE
.ENABLE_WARNINGS
: enables GCC/Clang warnings I consider usefulTREAT_WARNINGS_AS_ERRORS
: treat CCC/Clang warnings as errorsENABLE_DEVEL_DEFAULTS
: enables defaults I find useful for development (warnings, treat warnings as errors, build tests as part of all/default target, enable tidy targets, build by default shared libs when targeting GNU/Linux, …)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 one can also just pass the library path directly by specifying the relevant CMake cache variable on the CMake invocation.
FORCE_UTF8_CODEPAGE=ON/OFF
: forces use of UTF-8 codepage in terminalWINDOWS_RESOURCES_ENABLED=ON/OFF
: enables creating resources for application meta data and icon (enabled by default)BUNDLE_INSTALL_DESTINATION=/some/path
: specifies the install destination for application bundles; if not specified, the default bin directory is usedWIDGETS_GUI=ON/OFF
: enables Qt Widgets GUI for projects where it is available and optionalQUICK_GUI=ON/OFF
: enables Qt Quick GUI for projects where it is available and optionalQT_PACKAGE_PREFIX=Qt5
: sets the prefix for Qt packages, by default Qt5
QT_PACKAGE_PREFIX=Qt6
to build against Qt 6KF_PACKAGE_PREFIX=KF5
: sets the prefix for KDE Frameworks packages, by default KF5
ENABLE_QT_TRANSLATIONS=ON/OFF
: enables translations for Qt applications, enabled by defaultBUILTIN_TRANSLATIONS=ON/OFF
: enables built-in translations instead of installing translations as separate filesBUILTIN_TRANSLATIONS_OF_QT=ON/OFF
: enables built-in translations also for Qt's own translation files when building an applicationBUILTIN_TRANSLATIONS
is enabledBUILTIN_TRANSLATIONS
is disabledBUILTIN_ICON_THEMES=breeze;breeze-dark;...
: specifies icon themes to built-inBUILTIN_ICON_THEMES_IN_LIBRARIES=breeze;breeze-dark;...
: same as above but also affects librariesSVG_SUPPORT=ON/OFF
: enables linking against the static SVG image format pluginSVG_ICON_SUPPORT=ON/OFF
: enables linking against the static SVG icon engine plugin provided by the Qt Svg moduleIMAGE_FORMAT_SUPPORT
: enables linking against the specified static image format pluginsqtimageformats
repositoryQT_PLUGIN_DIR
: specified the directory to install Qt plugins toQT_PLUGIN_PATH
environment variable accordingly so the plugin can be found.qmake -query QT_INSTALL_PLUGINS
unless that directory would be outside the specified CMAKE_INSTALL_PREFIX
.WEBVIEW_PROVIDER=auto/webkit/webengine/none
: specifies the Qt module to use for the web viewJS_PROVIDER=qml/script/none
: specifies the Qt module to use for the JavaScript engineWEBVIEW_PROVIDER=webengine/webkit/none
: specifies the Qt module to use for the built-in web viewThe following variables are read by the CMake modules provided by c++utilities and qtutilities.
META_PROJECT_NAME=name
: specifies the project name which is used as the application/library name, mustn't contain spacesMETA_APP_NAME=The Name
: specifies a more readable version of the project name used for instance in about dialog and desktop fileMETA_APP_AUTHOR
: specifies the author shown in for instance in about dialogMETA_APP_DESCRIPTION
: specifies a description shown for instance in about dialog and desktop fileMETA_GENERIC_NAME
: specifies a generic name for the desktop fileMETA_VERSION_MAJOR/MINOR/PATCH=number
: specifies the application/library version, default is 0META_PROJECT_TYPE=application/library/plugin/qtplugin
: specifies whether to build an application, a library or a pluginMETA_CXX_STANDARD=11/14/..
: specifies the C++ version, default is 14META_NO_TIDY
: disables availability of enabling formatting via CLANG_FORMAT_ENABLED
for this projectMETA_NO_INSTALL_TARGETS
: the project is not meant to be installed, eg. private test helper; prevents creation of install targetsMETA_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION
: implicitly add a source file with a main()-entry point to test target for running CppUnit test casesTLS_SUPPORT
: enables TLS supportMETA_TLS_PLUGINS
: specifies an additional list of Qt TLS plugins to check before the known TLS pluginsHEADER_FILES
/SRC_FILES
: specifies C++ header/source filesTEST_HEADER_FILES
/TEST_SRC_FILES
: specifies C++ header/source files of the testsTS_FILES
: specifies Qt translationsRES_FILES
: specifies Qt resource filesDBUS_FILES
: specifies files for Qt DBusWIDGETS_HEADER_FILES
/WIDGETS_SRC_FILES
: specifies C++ header/source files only required for Qt Widgets GUIQML_HEADER_FILES
/QML_SRC_FILES
/QML_RES_FILES
: specifies C++ header/source files and Qt resource files only required for Qt Quick GUIEXCLUDED_FILES
: specifies C++ files which are part of the project (and therefore should be formatted by the tidy
target, added to the documentation and considered for translations) but are excluded from the actual build; when adding files conditionally to the other _FILES
variables, be sure to add them at least to EXCLUDED_FILES
DOC_FILES
: additional markdown files to be included in the documentation created via Doxygen; the first file is used as the main pageREQUIRED_ICONS
: names of the icons required by the application and the used libraries (can be generated with findicons)CMAKE_MODULE_FILES
/CMAKE_TEMPLATE_FILES
: specifies CMake modules/templates provides by the project; those files are installed so they can be used by other projectsMETA_PRIVATE_COMPILE_DEFINITIONS
/META_PUBLIC_COMPILE_DEFINITIONS
: specifies private/public compile definitionsMETA_PRIVATE_COMPILE_OPTIONS
/META_PUBLIC_COMPILE_OPTIONS
: specifies private/public compile optionsMETA_SOVERSION
: specifies the soversion for libraries (defaults to META_VERSION_MAJOR
)PUBLIC_LIBRARIES
/PRIVATE_LIBRARIES
: specifies the public/private libraries to link againstPUBLIC_INCLUDE_DIRS
/PRIVATE_INCLUDE_DIRS
: specifies the public/private include directoriesADDITIONAL_QT_MODULES
: specifies additional Qt modules to link againstADDITIONAL_KF_MODULES
: specifies additional KDE frameworks modules to link againstMETA_QT_VERSION
: specifies the minimum Qt version to requirec++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:
BaseConfig
: does basic configuration, reads most of the META
-variablesQtConfig
: does basic Qt-related configuration, reads most of the Qt-specific variables documented aboveQtGuiConfig
: does Qt-related configuration for building a Qt Widgets or Qt Quick based GUI application/libraryQtConfig
WebViewProviderConfig
: configures the webview providerLibraryTarget
: does further configuration for building dynamic and static libraries and plugins; META_PROJECT_TYPE
can be left empty or set explicitly to library
AppTarget
: does further configuration for building an application; META_PROJECT_TYPE
must be set to application
ShellCompletion
: enables shell completionApplicationUtilities::ArgumentParser
class of courseTestTarget
: adds the test target check
check
target is not required by target all
TEST_HEADER_FILES
/TEST_SRC_FILES
variablescppunit
which is the test framework used by most my projects; set META_NO_CPP_UNIT=OFF
in the project file to prevent thisTestUtilities
: provides the configure_test_target
macro for creating test targets manuallyCMakeLists.txt
of qtutilities
for an exampleAndroidApk
: adds a target to create an APK package for Android using androiddeployqt, ignored on other platformsDoxygen
: adds a target to generate documentation using DoxygenWindowsResources
: handles creation of Windows resources to set application meta data and icon, ignored on other platformsConfigHeader
: generates resources/config.h
, must be included as the last module (when all configuration is done)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, ...).