3 \brief Documents variables to control the build system and provided CMake
6 ## Variables passable as CMake arguments
8 ### Useful variables provided by CMake itself
9 * `CMAKE_INSTALL_PREFIX=path`: specifies the final install prefix (temporary
10 install prefix is set via `make` argument `DESTDIR=path`)
11 * `CMAKE_BUILD_TYPE=Release/Debug`: specifies whether to do a debug or a release
13 * `CMAKE_SKIP_BUILD_RPATH=OFF`: ensures the rpath is set in the build tree
14 * `CMAKE_INSTALL_RPATH=rpath`: sets the rpath used when installing
15 * `CMAKE_CXX_FLAGS`: sets flags to be passed to the C++ compiler
18 The following variables are read by the CMake modules provided by c++utilities
21 None of these are enabled or set by default, unless stated otherwise.
23 * `LIB_SUFFIX=suffix`: suffix for library install directory
24 * `LIB_SUFFIX_32=suffix`: suffix for library install directory
25 * used when building for 32-bit platforms
26 * overrides general `LIB_SUFFIX` when building for 32-bit platforms
27 * `LIB_SUFFIX_64=suffix`: suffix for library install directory
28 * used when building for 64-bit platforms
29 * overrides general `LIB_SUFFIX` when building for 64-bit platforms
30 * `ENABLE_STATIC_LIBS=ON/OFF`: enables building static libs
31 * `DISABLE_SHARED_LIBS=ON/OFF`: disables building shared libs
32 * `STATIC_LINKAGE=ON/OFF`: enables linking applications *preferably* against
34 * by default dynamic libraries are preferred
35 * only affect building applications
36 * `STATIC_LIBRARY_LINKAGE=ON/OFF`: enables linking dynamic libraries *preferably*
37 against static libraries
38 * by default linking against dynamic libraries is preferred
39 * only affects building dynamic libraries (static libraries are just archives
40 of objects and hence *not linked* against their dependencies when being built)
41 * note that static libraries are always preferred to provide the dependency
42 of another static library
43 * eg. linking against static `c++utilities` requires also linking against
44 its dependency `iconv`; the static version of `iconv` is preferred
45 * this behaviour has actually nothing to do with `STATIC_LIBRARY_LINKAGE`
46 and can currently not be controlled
47 * `SHELL_COMPLETION_ENABLED=ON/OFF`: enables shell completion in general
49 * `BASH_COMPLETION_ENABLED=ON/OFF`: enables Bash completion (enabled by
51 * `LOGGING_ENABLED=ON/OFF`: enables further loggin in some applications
52 * `FORCE_OLD_ABI=ON/OFF`: forces use of old C++ ABI
53 * sets `_GLIBCXX_USE_CXX11_ABI=0`
54 * only relevant when using libstdc++
55 * `EXCLUDE_TESTS_FROM_ALL=ON/OFF`: excludes tests from the all target
57 * `APPEND_GIT_REVISION=ON/OFF`: whether the build script should attempt to
58 append the Git revision and the latest commit ID to the version
59 * displayed via `--help`
60 * enabled by default but has no effect when the source directory is
61 no Git checkout or Git is not installed
62 * `CLANG_FORMAT_ENABLED=ON/OFF`: enables tidy target for code formatting via
64 * can be made unavailable by setting `META_NO_TIDY` in the project file
65 * only available if format rules are available
66 * also enables tidy check executed via `check` target
67 * `CLANG_SOURCE_BASED_COVERAGE_ENABLED=ON/OFF`: enables `coverage` target to
68 determine source-based test coverage using Clang/llvm
69 * only available when building with Clang under UNIX
70 * coverage report is stored in build directory
71 * `ENABLE_INSTALL_TARGETS=ON/OFF`: enables creation of install targets (enabled
74 #### Variables for specifying location of 3rd party dependencies
75 The build script tries to find the required dependencies at standard loctions
76 using the CMake functions
77 [`find_library`](https://cmake.org/cmake/help/latest/command/find_library.html)
79 [`find_package`](https://cmake.org/cmake/help/latest/command/find_package.html).
80 The behaviour of those functions can be controlled by setting some variables, eg.
81 using a toolchain file. Checkout the CMake documentation for this.
83 If the detection does not work as expected or a library from a non-standard
84 location should be used, the following variables can be used to specify
85 the location of libraries and include directories directly:
87 * `dependency_DYNAMIC_LIB`: specifies the locations of the dynamic libraries
89 * `dependency_STATIC_LIB`: specifies the locations of the static libraries
91 * `dependency_DYNAMIC_INCLUDE_DIR`: specifies the locations of the additional
92 include directories required for using the dynamic version of the *dependency*
93 * `dependency_STATIC_INCLUDE_DIR`: specifies the locations of the additional
94 include directories required for using the static version of the *dependency*
96 Example of passing location of dynamic `iconv` and `zlib` to CMake:
98 /opt/osxcross/bin/x86_64-apple-darwin15-cmake \
99 -Diconv_DYNAMIC_LIB:FILEPATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/lib/libiconv.2.tbd \
100 -Diconv_DYNAMIC_INCLUDE_DIR:PATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/include \
101 -Dz_DYNAMIC_LIB:FILEPATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/lib/libz.1.tbd \
102 -Dz_DYNAMIC_INCLUDE_DIR:PATH=/opt/osxcross/SDK/MacOSX10.11.sdk/usr/include \
106 *Note about Qt*: Qt modules must be located via `find_package`. So using the variables
107 described above to specify a custom location does not work. Instead, the
108 variable `CMAKE_PREFIX_PATH` can be used to specify the install prefix of the
109 Qt build to use. Set `QT_LINKAGE` to `STATIC` if it is a static build of Qt.
111 #### Windows specific
112 * `USE_NATIVE_FILE_BUFFER=ON/OFF`: use native function to open file streams
113 to pass unicode file names correctly
114 * Changing this option alters the ABI of `c++utilities` and libraries using
115 that feature (eg. `tagparser`).
116 * This feature is implemented in `c++utilities`, so the option must be specified
117 when building `c++utilities`. Specifying it only when building eg. `tagparser`
119 * `FORCE_UTF8_CODEPAGE=ON/OFF`: forces use of UTF-8 codepage in terminal
120 * `WINDOWS_RESOURCES_ENABLED=ON/OFF`: enables creating resources for
121 application meta data and icon (enabled by default)
124 * `BUNDLE_INSTALL_DESTINATION=/some/path`: specifies the install destination for
125 application bundles; if not specified, the default bin directory is used
128 * `WIDGETS_GUI=ON/OFF`: enables Qt Widgets GUI for projects where it is
129 available and optional
130 * `QUICK_GUI=ON/OFF`: enables Qt Quick GUI for projects where it is available
132 * `BUILTIN_TRANSLATIONS=ON/OFF`: enables built-in translations in applications
133 * `BUILTIN_ICON_THEMES=breeze;breeze-dark;...`: specifies icon themes to
135 * `BUILTIN_ICON_THEMES_IN_LIBRARIES=breeze;breeze-dark;...`: same as above but
136 also affects libraries
137 * `SVG_SUPPORT=ON/OFF`: enables linking against the static SVG image format
140 * requires the Qt Svg module
141 * only relevant when using static Qt
142 * `SVG_ICON_SUPPORT=ON/OFF`: enables linking against the static SVG icon engine
143 plugin provided by the Qt Svg module
145 * requires the Qt Svg module
146 * only relevant when using static Qt
147 * required to use Breeze icon theme (or any other SVG icon theme)
148 * `IMAGE_FORMAT_SUPPORT`: enables linking against the specified static image
150 * comma-separated list
151 * by default set to "Gif;ICO;Jpeg", so support for Gif, ICO and Jpeg is
153 * note that PNG support is not provided via a plugin, so it should be
154 always available and not be affected by this option
155 * further image formats require building the plugins contained by the
156 additional `qtimageformats` repository
157 * only relevant when using static Qt
158 * `WEBVIEW_PROVIDER=auto/webkit/webengine/none`: specifies the Qt module to use
160 * `JS_PROVIDER=auto/script/qml/none`: specifies the Qt module to use
161 for the JavaScript engine
162 * `QT_LINKAGE=AUTO_LINKAGE/STATIC/SHARED`: specifies whether to use static
163 or shared version of Qt (only works with Qt packages provided in the AUR)
164 * `ADDITIONAL_QT_MODULES=Network;Concurrent;...`: specifies additional Qt
165 modules to link against (only use for modules which can not be added
169 ## Variables to be set in project file
170 The following variables are read by the CMake modules provided by c++utilities
174 * `META_PROJECT_NAME=name`: specifies the project name which is used as the
175 application/library name, mustn't contain spaces
176 * `META_APP_NAME=The Name`: specifies a more readible version of the project
177 name used for instance in about dialog and desktop file
178 * `META_APP_AUTHOR`: specifies the author shown in for instance in about
180 * `META_APP_DESCRIPTION`: specifies a description shown for instance in about
181 dialog and desktop file
182 * `META_GENERIC_NAME`: specifies a generic name for the desktop file
183 * `META_VERSION_MAJOR/MINOR/PATCH=number`: specifies the application/library
184 version, default is 0
185 * `META_PROJECT_TYPE=application/library/plugin/qtplugin`: specifies whether
186 to build an application, a library or a plugin
187 * `META_CXX_STANDARD=11/14/..`: specifies the C++ version, default is 14
188 * `META_NO_TIDY`: disables availability of enabling formatting via
189 `CLANG_FORMAT_ENABLED` for this project
190 * `META_NO_INSTALL_TARGETS`: the project is not meant to be installed, eg.
191 private test helper; prevents creation of install targets
194 * `HEADER_FILES`/`SRC_FILES`: specifies C++ header/source files
195 * `TEST_HEADER_FILES`/`TEST_SRC_FILES`: specifies C++ header/source files of the
197 * `TS_FILES`: specifies Qt translations
198 * `RES_FILES`: specifies Qt resource files
199 * `DBUS_FILES`: specifies files for Qt DBus
200 * `WIDGETS_HEADER_FILES`/`WIDGETS_SRC_FILES`: specifies C++ header/source files
201 only required for Qt Widgets GUI
202 * `QML_HEADER_FILES`/`QML_SRC_FILES`/`QML_RES_FILES`: specifies C++
203 header/source files and Qt resouce files only required for Qt Quick GUI
204 * `DOC_FILES`: additional markdown files to be inlcuded in the documentation
205 created via Doxygen; the first file is used as the main page
206 * `DOC_ONLY_FILES`: specifies documentation-only files
207 * `REQUIRED_ICONS`: names of the icons required by the application and the
208 used libraries (can be generated with `qtutilities/scripts/required_icons.sh`)
209 * `CMAKE_MODULE_FILES`/`CMAKE_TEMPLATE_FILES`: specifies CMake modules/templates
210 provides by the project; those files are installed so they can be used by
213 ### Additional build variables
214 * `META_PRIVATE/PUBLIC_COMPILE_DEFINITIONS`: specifies private/public compile
216 * `LIBRARIES`: specifies libraries to link against
217 * `META_PUBLIC_QT_MODULES`: specifies Qt modules used in the public library
219 * `META_PUBLIC_SHARED_LIB_DEPENDS`: specifies shared libraries used in the public
221 * `META_PUBLIC_STATIC_LIB_DEPENDS`: specifies static libraries used in the public
225 c++utilities and qtutilities provide CMake modules to reduce boilerplate code
226 in the CMake files of my projects. Those modules implement the functionality
227 controlled by the variables documented above. Most important modules are:
229 * `BaseConfig`: does basic configuration, reads most of the `META`-variables
230 * `QtConfig`: does basic Qt-related configuration, reads most of the Qt-specific
231 variables documented above
232 * `QtGuiConfig`: does Qt-related configuration for building a Qt Widgets or
233 Qt Quick based GUI application/library
234 * must be included *before* `QtConfig`
235 * `WebViewProviderConfig`: configures the webview provider
236 * used by Tag Editor and Syncthing Tray to select between Qt WebEngine,
237 Qt WebKit or disabling the built-in webview
238 * `LibraryTarget`: does further configuration for building dynamic and static
239 libraries and plugins; `META_PROJECT_TYPE` can be left empty or set explicitely
241 * `AppTarget`: does further configuration for building an application;
242 `META_PROJECT_TYPE` must be set to `application`
243 * `ShellCompletion`: enables shell completion
244 * only works when using the argument parser provided by the
245 `ApplicationUtilities::ArgumentParser` class of course
246 * `TestTarget`: adds the test target `check`
247 * `check` target is *not* required by target `all`
248 * test target uses files specified in `TEST_HEADER_FILES`/`TEST_SRC_FILES`
250 * test target will automatically link against `cppunit` which is the test
251 framework used by all my projects; set `META_NO_CPP_UNIT=OFF` in the project
253 * `Doxygen`: adds a target to generate documentation using Doxygen
254 * `WindowsResources`: handles creation of Windows resources to set application
255 meta data and icon, ignored on other platforms
256 * `ConfigHeader`: generates `resources/config.h`, must be included as the last
257 module (when all configuration is done)
259 Since those modules make use of the variables explained above, the modules must
260 be included *after* setting those variables. The inclusion order of the modules
263 For an example, checkout the project file of c++utilities itself. The project
264 files of [Syncthing Tray](https://github.com/Martchus/syncthingtray) should
265 cover everything (library, plugin, application, tests, desktop file, Qt
266 resources and translations, ...).