ECM-KDE-MODULES(7) Extra CMake Modules ECM-KDE-MODULES(7) NAME ecm-kde-modules - ECM KDE Modules Reference INTRODUCTION Extra CMake Modules (ECM) provides several modules that provide default settings (like installation directories, compiler flags and other CMake options) aimed at software produced by the KDE modules; these are documented here. ECM also provides modules with more general functionality, documented in ecm-modules(7), and ones that extend the functionality of the find_package command, documented in ecm-find-modules(7). To use these modules, you need to tell CMake to find the ECM package, and then add either ${ECM_MODULE_PATH} or ${ECM_KDE_MODULE_DIR} to the CMAKE_MODULE_PATH variable: find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_DIR}) Using ${ECM_MODULE_PATH} will also make the other types of modules available. ALL KDE MODULES KDECMakeSettings Changes various CMake settings to what the KDE community views as more sensible defaults. It is recommended to include this module with the NO_POLICY_SCOPE flag, otherwise you may get spurious warnings with some versions of CMake. It is split into three parts, which can be independently disabled if desired. Runtime Paths The default runtime path (used on Unix systems to search for dynamically-linked libraries) is set to include the location that libraries will be installed to (as set in LIB_INSTALL_DIR or, if the former is not set, KDE_INSTALL_LIBDIR), and also the linker search path. NOTE: LIB_INSTALL_DIR or alternatively KDE_INSTALL_LIBDIR needs to be set before including this module. Typically, this is done by including the KDEInstallDirs module. This section can be disabled by setting KDE_SKIP_RPATH_SETTINGS to TRUE before including this module. Testing Testing is enabled by default, and an option BUILD_TESTING is provided for users to control this. See the CTest module documentation in the CMake manual for more details. This section can be disabled by setting KDE_SKIP_TEST_SETTINGS to TRUE before including this module. Build Settings Various CMake build defaults are altered, such as searching source and build directories for includes first, enabling automoc by default. When find_package(ECM 5.38) or higher is called, this also selects a layout for the build dir that helps running executables without installing: all executables are built into a toplevel "bin" dir, making it possible to find helper binaries, and to find uninstalled plugins (provided that you use kcoreaddons_add_plugin() or set LIBRARY_OUTPUT_DIRECTORY as documented on https://community.kde.org/Guidelines_and_HOWTOs/Making_apps_run_uninstalled). This section can be disabled by setting KDE_SKIP_BUILD_SETTINGS to TRUE before including this module. This section also provides an uninstall target that can be individually disabled by setting KDE_SKIP_UNINSTALL_TARGET to TRUE before including this module. By default on OS X, X11 and XCB related detections are disabled. However if the need would arise to use these technologies, the detection can be enabled by setting APPLE_FORCE_X11 to ON. A warning is printed for the developer to know that the detection is disabled on OS X. This message can be turned off by setting APPLE_SUPPRESS_X11_WARNING to ON. Since pre-1.0.0. ENABLE_CLAZY option is added (OFF by default) when clang is being used. Turning this option on will force clang to load the clazy plugins for richer warnings on Qt-related code. If clang is not being used, this won't have an effect. See https://commits.kde.org/clazy?path=README.md Since 5.17.0 o uninstall target functionality since 1.7.0 o APPLE_FORCE_X11 option since 5.14.0 (detecting X11 was previously the default behavior) o APPLE_SUPPRESS_X11_WARNING option since 5.14.0 o CMAKE_AUTORCC enabled by default when supported by CMake (>= 3.0) since 5.62.0 Translations (deprecated) A fetch-translations target will be set up that will download translations for projects using l10n.kde.org. KDE_L10N_BRANCH will be responsible for choosing which l10n branch to use for the translations. KDE_L10N_AUTO_TRANSLATIONS (OFF by default) will indicate whether translations should be downloaded when building the project. Since 5.34.0 KDE_L10N_SYNC_TRANSLATIONS (OFF by default) will download the translations at configuration time instead of build time. Since 5.50.0 All KDE_L10N_* options have been deprecated since 5.102.0, as translations are meanwhile present inside the source code repositories. KDEClangFormat This module provides a functionality to format the source code of your repository according to a predefined KDE clang-format file. This module provides the following function: kde_clang_format() Using this function will create a clang-format target that will format all passed to the function with the predefined KDE clang-format style. To format the files you have to invoke the target with make clang-format or ninja clang-format. Once the project is formatted it is recommended to enforce the formatting using a pre-commit hook, this can be done using KDEGitCommitHooks. The .clang-format file from ECM will be copied to the source directory. This file should not be added to version control. It is recommended to add it to the .gitignore file: /.clang-format. Since 5.79: If the source folder already contains a .clang-format file it is not overwritten. Since version 5.80 this function is called by default in KDEFrameworkCompilerSettings. If directories should be excluded from the formatting a .clang-format file with DisableFormat: true and SortIncludes: false should be created. Example usage: include(KDEClangFormat) file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.hpp *.c) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) To exclude directories from the formatting add a .clang-format file in the directory with the following contents: DisableFormat: true SortIncludes: false Since 5.64 KDECompilerSettings Set useful compile and link flags for C++ (and C) code. Enables many more warnings than the default, and sets stricter modes for some compiler features. By default, exceptions are disabled; kde_target_enable_exceptions() can be used to re-enable them for a specific target. NOTE: It is recommended to include this module with the NO_POLICY_SCOPE flag, otherwise you may get spurious warnings with some versions of CMake. Since 5.85 newer settings are controlled by a variable KDE_COMPILERSETTINGS_LEVEL, taking an ECM version as value. That version can not be greater than the minimum required ECM version. The settings which are default at that version will then be used, but can be overridden by more fine-grained controls (see respective settings). This variable needs to be set before including this module, otherwise defaults to the minimum required ECM version. Modern code The following CMake C standard default variables are set: For KDE_COMPILERSETTINGS_LEVEL >= 5.85: o CMAKE_C_STANDARD: 99 o CMAKE_C_STANDARD_REQUIRED: TRUE o CMAKE_C_EXTENSIONS: OFF Otherwise: o CMAKE_C_STANDARD: 90 o CMAKE_C_STANDARD_REQUIRED: not modified o CMAKE_C_EXTENSIONS: not modified If the variable CMAKE_C_STANDARD is already set when including this module, none of the above variables will be modified. The following CMake C++ standard default variables are set: For KDE_COMPILERSETTINGS_LEVEL >= 5.85: o CMAKE_CXX_STANDARD: 17 o CMAKE_CXX_STANDARD_REQUIRED: TRUE o CMAKE_CXX_EXTENSIONS: OFF Otherwise: o CMAKE_CXX_STANDARD: 11 o CMAKE_CXX_STANDARD_REQUIRED: TRUE o CMAKE_CXX_EXTENSIONS: not modified. If the variable CMAKE_CXX_STANDARD is already set when including this module, none of the above variables will be modified. The following C++ compiler flags are set: o -pedantic (GNU and Clang compilers, since 5.85) Can be disabled by setting KDE_SKIP_PEDANTIC_WARNINGS_SETTINGS to TRUE before including this module (default is FALSE for KDE_COMPILERSETTINGS_LEVEL >= 5.85, TRUE otherwise). o -Wmissing-include-dirs (GNU compilers, since 5.85) Can be disabled by setting KDE_SKIP_MISSING_INCLUDE_DIRS_WARNINGS_SETTINGS to TRUE before including this module (default is FALSE for KDE_COMPILERSETTINGS_LEVEL >= 5.85, TRUE otherwise). o -Wzero-as-null-pointer-constant (GNU and Clang compilers, since 5.85) Can be disabled by setting KDE_SKIP_NULLPTR_WARNINGS_SETTINGS to TRUE before including this module (default is FALSE for KDE_COMPILERSETTINGS_LEVEL >= 5.85, TRUE otherwise). o -Werror=undef (GNU and Clang compilers, since 5.96.0) o Qt related preprocessor definitions (since 5.85.0): o -DQT_NO_CAST_TO_ASCII o -DQT_NO_CAST_FROM_ASCII o -DQT_NO_URL_CAST_FROM_STRING o -DQT_NO_CAST_FROM_BYTEARRAY o -DQT_USE_QSTRINGBUILDER o -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT o -DQT_NO_KEYWORDS o -DQT_NO_FOREACH o -DQT_STRICT_ITERATORS Strict iterators are not enabled on Windows, because they lead to a link error when application code iterates over a QVector for instance, unless Qt itself was also built with strict iterators. See example at https://bugreports.qt.io/browse/AUTOSUITE-946 Can be controlled by setting KDE_QT_MODERNCODE_DEFINITIONS_LEVEL to the version of ECM where the wanted set of definitions has been added before including this module (default is KDE_COMPILERSETTINGS_LEVEL). To disable individual definitions instead use remove_definitions() directly after including this module. Functions This module provides the following functions: kde_source_files_enable_exceptions([file1 [file2 [...]]]) Enables exceptions for specific source files. This should not be used on source files in a language other than C++. kde_target_enable_exceptions(target ) Enables exceptions for a specific target. This should not be used on a target that has source files in a language other than C++. kde_enable_exceptions() Enables exceptions for C++ source files compiled for the CMakeLists.txt file in the current directory and all subdirectories. Variables Inclusion of this module defines the following variables: ENABLE_BSYMBOLICFUNCTIONS indicates whether we make use of -Bsymbolic-functions for linking. It ensures libraries bind global function references locally rather than at runtime. This option only has an effect on ELF-based systems. The option is disabled by default except when using KDEFrameworkCompilerSettings where it's enabled. Projects can enable it by calling set(ENABLE_BSYMBOLICFUNCTIONS ON) or passing -DENABLE BSYMBOLICFUNCTIONS=ON when configuring the build directory. Since 5.85 Example usages: # needing some macro/feature only available with ECM 5.80.0 find_package(ECM 5.80.0 NO_MODULE) # requiring ECM 5.80.0 above will default KDE_COMPILERSETTINGS_LEVEL also to 5.80.0, # thus not activate any newer settings include(KDECompilerSettings NO_POLICY_SCOPE) # needing some macro/feature only available with ECM 5.87.0 find_package(ECM 5.87.0 NO_MODULE) # project uses settings default as of KDECompilerSettings in ECM 5.85.0 set(KDE_COMPILERSETTINGS_LEVEL 5.85.0) include(KDECompilerSettings NO_POLICY_SCOPE) # needing some macro/feature only available with ECM 5.87.0 find_package(ECM 5.87.0 NO_MODULE) # project mainly uses settings default as of KDECompilerSettings in ECM 5.85.0 # with some small twisting set(KDE_COMPILERSETTINGS_LEVEL 5.85.0) # not ready yet for pedantic compilers set(KDE_SKIP_PEDANTIC_WARNINGS_SETTINGS TRUE) # avoid any Qt definitions set(KDE_QT_MODERNCODE_DEFINITIONS_LEVEL 5.84.0) include(KDECompilerSettings NO_POLICY_SCOPE) # needing some macro/feature only available with ECM 5.85.0 find_package(ECM 5.85.0 NO_MODULE) # requiring ECM 5.85.0 above will default KDE_COMPILERSETTINGS_LEVEL also to 5.85.0, # which again defaults KDE_QT_MODERNCODE_DEFINITIONS_LEVEL also to 5.85.0 include(KDECompilerSettings NO_POLICY_SCOPE) # project is fine with almost all added Qt definitions as of 5.85.0, but not these ones: remove_definitions( -DQT_NO_KEYWORDS -DQT_NO_FOREACH ) Since pre-1.0.0. KDEFrameworkCompilerSettings Set stricter compile and link flags for KDE Frameworks modules. WARNING: Do not use this module for software which is not part of KDE-Frameworks. There is no guarantee for backward-compatibility in newer versions. The KDECompilerSettings module is included and, in addition, various defines that affect the Qt libraries are set to enforce certain conventions. For example, constructions like QString("foo") are prohibited, instead forcing the use of QLatin1String or QStringLiteral, and some Qt-defined keywords like signals and slots will not be defined. NOTE: It is recommended to include this module with the NO_POLICY_SCOPE flag, otherwise you may get spurious warnings with some versions of CMake. Since pre-1.0.0. KDEGitCommitHooks This module provides a functionality to enforce formatting or in the future other QS checks. This module provides the following function: kde_configure_git_pre_commit_hook( CHECKS [ [...] [CUSTOM_SCRIPTS [