Advance Wayland and KDE package bring-up

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-04-14 10:51:06 +01:00
parent 51f3c21121
commit cf12defd28
15214 changed files with 20594243 additions and 269 deletions
@@ -0,0 +1,390 @@
# SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>
# SPDX-FileCopyrightText: 2013 Aleix Pol <aleixpol@kde.org>
# SPDX-FileCopyrightText: 2012-2013 Stephen Kelly <steveire@gmail.com>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
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 :kde-module:`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
- ``uninstall`` target functionality since 1.7.0
- ``APPLE_FORCE_X11`` option since 5.14.0 (detecting X11 was previously the default behavior)
- ``APPLE_SUPPRESS_X11_WARNING`` option since 5.14.0
- ``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.
#]=======================================================================]
################# RPATH handling ##################################
if(NOT KDE_SKIP_RPATH_SETTINGS)
# Set the default RPATH to point to useful locations, namely where the
# libraries will be installed and the linker search path
# First look for the old LIB_INSTALL_DIR, then fallback to newer KDE_INSTALL_LIBDIR
if(NOT LIB_INSTALL_DIR)
if(NOT KDE_INSTALL_LIBDIR)
message(FATAL_ERROR "Neither KDE_INSTALL_LIBDIR nor LIB_INSTALL_DIR is set. Setting one is necessary for using the RPATH settings.")
else()
set(_abs_LIB_INSTALL_DIR "${KDE_INSTALL_LIBDIR}")
endif()
else()
set(_abs_LIB_INSTALL_DIR "${LIB_INSTALL_DIR}")
endif()
if (NOT IS_ABSOLUTE "${_abs_LIB_INSTALL_DIR}")
set(_abs_LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${_abs_LIB_INSTALL_DIR}")
endif()
if (UNIX)
# for macOS: add install name dir in addition
# check: is the rpath stuff below really required on macOS? at least it seems so to use a stock qt from qt.io
if (APPLE)
set(CMAKE_INSTALL_NAME_DIR ${_abs_LIB_INSTALL_DIR})
endif ()
# add our LIB_INSTALL_DIR to the RPATH (but only when it is not one of
# the standard system link directories - such as /usr/lib on UNIX)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemLibDir)
list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemCxxLibDir)
list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemCLibDir)
if("${_isSystemLibDir}" STREQUAL "-1" AND "${_isSystemCxxLibDir}" STREQUAL "-1" AND "${_isSystemCLibDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${_abs_LIB_INSTALL_DIR}")
endif()
# Append directories in the linker search path (but outside the project)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif (UNIX)
endif()
################ Testing setup ####################################
find_program(APPSTREAMCLI appstreamcli)
function(appstreamtest)
cmake_policy(PUSH)
cmake_policy(SET CMP0064 NEW) # enable TEST operator
if(TEST appstreamtest)
# already configured
elseif(APPSTREAMCLI)
add_test(NAME appstreamtest COMMAND ${CMAKE_COMMAND} -DAPPSTREAMCLI=${APPSTREAMCLI} -DINSTALL_FILES=${CMAKE_BINARY_DIR}/install_manifest.txt -P ${CMAKE_CURRENT_LIST_DIR}/appstreamtest.cmake)
else()
message(STATUS "Could not set up the appstream test. appstreamcli is missing.")
endif()
cmake_policy(POP)
endfunction()
if(NOT KDE_SKIP_TEST_SETTINGS)
# If there is a CTestConfig.cmake, include CTest.
# Otherwise, there will not be any useful settings, so just
# fake the functionality we care about from CTest.
if (EXISTS ${CMAKE_SOURCE_DIR}/CTestConfig.cmake)
include(CTest)
else()
option(BUILD_TESTING "Build the testing tree." ON)
if(BUILD_TESTING)
enable_testing()
appstreamtest()
endif ()
endif ()
endif()
################ Build-related settings ###########################
if(NOT KDE_SKIP_BUILD_SETTINGS)
# Always include srcdir and builddir in include path
# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} in about every subdir
# since cmake 2.4.0
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# put the include dirs which are in the source or build tree
# before all other include dirs, so the headers in the sources
# are preferred over the already installed ones
# since cmake 2.4.1
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
# Add the src and build dir to the BUILD_INTERFACE include directories
# of all targets. Similar to CMAKE_INCLUDE_CURRENT_DIR, but transitive.
# Since CMake 2.8.11
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
# When a shared library changes, but its includes do not, don't relink
# all dependencies. It is not needed.
# Since CMake 2.8.11
set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
# Default to shared libs for KDE, if no type is explicitly given to add_library():
set(BUILD_SHARED_LIBS TRUE CACHE BOOL "If enabled, shared libs will be built by default, otherwise static libs")
# Enable automoc in cmake
# Since CMake 2.8.6
set(CMAKE_AUTOMOC ON)
# Enable autorcc and in cmake so qrc files get generated.
# Since CMake 3.0
# TODO KF6: discuss enabling AUTOUIC and note porting requirements. autouic
# acts on all #include "ui_*.h" assuming *.ui exists
set(CMAKE_AUTORCC ON)
# By default, create 'GUI' executables. This can be reverted on a per-target basis
# using ECMMarkNonGuiExecutable
# Since CMake 2.8.8
set(CMAKE_WIN32_EXECUTABLE ON)
set(CMAKE_MACOSX_BUNDLE ON)
# By default, don't put a prefix on MODULE targets. add_library(MODULE) is basically for plugin targets,
# and in KDE plugins don't have a prefix.
set(CMAKE_SHARED_MODULE_PREFIX "")
unset(EXECUTABLE_OUTPUT_PATH)
unset(LIBRARY_OUTPUT_PATH)
unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
# under Windows, output all executables and dlls into
# one common directory, and all static|import libraries and plugins
# into another one. This way test executables can find their dlls
# even without installation.
# We do the same under Unix to make it possible to run tests and apps without installing
if (WIN32 OR ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.38.0)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
# For Android we need to put shared libraries into "lib" for androiddeployqt to work without prior installation.
# That fact that this conflicts with the above isn't really an issue, as we can't run things while cross-compiling
# for Android anyway.
if (ANDROID)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
endif()
if (APPLE)
# Disable detection of X11 and related package on OS X because when using
# brew or macports, X11 can be installed and thus is detected.
option(APPLE_FORCE_X11 "Force enable X11 related detection on OS X" OFF)
option(APPLE_SUPPRESS_X11_WARNING "Suppress X11 and related technologies search disabling warning on OS X" OFF)
if(NOT APPLE_FORCE_X11)
if (NOT APPLE_SUPPRESS_X11_WARNING)
message(WARNING "Searching for X11 and related technologies is disabled on Apple systems. Set APPLE_FORCE_X11 to ON to change this behaviour. Set APPLE_SUPPRESS_X11_WARNING to ON to hide this warning.")
endif()
set(CMAKE_DISABLE_FIND_PACKAGE_X11 true)
set(CMAKE_DISABLE_FIND_PACKAGE_XCB true)
set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true)
endif()
endif()
option(KDE_SKIP_UNINSTALL_TARGET "Prevent an \"uninstall\" target from being generated." OFF)
if(NOT KDE_SKIP_UNINSTALL_TARGET)
include("${ECM_MODULE_DIR}/ECMUninstallTarget.cmake")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
option(ENABLE_CLAZY "Enable Clazy warnings" OFF)
if(ENABLE_CLAZY)
find_library(CLAZY_v1_5_FOUND ClazyPlugin${CMAKE_SHARED_LIBRARY_SUFFIX})
if(CLAZY_v1_5_FOUND) # clazy >= 1.5
set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClazyPlugin${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clazy")
else() # clazy < 1.5
set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClangLazy${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clang-lazy")
endif()
endif()
endif()
###################################################################
# Download translations
function(_repository_name reponame dir)
execute_process(COMMAND git rev-parse --symbolic-full-name @{u}
OUTPUT_VARIABLE upstream_ref
RESULT_VARIABLE exitCode
WORKING_DIRECTORY "${dir}")
if(exitCode EQUAL 0)
string(REGEX REPLACE "refs/remotes/([^/]+)/.*" "\\1" gitorigin "${upstream_ref}")
message(DEBUG "Git upstream inferred as ${gitorigin}, upstream ref was ${upstream_ref}")
else()
set(gitorigin "origin")
message(DEBUG "Assuming origin as the git remote as we are in detached mode")
endif()
execute_process(COMMAND git remote get-url --all "${gitorigin}"
OUTPUT_VARIABLE giturl
RESULT_VARIABLE exitCode
WORKING_DIRECTORY "${dir}")
if(exitCode EQUAL 0)
message(DEBUG "Git URL inferred as ${giturl}")
string(REGEX MATCHALL ".+kde\\.org[:\\/]([-A-Za-z0-9\\/]+)(.git)?\\s*" "" ${giturl})
set(${reponame} ${CMAKE_MATCH_1})
message(DEBUG "Repository inferred as ${${reponame}}")
endif()
if(NOT ${reponame})
set(${reponame} ${CMAKE_PROJECT_NAME})
endif()
set(${reponame} ${${reponame}} PARENT_SCOPE)
endfunction()
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/po AND NOT TARGET fetch-translations)
option(KDE_L10N_AUTO_TRANSLATIONS "Automatically 'make fetch-translations`" OFF)
option(KDE_L10N_SYNC_TRANSLATIONS "Fetch translations when KDECMakeSettings.cmake is processed." OFF)
set(KDE_L10N_BRANCH "trunk" CACHE STRING "Branch from l10n.kde.org to fetch from: trunk | stable | lts | trunk_kde4 | stable_kde4")
if(KDE_L10N_AUTO_TRANSLATIONS AND NOT KDE_L10N_SYNC_TRANSLATIONS)
set(_EXTRA_ARGS "ALL")
else()
set(_EXTRA_ARGS)
endif()
set(_reponame "")
_repository_name(_reponame "${CMAKE_SOURCE_DIR}")
set(releaseme_clone_commands
COMMAND git clone --depth 1 https://invent.kde.org/sdk/releaseme.git
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/releaseme"
${releaseme_clone_commands}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Fetching releaseme scripts to download translations..."
)
set(_l10n_po_dir "${CMAKE_BINARY_DIR}/po")
set(_l10n_poqm_dir "${CMAKE_BINARY_DIR}/poqm")
set(extra BYPRODUCTS ${_l10n_po_dir} ${_l10n_poqm_dir})
set(fetch_commands
COMMAND ruby "${CMAKE_BINARY_DIR}/releaseme/fetchpo.rb"
--origin ${KDE_L10N_BRANCH}
--project "${_reponame}"
--output-dir "${_l10n_po_dir}"
--output-poqm-dir "${_l10n_poqm_dir}"
"${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(fetch-translations ${_EXTRA_ARGS}
COMMENT "Downloading translations for ${_reponame} branch ${KDE_L10N_BRANCH}..."
COMMAND git -C "${CMAKE_BINARY_DIR}/releaseme" pull
COMMAND cmake -E remove_directory ${_l10n_po_dir}
COMMAND cmake -E remove_directory ${_l10n_poqm_dir}
${fetch_commands}
${extra}
DEPENDS "${CMAKE_BINARY_DIR}/releaseme"
)
if (KDE_L10N_SYNC_TRANSLATIONS AND (NOT EXISTS ${_l10n_po_dir} OR NOT EXISTS ${_l10n_poqm_dir}))
execute_process(${releaseme_clone_commands})
execute_process(${fetch_commands})
endif()
endif()
@@ -0,0 +1,114 @@
# SPDX-FileCopyrightText: 2019 Christoph Cullmann <cullmann@kde.org>
# SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
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(<files>)
Using this function will create a clang-format target that will format all
``<files>`` 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 :kde-module:`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 :kde-module:`KDEFrameworkCompilerSettings`. If directories should be excluded from
the formatting a .clang-format file with ``DisableFormat: true`` and ``SortIncludes: false`` should be created.
Example usage:
.. code-block:: cmake
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:
.. code-block:: yaml
DisableFormat: true
SortIncludes: false
Since 5.64
#]=======================================================================]
# try to find clang-format in path
find_program(KDE_CLANG_FORMAT_EXECUTABLE clang-format)
# instantiate our clang-format file, must be in source directory for tooling if we have the tool
if(KDE_CLANG_FORMAT_EXECUTABLE)
set(CLANG_FORMAT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format)
if (EXISTS ${CLANG_FORMAT_FILE})
file(READ ${CLANG_FORMAT_FILE} CLANG_FORMAT_CONTENTS LIMIT 1000)
string(FIND "${CLANG_FORMAT_CONTENTS}" "This file got automatically created by ECM, do not edit" matchres)
if(${matchres} EQUAL -1)
message(WARNING "The .clang-format file already exists. Please remove it in order to use the file provided by ECM")
else()
configure_file(${CMAKE_CURRENT_LIST_DIR}/clang-format.cmake ${CLANG_FORMAT_FILE} @ONLY)
endif()
else()
configure_file(${CMAKE_CURRENT_LIST_DIR}/clang-format.cmake ${CLANG_FORMAT_FILE} @ONLY)
endif()
endif()
# formatting target
function(KDE_CLANG_FORMAT)
if (TARGET clang-format)
# We can only define one clang-format target
return()
endif()
# add target without specific commands first, we add the real calls file-per-file to avoid command line length issues and enable parallelization
add_custom_target(clang-format COMMENT "Formatting sources in ${CMAKE_CURRENT_SOURCE_DIR} with ${KDE_CLANG_FORMAT_EXECUTABLE}...")
# run clang-format only if available, else signal the user what is missing
if(KDE_CLANG_FORMAT_EXECUTABLE)
get_filename_component(_binary_dir ${CMAKE_BINARY_DIR} REALPATH)
set(_ci_install_dir "${CMAKE_SOURCE_DIR}/_install") # on the KDE-CI, we install dependencies in-source
foreach(_file ${ARGV})
# check if the file is inside the build directory => ignore such files
get_filename_component(_full_file_path ${_file} REALPATH)
string(FIND ${_full_file_path} ${_binary_dir} _binary_idx)
string(FIND ${_full_file_path} ${_ci_install_dir} _dependency_idx)
if(NOT _binary_idx EQUAL 0 AND NOT _dependency_idx EQUAL 0)
get_filename_component(_file_name ${_file} NAME)
file(RELATIVE_PATH _rel_file_path ${CMAKE_SOURCE_DIR} ${_full_file_path})
string(REPLACE "/" "_" unique_target_name "clang-format-${_rel_file_path}")
string(REPLACE "%" "_" unique_target_name ${unique_target_name}) # some imvalid cmake target names
string(REPLACE "{" "_" unique_target_name ${unique_target_name})
string(REPLACE "}" "_" unique_target_name ${unique_target_name})
add_custom_target(${unique_target_name}
DEPENDS ${_full_file_path}
)
add_custom_command(TARGET ${unique_target_name}
POST_BUILD
COMMAND ${KDE_CLANG_FORMAT_EXECUTABLE} -style=file -i ${_full_file_path}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(clang-format ${unique_target_name})
endif()
endforeach()
else()
add_custom_command(TARGET clang-format
COMMAND
${CMAKE_COMMAND} -E echo "Could not set up the clang-format target as the clang-format executable is missing."
)
endif()
endfunction()
@@ -0,0 +1,794 @@
# SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org>
# SPDX-FileCopyrightText: 2013 Stephen Kelly <steveire@gmail.com>
# SPDX-FileCopyrightText: 2012-2013 Raphael Kubo da Costa <rakuco@FreeBSD.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
# SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
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:
- ``CMAKE_C_STANDARD``: ``99``
- ``CMAKE_C_STANDARD_REQUIRED``: ``TRUE``
- ``CMAKE_C_EXTENSIONS``: ``OFF``
Otherwise:
- ``CMAKE_C_STANDARD``: ``90``
- ``CMAKE_C_STANDARD_REQUIRED``: not modified
- ``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:
- ``CMAKE_CXX_STANDARD``: ``17``
- ``CMAKE_CXX_STANDARD_REQUIRED``: ``TRUE``
- ``CMAKE_CXX_EXTENSIONS``: ``OFF``
Otherwise:
- ``CMAKE_CXX_STANDARD``: ``11``
- ``CMAKE_CXX_STANDARD_REQUIRED``: ``TRUE``
- ``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:
- ``-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).
- ``-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).
- ``-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).
- ``-Werror=undef`` (GNU and Clang compilers, since 5.96.0)
- Qt related preprocessor definitions (since 5.85.0):
- ``-DQT_NO_CAST_TO_ASCII``
- ``-DQT_NO_CAST_FROM_ASCII``
- ``-DQT_NO_URL_CAST_FROM_STRING``
- ``-DQT_NO_CAST_FROM_BYTEARRAY``
- ``-DQT_USE_QSTRINGBUILDER``
- ``-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT``
- ``-DQT_NO_KEYWORDS``
- ``-DQT_NO_FOREACH``
- ``-DQT_STRICT_ITERATORS``
Strict iterators are not enabled on Windows, because they lead
to a link error when application code iterates over a QVector<QPoint> 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 <INTERFACE|PUBLIC|PRIVATE>)
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
:kde-module:`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:
.. code-block:: cmake
# 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)
.. code-block:: cmake
# 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)
.. code-block:: cmake
# 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)
.. code-block:: cmake
# 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.
#]=======================================================================]
############################################################
# Select and check KDE_COMPILERSETTINGS_LEVEL
# For a specified version of KDE_COMPILERSETTINGS_LEVEL always the same set
# of settings needs to be used, to give that version a meaning, even more as
# the settings are usually more strict and can break builds which build fine
# without the setting.
# As at the time of version x it is usually unknown what future versions x+y
# will offer as settings, the minimum required version of ECM sets the upper
# limit then for the level version.
if(NOT DEFINED KDE_COMPILERSETTINGS_LEVEL)
set(KDE_INTERNAL_COMPILERSETTINGS_LEVEL "${ECM_GLOBAL_FIND_VERSION}")
else()
if(KDE_COMPILERSETTINGS_LEVEL VERSION_GREATER "${ECM_GLOBAL_FIND_VERSION}")
message(FATAL_ERROR "KDE_COMPILERSETTINGS_LEVEL (${KDE_COMPILERSETTINGS_LEVEL}) cannot be newer than the min. required ECM version (${ECM_GLOBAL_FIND_VERSION}).")
endif()
set(KDE_INTERNAL_COMPILERSETTINGS_LEVEL "${KDE_COMPILERSETTINGS_LEVEL}")
endif()
include("${ECM_MODULE_DIR}/ECMSourceVersionControl.cmake")
############################################################
# Default build type
# If no build type was specified, default to using a debug build if the
# source directory is a git clone.
# Otherwise, leave it empty, to let distro packagers choose the flags.
############################################################
if (ECM_SOURCE_UNDER_VERSION_CONTROL AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(default_build_type "Debug")
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE "${default_build_type}")
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
############################################################
# Toolchain minimal requirements
#
# Note that only compilers officially supported by Qt are
# supported by this file; workarounds for older compilers
# will generally not be included. See
# https://qt-project.org/doc/qt-5/supported-platforms.html
# and
# https://community.kde.org/Frameworks/Policies#Frameworks_compiler_requirements_and_C.2B.2B11
# for more details.
############################################################
macro(_kde_compiler_min_version min_version)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${min_version})
message(WARNING "Version ${CMAKE_CXX_COMPILER_VERSION} of the ${CMAKE_CXX_COMPILER_ID} C++ compiler is not supported. Please use version ${min_version} or later.")
endif()
endmacro()
if (MSVC)
# MSVC_VERSION 1600 = VS 10.0 = Windows SDK 7
# See: cmake --help-variable MSVC_VERSION
# and https://developer.mozilla.org/en-US/docs/Windows_SDK_versions
if (${MSVC_VERSION} LESS 1600)
message(WARNING "Your MSVC version (${MSVC_VERSION}) is not supported. Please use the Windows SDK version 7 or later (or Microsoft Visual Studio 2010 or later).")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (WIN32)
_kde_compiler_min_version("4.7")
elseif (APPLE)
# FIXME: Apple heavily modifies GCC, so checking the
# GCC version on OS/X is not very useful.
else()
_kde_compiler_min_version("4.5")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
_kde_compiler_min_version("3.1")
else()
message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported C++ compiler.")
endif()
############################################################
# System API features
############################################################
# This macro is for adding definitions that affect the underlying
# platform API. It makes sure that configure checks will also have
# the same defines, so that the checks match compiled code.
macro (_KDE_ADD_PLATFORM_DEFINITIONS)
add_definitions(${ARGV})
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${ARGV})
endmacro()
include(CheckSymbolExists)
check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC)
if (LIBC_IS_GLIBC)
# Enable everything in GNU libc. Any code using non-portable features
# needs to perform feature tests, but this ensures that any such features
# will be found if they exist.
#
# NB: we do NOT define _BSD_SOURCE, as with GNU libc that requires linking
# against the -lbsd-compat library (it changes the behaviour of some
# functions). This, however, means that strlcat and strlcpy are not
# provided by glibc.
_kde_add_platform_definitions(-D_GNU_SOURCE)
endif ()
if (UNIX)
# Enable extra API for using 64-bit file offsets on 32-bit systems.
# FIXME: this is included in _GNU_SOURCE in glibc; do other libc
# implementation recognize it?
_kde_add_platform_definitions(-D_LARGEFILE64_SOURCE)
include(CheckCXXSourceCompiles)
# By default (in glibc, at least), on 32bit platforms off_t is 32 bits,
# which causes a SIGXFSZ when trying to manipulate files larger than 2Gb
# using libc calls (note that this issue does not occur when using QFile).
check_cxx_source_compiles("
#include <sys/types.h>
/* Check that off_t can represent 2**63 - 1 correctly.
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
int main() { return 0; }
" _OFFT_IS_64BIT)
if (NOT _OFFT_IS_64BIT)
_kde_add_platform_definitions(-D_FILE_OFFSET_BITS=64)
endif ()
endif()
if (WIN32)
# Speeds up compile times by not including everything with windows.h
# See http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx
_kde_add_platform_definitions(-DWIN32_LEAN_AND_MEAN)
if (KDE_INTERNAL_COMPILERSETTINGS_LEVEL VERSION_GREATER_EQUAL 5.240.0 OR QT_MAJOR_VERSION STREQUAL "6")
# Target Windows 10
# This enables various bits of new API
# See http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx
# Windows 10 is the default by Qt6 hence we do not need the next line, but we keep it disabled
# to not to start from scratch in case we want to target a different version in the future
# _kde_add_platform_definitions(-D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -D_WIN32_IE=0x0A00)
else()
# Target Windows Vista
# This enables various bits of new API
# See http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx
_kde_add_platform_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600 -D_WIN32_IE=0x0600)
endif()
# Use the Unicode versions of Windows API by default
# See http://msdn.microsoft.com/en-us/library/windows/desktop/dd317766%28v=vs.85%29.aspx
_kde_add_platform_definitions(-DUNICODE -D_UNICODE)
# As stated in http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx M_PI only gets defined
# if _USE_MATH_DEFINES is defined, with mingw this has a similar effect as -D_GNU_SOURCE on math.h
_kde_add_platform_definitions(-D_USE_MATH_DEFINES)
# Don't define MIN and MAX in windows.h
# the defines break the use of std::max
_kde_add_platform_definitions(-DNOMINMAX)
endif()
############################################################
# Language and toolchain features
############################################################
# Pick sensible versions of the C and C++ standards.
if (NOT CMAKE_C_STANDARD)
if (KDE_INTERNAL_COMPILERSETTINGS_LEVEL VERSION_GREATER_EQUAL 5.85.0)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_C_EXTENSIONS OFF)
else()
set(CMAKE_C_STANDARD 90)
endif()
endif()
if (NOT CMAKE_CXX_STANDARD)
if (KDE_INTERNAL_COMPILERSETTINGS_LEVEL VERSION_GREATER_EQUAL 5.85.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
endif()
# Do not merge uninitialized global variables.
# This is mostly a "principle of least surprise" thing, but also
# has performance benefits.
# See https://www.ibm.com/developerworks/community/blogs/zTPF/entry/benefits_of_the_fnocommon_compile_option_peter_lemieszewski?lang=en
# Note that this only applies to C code; C++ already behaves like this.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang" OR
(CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-common")
endif()
# Do not treat the operator name keywords and, bitand, bitor, compl, not, or and xor as synonyms as keywords.
# They're not supported under Visual Studio out of the box thus using them limits the portability of code
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang" OR
(CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names")
endif()
# Default to hidden visibility for symbols
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
if (POLICY CMP0063)
# No sane project should be affected by CMP0063, so suppress the warnings
# generated by the above visibility settings in CMake >= 3.3
cmake_policy(SET CMP0063 NEW)
endif()
if (UNIX AND NOT APPLE AND NOT CYGWIN)
# Enable adding DT_RUNPATH, which means that LD_LIBRARY_PATH takes precedence
# over the built-in rPath
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags ${CMAKE_EXE_LINKER_FLAGS}")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL GNU)
# Enable multithreading with the pthread library
# FIXME: Is this actually necessary to have here?
# Can CMakeLists.txt files that require it use FindThreads.cmake
# instead?
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread")
endif()
if (MSVC)
# Our source files are UTF-8 encoded, and assuming that is also the
# default behavior of GCC/Clang. Not so for MSVC though, so force
# that to UTF-8 explicitly, as that will otherwise cause compile-time
# and runtime issues when dealing with string literals outside of 7-bit ASCII.
add_compile_options(/utf-8)
endif()
############################################################
# Turn off exceptions by default
#
# This involves enough code to be separate from the
# previous section.
############################################################
# TODO: Deal with QT_NO_EXCEPTIONS for non-gnu compilers?
# This should be defined if and only if exceptions are disabled.
# qglobal.h has some magic to set it when exceptions are disabled
# with gcc, but other compilers are unaccounted for.
# Turn off exceptions by default
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
#elseif (MSVC OR (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Intel"))
# Exceptions appear to be disabled by default for MSVC
# http://msdn.microsoft.com/en-us/library/1deeycx5.aspx
# FIXME: are exceptions disabled by default for Intel?
endif()
macro(_kdecompilersettings_append_exception_flag VAR)
if (MSVC)
set(${VAR} "${${VAR}} -EHsc")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
if (WIN32)
set(${VAR} "${${VAR}} -EHsc")
else()
set(${VAR} "${${VAR}} -fexceptions")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(${VAR} "${${VAR}} -fexceptions")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(${VAR} "${${VAR}} -fexceptions")
endif()
string(STRIP "${${VAR}}" ${VAR})
endmacro()
function(KDE_SOURCE_FILES_ENABLE_EXCEPTIONS)
foreach(source_file ${ARGV})
get_source_file_property(flags ${source_file} COMPILE_FLAGS)
if(NOT flags)
# If COMPILE_FLAGS is not set, get_source_file_property() sets it to
# NOTFOUND, which breaks build if we concatenate anything to
# the "NOTFOUND" string.
# Note that NOTFOUND evaluates to False, so we do enter the if.
set(flags "")
endif()
_kdecompilersettings_append_exception_flag(flags)
set_source_files_properties(${source_file} COMPILE_FLAGS "${flags}")
endforeach()
endfunction()
function(KDE_TARGET_ENABLE_EXCEPTIONS target mode)
target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:MSVC>:-EHsc>")
if (WIN32)
target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:Intel>:-EHsc>")
else()
target_compile_options(${target} ${mode} "$<$<CXX_COMPILER_ID:Intel>:-fexceptions>")
endif()
target_compile_options(${target} ${mode}
"$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fexceptions>")
endfunction()
function(KDE_ENABLE_EXCEPTIONS)
# We set CMAKE_CXX_FLAGS, rather than add_compile_options(), because
# we only want to affect the compilation of C++ source files.
# strip any occurrences of -DQT_NO_EXCEPTIONS; this should only be defined
# if exceptions are disabled
# the extra spaces mean we will not accentially mangle any other options
string(REPLACE " -DQT_NO_EXCEPTIONS " " " CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} ")
# this option is common to several compilers, so just always remove it
string(REPLACE " -fno-exceptions " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# strip undoes the extra spaces we put in above
string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
_kdecompilersettings_append_exception_flag(CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
endfunction()
############################################################
# Better diagnostics (warnings, errors)
############################################################
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE) OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32))
# Linker warnings should be treated as errors
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_MODULE_LINKER_FLAGS}")
string(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" compileflags)
if("${CMAKE_CXX_FLAGS} ${${compileflags}}" MATCHES "-fsanitize")
set(sanitizers_enabled TRUE)
else()
set(sanitizers_enabled FALSE)
endif()
# Do not allow undefined symbols, even in non-symbolic shared libraries
# On OpenBSD we must disable this to allow the stuff to properly compile without explicit libc specification
if (NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD" AND (NOT sanitizers_enabled OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined ${CMAKE_MODULE_LINKER_FLAGS}")
endif()
endif()
set(_KDE_GCC_COMMON_WARNING_FLAGS "-Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# -Wgnu-zero-variadic-macro-arguments (part of -pedantic) is triggered by every qCDebug() call and therefore results
# in a lot of noise. This warning is only notifying us that clang is emulating the GCC behaviour
# instead of the exact standard wording so we can safely ignore it
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wmissing-format-attribute -Wwrite-strings")
# Make some warnings errors
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_KDE_GCC_COMMON_WARNING_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual")
# Make some warnings errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -Werror=init-self")
if (KDE_INTERNAL_COMPILERSETTINGS_LEVEL VERSION_GREATER_EQUAL 5.96.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=undef")
endif()
elseif(MSVC)
# similar to -Werror=return-type
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=msvc-170
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /we4715")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5))
# -Wvla: use of variable-length arrays (an extension to C++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla")
endif()
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0) OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5))
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wdate-time HAVE_DATE_TIME)
if (HAVE_DATE_TIME)
# -Wdate-time: warn if we use __DATE__ or __TIME__ (we want to be able to reproduce the exact same binary)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdate-time")
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override -Wlogical-op" )
endif()
endif()
# -w1 turns on warnings and errors
# FIXME: someone needs to have a closer look at the Intel compiler options
if (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -w1 -Wpointer-arith")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -w1 -Wpointer-arith")
endif()
if (MSVC)
# enable linter like warnings including deprecation warnings
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
# Disable warnings:
# C4250: 'class1' : inherits 'class2::member' via dominance
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4250")
# C4251: 'identifier' : class 'type' needs to have dll-interface to be
# used by clients of class 'type2'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251")
# C4396: 'identifier' : 'function' the inline specifier cannot be used
# when a friend declaration refers to a specialization of a
# function template
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4396")
# C4661: 'identifier' : no suitable definition provided for explicit
# template instantiation request
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4661")
if (CMAKE_CXX_STANDARD GREATER_EQUAL 11)
# Ensure __cplusplus is correct, otherwise it defaults to 199711L which isn't true
# https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
endif()
endif()
option(ENABLE_BSYMBOLICFUNCTIONS "Make use of -Bsymbolic-functions" OFF)
if (ENABLE_BSYMBOLICFUNCTIONS)
set(_SYMBOLIC_FUNCTIONS_COMPILER_OPTION "-Wl,-Bsymbolic-functions")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}")
include(CheckCXXSourceCompiles)
check_cxx_source_compiles( "int main () { return 0; }" BSYMBOLICFUNCTIONS_AVAILABLE )
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}")
if (BSYMBOLICFUNCTIONS_AVAILABLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}")
endif()
endif()
if (WIN32)
# Disable deprecation warnings for some API
# FIXME: do we really want this?
add_definitions(-D_CRT_SECURE_NO_DEPRECATE
-D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_DEPRECATE
-D_SCL_SECURE_NO_WARNINGS
)
endif()
if (APPLE)
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
_kde_add_platform_definitions(-D_DARWIN_C_SOURCE)
#Cocoa is unconditional since we only support OS X 10.6 and above
_kde_add_platform_definitions(-DQT_MAC_USE_COCOA)
endif()
############################################################
# Modern code
############################################################
function(_kde_set_default_skip_variable_by_min_ecm _var_name _ecm_version)
if(NOT DEFINED ${_var_name})
if (KDE_INTERNAL_COMPILERSETTINGS_LEVEL VERSION_LESS ${_ecm_version})
set(${_var_name} TRUE PARENT_SCOPE)
else()
set(${_var_name} FALSE PARENT_SCOPE)
endif()
endif()
endfunction()
if(NOT DEFINED KDE_QT_MODERNCODE_DEFINITIONS_LEVEL)
set(KDE_INTERNAL_QT_MODERNCODE_DEFINITIONS_LEVEL ${KDE_INTERNAL_COMPILERSETTINGS_LEVEL})
else()
set(KDE_INTERNAL_QT_MODERNCODE_DEFINITIONS_LEVEL ${KDE_QT_MODERNCODE_DEFINITIONS_LEVEL})
endif()
if (KDE_INTERNAL_QT_MODERNCODE_DEFINITIONS_LEVEL VERSION_GREATER_EQUAL "5.85.0")
add_definitions(
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_USE_QSTRINGBUILDER
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
-DQT_NO_KEYWORDS
-DQT_NO_FOREACH
)
if (NOT WIN32)
# Strict iterators can't be used on Windows, they lead to a link error
# when application code iterates over a QVector<QPoint> for instance, unless
# Qt itself was also built with strict iterators.
# See example at https://bugreports.qt.io/browse/AUTOSUITE-946
add_definitions(-DQT_STRICT_ITERATORS)
endif()
endif()
_kde_set_default_skip_variable_by_min_ecm(KDE_SKIP_PEDANTIC_WARNINGS_SETTINGS "5.85.0")
if (NOT KDE_SKIP_PEDANTIC_WARNINGS_SETTINGS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
endif()
endif()
_kde_set_default_skip_variable_by_min_ecm(KDE_SKIP_NULLPTR_WARNINGS_SETTINGS "5.85.0")
if (NOT KDE_SKIP_NULLPTR_WARNINGS_SETTINGS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" )
endif()
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" )
endif()
endif()
endif()
_kde_set_default_skip_variable_by_min_ecm(KDE_SKIP_MISSING_INCLUDE_DIRS_WARNINGS_SETTINGS "5.85.0")
if (NOT KDE_SKIP_MISSING_INCLUDE_DIRS_WARNINGS_SETTINGS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-include-dirs")
endif()
endif()
############################################################
# Hacks
#
# Anything in this section should be thoroughly documented,
# including what problems it is supposed to fix and in what
# circumstances those problems occur. Include links to any
# relevant bug reports.
############################################################
if (APPLE)
# FIXME: why are these needed? The commit log is unhelpful
# (it was introduced in svn path=/trunk/KDE/kdelibs/; revision=503025 -
# kdelibs git commit 4e4cb9cb9a2216b63d3eabf88b8fe94ee3c898cf -
# with the message "mac os x fixes for the cmake build")
set (CMAKE_SHARED_LINKER_FLAGS "-single_module -multiply_defined suppress ${CMAKE_SHARED_LINKER_FLAGS}")
set (CMAKE_MODULE_LINKER_FLAGS "-multiply_defined suppress ${CMAKE_MODULE_LINKER_FLAGS}")
endif()
if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# This was copied from the Phonon build settings, where it had the comment
# "otherwise undefined symbol in phononcore.dll errors occurs", with the commit
# message "set linker flag --export-all-symbols for all targets, otherwise
# some depending targets could not be build"
# FIXME: do our export macros not deal with this properly?
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--export-all-symbols")
endif()
if (CMAKE_GENERATOR STREQUAL "Ninja" AND
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9) OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5)))
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
# Rationale in https://github.com/ninja-build/ninja/issues/814
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
include("${ECM_MODULE_DIR}/ECMEnableSanitizers.cmake")
include("${ECM_MODULE_DIR}/ECMCoverageOption.cmake")
############################################################
# Clean-up
############################################################
# unset again, to not leak into caller scope and avoid usage there
set(KDE_INTERNAL_COMPILERSETTINGS_LEVEL)
set(KDE_INTERNAL_QT_MODERNCODE_DEFINITIONS_LEVEL)
@@ -0,0 +1,81 @@
# SPDX-FileCopyrightText: 2013 Albert Astals Cid <aacid@kde.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[
Backward-compatibility support
------------------------------
For all the non-KF projects which reused the KDEFrameworkCompilerSettings
module to get more strict settings.
Kept as is, to be removed on next backward-compatibility-breakage occasion.
#]=======================================================================]
if (NOT CMAKE_CXX_STANDARD)
if (ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.84.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endif()
include(KDECompilerSettings NO_POLICY_SCOPE)
add_definitions(-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_USE_QSTRINGBUILDER
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
)
if (NOT WIN32)
# Strict iterators can't be used on Windows, they lead to a link error
# when application code iterates over a QVector<QPoint> for instance, unless
# Qt itself was also built with strict iterators.
# See example at https://bugreports.qt.io/browse/AUTOSUITE-946
add_definitions(-DQT_STRICT_ITERATORS)
endif()
# Some non-KF projects make (ab)use of KDEFrameworkCompilerSettings currently,
# let them only hit this as well when bumping their min. ECM requirement to a newer version.
if (ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.79.0)
add_definitions(
-DQT_NO_KEYWORDS
-DQT_NO_FOREACH
)
else()
add_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS)
endif()
add_definitions(
-DQT_DEPRECATED_WARNINGS_SINCE=0x060000
-DKF_DEPRECATED_WARNINGS_SINCE=0x060000
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" )
endif()
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant" )
endif()
endif()
if (ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.80.0)
include(KDEClangFormat)
# add clang-format target
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.hpp *.c)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
endif ()
@@ -0,0 +1,69 @@
# SPDX-FileCopyrightText: 2013 Albert Astals Cid <aacid@kde.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
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 :kde-module:`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.
#]=======================================================================]
# No-one else should be using this module, at least by the time when requiring
# ECM 5.85 as minimum, where also settings levels had been introduced for
# KDECompilerSettings to satisfy the needs for stricter out-of-the-box
# settings.
# So making a clear cut here by that condition and providing backward-compat
# support from a separate file with the old code, avoiding the need for
# further if()-else() when changing the settings for current KDE Frameworks.
if (ECM_GLOBAL_FIND_VERSION VERSION_LESS 5.85.0)
include(KDEFrameworkCompilerLegacySettings NO_POLICY_SCOPE)
return()
endif()
# set ENABLE_BSYMBOLICFUNCTIONS default to ON when possible
# TODO: find a nice way to set an option default
# we can only use symbolic functions when everything is built with that
# otherwise we'll break function pointer based connects and method lookups
include(${CMAKE_CURRENT_LIST_DIR}/../modules/QtVersionOption.cmake)
if (QT_MAJOR_VERSION EQUAL "6")
find_package(Qt6Core)
set(ENABLE_BSYMBOLICFUNCTIONS ${QT_FEATURE_reduce_relocations})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
else ()
set(ENABLE_BSYMBOLICFUNCTIONS ON)
endif()
# Current defaults
include(KDECompilerSettings NO_POLICY_SCOPE)
# add clang-format target
include(KDEClangFormat)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.hpp *.c)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
# add the metainfo platform check
include(KDEMetaInfoPlatformCheck)
@@ -0,0 +1,182 @@
# SPDX-FileCopyrightText: 2020-2023 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-FileCopyrightText: 2022 Ahmad Samir <a.samirh78@gmail.com>
# SPDX-FileCopyrightText: 2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
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 <check1> [<check2> [...]
[CUSTOM_SCRIPTS [<script paths> [<script paths> ...]]] # since 5.109
)
This function will create a pre-commit hook which contains all the given checks.
In addition to that, you can pass in paths to custom scripts that will be run as the pre-commit hook.
If a custom hooks directory is set via ``core.hooksPath``, a warning is issued.
Checks:
- ``CLANG_FORMAT`` With this check enabled the ``git clang-format`` tool will be used to make sure that
the changed parts are properly formatted. In case the changes are not properly formatted an error
message with the command to preview the formatting changes and to format the files in place
will be displayed. This tool will reuse the exsting ``.clang-format`` file, in case you
want to use the one provided by ECM you can include ``include(KDEClangFormat)`` which will copy
the file to the source dir. It is also recommended to reformat the entire project before enforcing
the formatting using this commit hook.
- ``JSON_SCHEMA`` Since 5.110, uses the check-jsonschema CLI tool to ensure that all files are valid JSON and
match the KPluginMetaData spec. This only applied if the JSON file has a "KPlugin" object in its root.
To ignore invalid files, for example for testing error handling, given files can be exlcuded in the .kde-ci.yml file
Define Options.json-validate-ignore with an array of the files you want to ignore
Example usage:
.. code-block:: cmake
include(KDEGitCommitHooks)
kde_configure_git_pre_commit_hook(CHECKS JSON_SCHEMA CLANG_FORMAT)
Since 5.79
#]=======================================================================]
# try to find clang-format in path
find_program(KDE_CLANG_FORMAT_EXECUTABLE clang-format)
find_program(KDE_CHECK_JSONSCHEMA_EXECUTABLE check-jsonschema)
set(PRE_COMMIT_HOOK_UNIX "${CMAKE_CURRENT_LIST_DIR}/kde-git-commit-hooks/pre-commit.in")
set(CLANG_FORMAT_UNIX "${CMAKE_CURRENT_LIST_DIR}/kde-git-commit-hooks/clang-format.sh")
set(JSON_SCHEMA_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/kde-git-commit-hooks/json-schema.py")
set(JSON_SCHEMA_IN "${CMAKE_CURRENT_LIST_DIR}/kde-git-commit-hooks/combined.schema.json.in")
set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git")
set(GIT_HOOKS_DIR "${GIT_DIR}/hooks")
set(JSON_SCHEMA_OUT "${GIT_HOOKS_DIR}/scripts/combined.schema.json")
function(KDE_CONFIGURE_GIT_PRE_COMMIT_HOOK)
set(_oneValueArgs "")
set(_multiValueArgs CHECKS CUSTOM_SCRIPTS)
cmake_parse_arguments(ARG "" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
message(STATUS "Project is not top level project - pre-commit hook not installed")
return()
endif()
if(NOT ARG_CHECKS)
message(FATAL_ERROR "No checks were specified")
endif()
find_package(Git QUIET)
if (NOT IS_DIRECTORY ${GIT_DIR} # In case of tarballs there is no .git directory
OR NOT (UNIX OR WIN32)
OR NOT GIT_FOUND
)
return()
endif()
execute_process(COMMAND "${GIT_EXECUTABLE}" config --get core.hooksPath
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE _gitresult
OUTPUT_VARIABLE _gitoutput
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_gitresult EQUAL 0 AND NOT ${GIT_HOOKS_DIR} EQUAL "${_gitoutput}")
message(WARNING "Git is configured to use '${_gitoutput}' for hooks. The generated commit hooks will likely not be executed.")
endif()
string(REPLACE ";" "\n" PRE_COMMIT_SCRIPTS "${ARG_CUSTOM_SCRIPTS}")
set(_write_hook FALSE)
if(KDE_CLANG_FORMAT_EXECUTABLE)
list(FIND ARG_CHECKS "CLANG_FORMAT" _index)
# Used to configure clang-format.sh script
if (COMMAND KDE_CLANG_FORMAT)
set(HAS_CLANG_FORMAT_COMMAND_INCLUDED TRUE)
else()
set(HAS_CLANG_FORMAT_COMMAND_INCLUDED FALSE)
endif()
if (${_index} GREATER -1)
# get version of clang-format
execute_process(
COMMAND "${KDE_CLANG_FORMAT_EXECUTABLE}" --version
OUTPUT_VARIABLE _clang_format_version_raw
ERROR_VARIABLE _clang_format_version_raw
)
if (_clang_format_version_raw MATCHES "clang-format version ([0-9]+)(\\.[0-9]+)*")
set(KDE_CLANG_FORMAT_MAJOR_VERSION "${CMAKE_MATCH_1}")
endif()
unset(_clang_format_version_raw)
message(STATUS "Found clang-format version ${KDE_CLANG_FORMAT_MAJOR_VERSION}")
set(CLANG_FORMAT_SCRIPT "\"$(git rev-parse --git-common-dir)\"/hooks/scripts/clang-format.sh")
configure_file(${CLANG_FORMAT_UNIX} "${GIT_HOOKS_DIR}/scripts/clang-format.sh" @ONLY)
set(PRE_COMMIT_SCRIPTS "\"$(git rev-parse --git-common-dir)\"/hooks/scripts/clang-format.sh\n${PRE_COMMIT_SCRIPTS}")
set(_write_hook TRUE)
endif()
endif()
list(FIND ARG_CHECKS "JSON_SCHEMA" _index)
if (${_index} GREATER -1)
set(_write_hook TRUE)
foreach(path ${CMAKE_PREFIX_PATH};${CMAKE_INCLUDE_PATH})
file(GLOB files "${path}/${KDE_INSTALL_DATADIR}/kf6/jsonschema/*.json")
set(SCHEMA_FILES ${SCHEMA_FILES};${files})
endforeach()
foreach (SCHEMA ${SCHEMA_FILES})
if (SCHEMA_INCLUDES)
set(SCHEMA_INCLUDES "${SCHEMA_INCLUDES},")
endif()
set(SCHEMA_INCLUDES "${SCHEMA_INCLUDES}{\"$ref\": \"${SCHEMA}\"}")
endforeach()
configure_file(${JSON_SCHEMA_IN} ${JSON_SCHEMA_OUT} @ONLY)
if (KDE_CHECK_JSONSCHEMA_EXECUTABLE)
set(PRE_COMMIT_SCRIPTS "set -e\npython3 ${JSON_SCHEMA_SCRIPT} \"${JSON_SCHEMA_OUT}\"\n${PRE_COMMIT_SCRIPTS}")
else()
message(WARNING "check-jsonschema executable not found. Please install it using pip or using your package manager")
endif()
endif()
set(_hook_file "${GIT_HOOKS_DIR}/pre-commit")
# Appending to the file is quite ugly and causes edge cases. With the CUSTOM_SCRIPTS arg, this should not be needed though
if (ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.109.0)
set(PRE_COMMIT_SCRIPTS "# This file is autogenerated by kde_configure_git_pre_commit_hook, any changes will be lost! \n${PRE_COMMIT_SCRIPTS}")
configure_file(${PRE_COMMIT_HOOK_UNIX} "${_hook_file}")
else()
if(NOT _write_hook)
message(WARNING "No clang-format executable was found, skipping the formatting pre-commit hook")
return()
endif()
# Doesn't exist? write away
if(NOT EXISTS ${_hook_file})
configure_file(${PRE_COMMIT_HOOK_UNIX} "${_hook_file}")
return()
endif()
file(READ ${_hook_file} _contents)
# For when CLANG_FORMAT_SCRIPT didn't have the 'git rev-parse --git-common-dir' part
set(_old_cmd "./.git/hooks/scripts/clang-format.sh")
string(FIND "${_contents}" "${_old_cmd}" _idx)
if (${_idx} GREATER -1)
string(REPLACE "${_old_cmd}" "${CLANG_FORMAT_SCRIPT}" _contents "${_contents}")
file(WRITE ${_hook_file} "${_contents}")
return()
endif()
string(FIND "${_contents}" "${CLANG_FORMAT_SCRIPT}" _idx)
# File exists and doesn't have the clang-format.sh line, append it
# so as to not overwrite users' customisations
if (_idx EQUAL -1)
file(APPEND ${_hook_file} "${CLANG_FORMAT_SCRIPT}")
endif()
endif()
endfunction()
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
KDEInstallDirs
--------------
Compatibility wrapper around :kde-module:`KDEInstallDirs5`.
Since 5.82.0, prior to that equivalent to :kde-module:`KDEInstallDirs5`.
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/../modules/QtVersionOption.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/KDEInstallDirs${QT_MAJOR_VERSION}.cmake)
@@ -0,0 +1,386 @@
# SPDX-FileCopyrightText: 2014-2015 Alex Merry <alex.merry@kde.org>
# SPDX-FileCopyrightText: 2013 Stephen Kelly <steveire@gmail.com>
# SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
KDEInstallDirs5
---------------
Define KDE standard installation directories for Qt5/KF5 based software.
Note that none of the variables defined by this module provide any
information about the location of already-installed KDE software.
Also sets ``CMAKE_INSTALL_PREFIX`` to the installation prefix of ECM,
unless that variable has been already explicitly set by something else
(since 5.61 and with CMake >= 3.7).
Inclusion of this module defines the following variables:
``KDE_INSTALL_<dir>``
destination for files of a given type
``KDE_INSTALL_FULL_<dir>``
corresponding absolute path
where ``<dir>`` is one of (default values in parentheses and alternative,
deprecated variable name in square brackets):
``BUNDLEDIR``
application bundles (``/Applications/KDE``) [``BUNDLE_INSTALL_DIR``]
``EXECROOTDIR``
executables and libraries (``<empty>``) [``EXEC_INSTALL_PREFIX``]
``BINDIR``
user executables (``EXECROOTDIR/bin``) [``BIN_INSTALL_DIR``]
``SBINDIR``
system admin executables (``EXECROOTDIR/sbin``) [``SBIN_INSTALL_DIR``]
``LIBDIR``
object code libraries (``EXECROOTDIR/lib``, ``EXECROOTDIR/lib64`` or
``EXECROOTDIR/lib/<multiarch-tuple`` on Debian) [``LIB_INSTALL_DIR``]
``LIBEXECDIR``
executables for internal use by programs and libraries (``BINDIR`` on
Windows, ``LIBDIR/libexec`` otherwise) [``LIBEXEC_INSTALL_DIR``]
``CMAKEPACKAGEDIR``
CMake packages, including config files (``LIBDIR/cmake``)
[``CMAKECONFIG_INSTALL_PREFIX``]
``QTPLUGINDIR``
Qt plugins (``LIBDIR/plugins`` or qmake-qt5's ``QT_INSTALL_PLUGINS``) [``QT_PLUGIN_INSTALL_DIR``]
``PLUGINDIR``
Plugins (``QTPLUGINDIR``) [``PLUGIN_INSTALL_DIR``]
``QTQUICKIMPORTSDIR``
QtQuick1 imports (``QTPLUGINDIR/imports`` or qmake-qt5's ``QT_INSTALL_IMPORTS``) [``IMPORTS_INSTALL_DIR``]
``QMLDIR``
QtQuick2 imports (``LIBDIR/qml`` or qmake-qt5's ``QT_INSTALL_QML``) [``QML_INSTALL_DIR``]
``INCLUDEDIR``
C and C++ header files (``include``) [``INCLUDE_INSTALL_DIR``]
``LOCALSTATEDIR``
modifiable single-machine data (``var``)
``SHAREDSTATEDIR``
modifiable architecture-independent data (``com``)
``DATAROOTDIR``
read-only architecture-independent data root (``BINDIR/data`` on
Windows, ``share`` otherwise)
[``SHARE_INSTALL_PREFIX``]
``DATADIR``
read-only architecture-independent data (``DATAROOTDIR``)
[``DATA_INSTALL_DIR``]
``DOCBUNDLEDIR``
documentation bundles generated using kdoctools
(``DATAROOTDIR/doc/HTML``) [``HTML_INSTALL_DIR``]
``KCFGDIR``
kconfig description files (``DATAROOTDIR/config.kcfg``)
[``KCFG_INSTALL_DIR``]
``KCONFUPDATEDIR``
kconf_update scripts (``DATAROOTDIR/kconf_update``)
[``KCONF_UPDATE_INSTALL_DIR``]
``KSERVICES5DIR`` or (since 5.89) ``KSERVICESDIR``
services for KDE Frameworks 5 (``DATAROOTDIR/kservices5``)
[``SERVICES_INSTALL_DIR``]
``KSERVICETYPES5DIR`` or (since 5.89) ``KSERVICETYPESDIR``
service types for KDE Frameworks 5 (``DATAROOTDIR/kservicetypes5``)
[``SERVICETYPES_INSTALL_DIR``]
``KXMLGUI5DIR`` or (since 5.89) ``KXMLGUIDIR``
kxmlgui .rc files (``DATAROOTDIR/kxmlgui5``)
[``KXMLGUI_INSTALL_DIR``]
``KAPPTEMPLATESDIR``
KAppTemplate and KDevelop templates (``DATAROOTDIR/kdevappwizard/templates``)
[``KDE_INSTALL_KTEMPLATESDIR``] Since 5.77.
``KFILETEMPLATESDIR``
KDevelop file templates (``DATAROOTDIR/kdevfiletemplates/templates``) Since 5.77.
``KNOTIFY5RCDIR`` or (since 5.89) ``KNOTIFYRCDIR``
knotify description files (``DATAROOTDIR/knotifications5``)
[``KNOTIFYRC_INSTALL_DIR``]
``ICONDIR``
icons (``DATAROOTDIR/icons``) [``ICON_INSTALL_DIR``]
``LOCALEDIR``
locale-dependent data (``DATAROOTDIR/locale``)
[``LOCALE_INSTALL_DIR``]
``SOUNDDIR``
sound files (``DATAROOTDIR/sounds``) [``SOUND_INSTALL_DIR``]
``TEMPLATEDIR``
templates (``DATAROOTDIR/templates``) [``TEMPLATES_INSTALL_DIR``]
``WALLPAPERDIR``
desktop wallpaper images (``DATAROOTDIR/wallpapers``)
[``WALLPAPER_INSTALL_DIR``]
``APPDIR``
application desktop files (``DATAROOTDIR/applications``) Since 1.1.0.
[``XDG_APPS_INSTALL_DIR``]
``DESKTOPDIR``
desktop directories (``DATAROOTDIR/desktop-directories``)
[``XDG_DIRECTORY_INSTALL_DIR``]
``MIMEDIR``
mime description files (``DATAROOTDIR/mime/packages``)
[``XDG_MIME_INSTALL_DIR``]
``METAINFODIR``
AppStream component metadata files (``DATAROOTDIR/metainfo``)
``QTQCHDIR``
documentation bundles in QCH format for Qt-extending libraries (``DATAROOTDIR/doc/qch`` or qmake-qt5's ``QT_INSTALL_DOCS``) Since 5.36.0.
``QCHDIR``
documentation bundles in QCH format (``DATAROOTDIR/doc/qch``) Since 5.36.0.
``MANDIR``
man documentation (``DATAROOTDIR/man``) [``MAN_INSTALL_DIR``]
``INFODIR``
info documentation (``DATAROOTDIR/info``)
``DBUSDIR``
D-Bus (``DATAROOTDIR/dbus-1``)
``DBUSINTERFACEDIR``
D-Bus interfaces (``DBUSDIR/interfaces``)
[``DBUS_INTERFACES_INSTALL_DIR``]
``DBUSSERVICEDIR``
D-Bus session services (``DBUSDIR/services``)
[``DBUS_SERVICES_INSTALL_DIR``]
``DBUSSYSTEMSERVICEDIR``
D-Bus system services (``DBUSDIR/system-services``)
[``DBUS_SYSTEM_SERVICES_INSTALL_DIR``]
``SYSCONFDIR``
read-only single-machine data
(``etc``, or ``/etc`` if ``CMAKE_INSTALL_PREFIX`` is ``/usr``)
[``SYSCONF_INSTALL_DIR``]
``CONFDIR``
application configuration files (``SYSCONFDIR/xdg``)
[``CONFIG_INSTALL_DIR``]
``AUTOSTARTDIR``
autostart files (``CONFDIR/autostart``) [``AUTOSTART_INSTALL_DIR``]
``LOGGINGCATEGORIESDIR``
Qt logging categories files directory (``DATAROOTDIR/qlogging-categories5``) Since 5.59.0
``JARDIR``
Java AAR/JAR files for Android. Since 5.62.0
``SYSTEMDUNITDIR``
Systemd Units (``lib/systemd``)
[``SYSTEMD_UNIT_INSTALL_DIR``]. Since 5.65
``SYSTEMDUSERUNITDIR``
Systemd User Units (``lib/systemd/user``)
[``SYSTEMD_USER_UNIT_INSTALL_DIR``]. Since 5.65
``ZSHAUTOCOMPLETEDIR``
Zsh functions and autocompletion definitions (``zsh/site-functions``)
Since 5.101
If ``KDE_INSTALL_USE_QT_SYS_PATHS`` is set to ``TRUE`` before including this
module, the default values for some variables are instead queried from
Qt5's qmake (where mentioned in the parentheses above).
If not set, it will default to ``TRUE`` if Qt5's qmake is found and
it's ``QT_INSTALL_PREFIX`` is the same as ``CMAKE_INSTALL_PREFIX``,
otherwise default to ``FALSE``.
This variable should NOT be set from within CMakeLists.txt files, instead
is intended to be set manually when configuring a project which uses
KDEInstallDirs (e.g. by packagers).
If ``KDE_INSTALL_DIRS_NO_DEPRECATED`` is set to ``TRUE`` before including this
module, the deprecated variables (listed in the square brackets above) are
not defined.
In addition, for each ``KDE_INSTALL_*`` variable, an equivalent
``CMAKE_INSTALL_*`` variable is defined. If
``KDE_INSTALL_DIRS_NO_DEPRECATED`` is set to ``TRUE``, only those variables
defined by the ``GNUInstallDirs`` module (shipped with CMake) are defined.
If ``KDE_INSTALL_DIRS_NO_CMAKE_VARIABLES`` is set to ``TRUE``, no variables with
a ``CMAKE_`` prefix will be defined by this module (other than
``CMAKE_INSTALL_DEFAULT_COMPONENT_NAME`` - see below).
The ``KDE_INSTALL_<dir>`` variables (or their ``CMAKE_INSTALL_<dir>`` or
deprecated counterparts) may be passed to the ``DESTINATION`` options of
``install()`` commands for the corresponding file type. They are set in the
CMake cache, and so the defaults above can be overridden by users.
Note that the ``KDE_INSTALL_<dir>``, ``CMAKE_INSTALL_<dir>`` or deprecated
form of the variable can be changed using CMake command line variable
definitions; in either case, all forms of the variable will be affected. The
effect of passing multiple forms of the same variable on the command line
(such as ``KDE_INSTALL_BINDIR`` and ``CMAKE_INSTALL_BINDIR`` is undefined.
The variable ``KDE_INSTALL_TARGETS_DEFAULT_ARGS`` is also defined (along with
the deprecated form ``INSTALL_TARGETS_DEFAULT_ARGS``). This should be used
when libraries or user-executable applications are installed, in the
following manner:
.. code-block:: cmake
install(TARGETS mylib myapp ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
It MUST NOT be used for installing plugins, system admin executables or
executables only intended for use internally by other code. Those should use
``KDE_INSTALL_PLUGINDIR``, ``KDE_INSTALL_SBINDIR`` or
``KDE_INSTALL_LIBEXECDIR`` respectively.
Additionally, ``CMAKE_INSTALL_DEFAULT_COMPONENT_NAME`` will be set to
``${PROJECT_NAME}`` to provide a sensible default for this CMake option.
Note that mixing absolute and relative paths, particularly for ``BINDIR``,
``LIBDIR`` and ``INCLUDEDIR``, can cause issues with exported targets. Given
that the default values for these are relative paths, relative paths should
be used on the command line when possible (eg: use
``-DKDE_INSTALL_LIBDIR=lib64`` instead of
``-DKDE_INSTALL_LIBDIR=/usr/lib/lib64`` to override the library directory).
Since 5.82.0, prior to that available as :kde-module:`KDEInstallDirs`.
NB: The variables starting ``KDE_INSTALL_`` are available since 1.6.0,
unless otherwise noted with the variable.
The ``KDE_INSTALL_PREFIX_SCRIPT`` option will install a ${CMAKE_INSTALL_PREFIX}/prefix.sh
file that allows to easily incorporate the necessary environment variables
for the prefix into a process.
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/KDEInstallDirsCommon.cmake)
if(WIN32)
_define_non_cache(LIBEXECDIR_KF5 "${CMAKE_INSTALL_LIBEXECDIR}")
else()
_define_non_cache(LIBEXECDIR_KF5 "${CMAKE_INSTALL_LIBEXECDIR}/kf5")
endif()
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED)
set(KF5_LIBEXEC_INSTALL_DIR "${CMAKE_INSTALL_LIBEXECDIR_KF5}")
endif()
include("${ECM_MODULE_DIR}/ECMQueryQt.cmake")
set(_default_KDE_INSTALL_USE_QT_SYS_PATHS OFF)
if(NOT DEFINED KDE_INSTALL_USE_QT_SYS_PATHS)
ecm_query_qt(qt_install_prefix_dir QT_INSTALL_PREFIX TRY)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
message(STATUS "Installing in the same prefix as Qt, adopting their path scheme.")
set(_default_KDE_INSTALL_USE_QT_SYS_PATHS ON)
endif()
endif()
option (KDE_INSTALL_USE_QT_SYS_PATHS "Install mkspecs files, QCH files for Qt-based libs, Plugins and Imports to the Qt 5 install dir" "${_default_KDE_INSTALL_USE_QT_SYS_PATHS}")
if(KDE_INSTALL_USE_QT_SYS_PATHS)
# Qt-specific vars
ecm_query_qt(qt_install_prefix_dir QT_INSTALL_PREFIX TRY)
ecm_query_qt(qt_plugins_dir QT_INSTALL_PLUGINS)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
file(RELATIVE_PATH qt_plugins_dir ${qt_install_prefix_dir} ${qt_plugins_dir})
endif()
_define_absolute(QTPLUGINDIR ${qt_plugins_dir}
"Qt plugins"
QT_PLUGIN_INSTALL_DIR)
ecm_query_qt(qt_imports_dir QT_INSTALL_IMPORTS)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
file(RELATIVE_PATH qt_imports_dir ${qt_install_prefix_dir} ${qt_imports_dir})
endif()
_define_absolute(QTQUICKIMPORTSDIR ${qt_imports_dir}
"QtQuick1 imports"
IMPORTS_INSTALL_DIR)
ecm_query_qt(qt_qml_dir QT_INSTALL_QML)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
file(RELATIVE_PATH qt_qml_dir ${qt_install_prefix_dir} ${qt_qml_dir})
endif()
_define_absolute(QMLDIR ${qt_qml_dir}
"QtQuick2 imports"
QML_INSTALL_DIR)
else()
set(_pluginsDirParent LIBDIR)
if (ANDROID)
set(_pluginsDirParent)
#androiddeployqt wants plugins right in the prefix
endif()
_define_relative(QTPLUGINDIR "${_pluginsDirParent}" "plugins"
"Qt plugins"
QT_PLUGIN_INSTALL_DIR)
_define_relative(QTQUICKIMPORTSDIR QTPLUGINDIR "imports"
"QtQuick1 imports"
IMPORTS_INSTALL_DIR)
_define_relative(QMLDIR LIBDIR "qml"
"QtQuick2 imports"
QML_INSTALL_DIR)
endif()
_define_relative(PLUGINDIR QTPLUGINDIR ""
"Plugins"
PLUGIN_INSTALL_DIR)
_define_non_cache(INCLUDEDIR_KF5 "${CMAKE_INSTALL_INCLUDEDIR}/KF5")
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED)
set(KF5_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR_KF5}")
endif()
_define_non_cache(DATADIR_KF5 "${CMAKE_INSTALL_DATADIR}/kf5")
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED)
set(KF5_DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR_KF5}")
endif()
# Qt-specific data vars
if(KDE_INSTALL_USE_QT_SYS_PATHS)
ecm_query_qt(qt_docs_dir QT_INSTALL_DOCS)
_define_absolute(QTQCHDIR ${qt_docs_dir}
"documentation bundles in QCH format for Qt-extending libraries")
else()
_define_relative(QTQCHDIR DATAROOTDIR "doc/qch"
"documentation bundles in QCH format for Qt-extending libraries")
endif()
# KDE Framework-specific things
_define_relative(KSERVICES5DIR DATAROOTDIR "kservices5"
"services for KDE Frameworks 5"
SERVICES_INSTALL_DIR KSERVICESDIR)
_define_relative(KSERVICETYPES5DIR DATAROOTDIR "kservicetypes5"
"service types for KDE Frameworks 5"
SERVICETYPES_INSTALL_DIR KSERVICETYPESDIR)
_define_relative(KNOTIFY5RCDIR DATAROOTDIR "knotifications5"
"knotify description files"
KNOTIFYRC_INSTALL_DIR KNOTIFYRCDIR)
_define_relative(KXMLGUI5DIR DATAROOTDIR "kxmlgui5"
"kxmlgui .rc files"
KXMLGUI_INSTALL_DIR KXMLGUIDIR)
_define_relative(LOGGINGCATEGORIESDIR DATAROOTDIR "qlogging-categories5"
"Qt Logging categories files")
# For more documentation see above.
# Later on it will be possible to extend this for installing OSX frameworks
# The COMPONENT Devel argument has the effect that static libraries belong to the
# "Devel" install component. If we use this also for all install() commands
# for header files, it will be possible to install
# -everything: make install OR cmake -P cmake_install.cmake
# -only the development files: cmake -DCOMPONENT=Devel -P cmake_install.cmake
# -everything except the development files: cmake -DCOMPONENT=Unspecified -P cmake_install.cmake
# This can then also be used for packaging with cpack.
set(KDE_INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT Devel
INCLUDES DESTINATION "${KDE_INSTALL_INCLUDEDIR}"
)
if(APPLE)
set(KDE_INSTALL_TARGETS_DEFAULT_ARGS ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}
BUNDLE DESTINATION "${BUNDLE_INSTALL_DIR}" )
endif()
set(KF5_INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT Devel
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR_KF5}"
)
# on macOS support an extra install directory for application bundles
if(APPLE)
set(KF5_INSTALL_TARGETS_DEFAULT_ARGS ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}
BUNDLE DESTINATION "${BUNDLE_INSTALL_DIR}" )
endif()
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED)
set(INSTALL_TARGETS_DEFAULT_ARGS ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
endif()
# version-less forward compatibility variants, see also KDEInstallDirs6.cmake
set(KF_INSTALL_TARGETS_DEFAULT_ARGS ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
_define_non_cache(INCLUDEDIR_KF "${KDE_INSTALL_INCLUDEDIR_KF5}")
_define_non_cache(DATADIR_KF "${KDE_INSTALL_DATADIR_KF5}")
_define_non_cache(LIBEXECDIR_KF "${KDE_INSTALL_LIBEXECDIR_KF5}")
include(${CMAKE_CURRENT_LIST_DIR}/KDESetupPrefixScript.cmake)
@@ -0,0 +1,303 @@
# SPDX-FileCopyrightText: 2014-2015 Alex Merry <alex.merry@kde.org>
# SPDX-FileCopyrightText: 2013 Stephen Kelly <steveire@gmail.com>
# SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
# SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
# SPDX-FileCopyrightText: 2021 Ahmad Samir <a.samir78@gmail.com>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
KDEInstallDirs6
---------------
Define KDE standard installation directories for Qt6/KF6 based software.
Note that none of the variables defined by this module provide any
information about the location of already-installed KDE software.
Also sets ``CMAKE_INSTALL_PREFIX`` to the installation prefix of ECM,
unless that variable has been already explicitly set by something else.
Inclusion of this module defines the following variables:
``KDE_INSTALL_<dir>``
destination for files of a given type
``KDE_INSTALL_FULL_<dir>``
corresponding absolute path
where ``<dir>`` is one of (default values in parentheses):
``BUNDLEDIR``
application bundles (``/Applications/KDE``)
``EXECROOTDIR``
executables and libraries (``<empty>``)
``BINDIR``
user executables (``EXECROOTDIR/bin``)
``SBINDIR``
system admin executables (``EXECROOTDIR/sbin``)
``LIBDIR``
object code libraries (``EXECROOTDIR/lib``, ``EXECROOTDIR/lib64`` or
``EXECROOTDIR/lib/<multiarch-tuple`` on Debian)
``LIBEXECDIR``
executables for internal use by programs and libraries (``BINDIR`` on
Windows, ``LIBDIR/libexec`` otherwise)
``CMAKEPACKAGEDIR``
CMake packages, including config files (``LIBDIR/cmake``)
``QTPLUGINDIR``
Qt plugins (``LIBDIR/plugins`` or qtpaths's ``QT_INSTALL_PLUGINS``)
``PLUGINDIR``
Plugins (``QTPLUGINDIR``) [``PLUGIN_INSTALL_DIR``]
``QMLDIR``
QtQuick2 imports (``LIBDIR/qml`` or qtpaths's ``QT_INSTALL_QML``)
``INCLUDEDIR``
C and C++ header files (``include``)
``LOCALSTATEDIR``
modifiable single-machine data (``var``)
``SHAREDSTATEDIR``
modifiable architecture-independent data (``com``)
``DATAROOTDIR``
read-only architecture-independent data root (``BINDIR/data`` on
Windows, ``share`` otherwise)
``DATADIR``
read-only architecture-independent data (``DATAROOTDIR``)
``DOCBUNDLEDIR``
documentation bundles generated using kdoctools
(``DATAROOTDIR/doc/HTML``)
``KCFGDIR``
kconfig description files (``DATAROOTDIR/config.kcfg``)
``KCONFUPDATEDIR``
kconf_update scripts (``DATAROOTDIR/kconf_update``)
``KXMLGUIDIR``
kxmlgui .rc files (``DATAROOTDIR/kxmlgui5``)
``KAPPTEMPLATESDIR``
KAppTemplate and KDevelop templates (``DATAROOTDIR/kdevappwizard/templates``)
``KFILETEMPLATESDIR``
KDevelop file templates (``DATAROOTDIR/kdevfiletemplates/templates``)
``KNOTIFYRCDIR``
knotify description files (``DATAROOTDIR/knotifications6``)
``ICONDIR``
icons (``DATAROOTDIR/icons``)
``LOCALEDIR``
locale-dependent data (``DATAROOTDIR/locale``)
``SOUNDDIR``
sound files (``DATAROOTDIR/sounds``)
``TEMPLATEDIR``
templates (``DATAROOTDIR/templates``)
``WALLPAPERDIR``
desktop wallpaper images (``DATAROOTDIR/wallpapers``)
``APPDIR``
application desktop files (``DATAROOTDIR/applications``)
``DESKTOPDIR``
desktop directories (``DATAROOTDIR/desktop-directories``)
``MIMEDIR``
mime description files (``DATAROOTDIR/mime/packages``)
``METAINFODIR``
AppStream component metadata files (``DATAROOTDIR/metainfo``)
``QTQCHDIR``
documentation bundles in QCH format for Qt-extending libraries (``DATAROOTDIR/doc/qch`` or qtpaths's ``QT_INSTALL_DOCS``)
``QCHDIR``
documentation bundles in QCH format (``DATAROOTDIR/doc/qch``)
``MANDIR``
man documentation (``DATAROOTDIR/man``)
``INFODIR``
info documentation (``DATAROOTDIR/info``)
``DBUSDIR``
D-Bus (``DATAROOTDIR/dbus-1``)
``DBUSINTERFACEDIR``
D-Bus interfaces (``DBUSDIR/interfaces``)
``DBUSSERVICEDIR``
D-Bus session services (``DBUSDIR/services``)
``DBUSSYSTEMSERVICEDIR``
D-Bus system services (``DBUSDIR/system-services``)
``SYSCONFDIR``
read-only single-machine data
(``etc``, or ``/etc`` if ``CMAKE_INSTALL_PREFIX`` is ``/usr``)
``CONFDIR``
application configuration files (``SYSCONFDIR/xdg``)
``AUTOSTARTDIR``
autostart files (``CONFDIR/autostart``)
``LOGGINGCATEGORIESDIR``
Qt logging categories files directory (``DATAROOTDIR/qlogging-categories6``)
``JARDIR``
Java AAR/JAR files for Android.
``SYSTEMDUNITDIR``
Systemd Units (``lib/systemd``)
``SYSTEMDUSERUNITDIR``
Systemd User Units (``lib/systemd/user``)
If ``KDE_INSTALL_USE_QT_SYS_PATHS`` is set to ``TRUE`` before including this
module, the default values for some variables are instead queried from
Qt6's qmake (where mentioned in the parentheses above).
If not set, it will default to ``TRUE`` if Qt6's qmake is found and
it's ``QT_INSTALL_PREFIX`` is the same as ``CMAKE_INSTALL_PREFIX``,
otherwise default to ``FALSE``.
This variable should NOT be set from within CMakeLists.txt files, instead
is intended to be set manually when configuring a project which uses
KDEInstallDirs (e.g. by packagers).
In addition, for each ``KDE_INSTALL_*`` variable, an equivalent
``CMAKE_INSTALL_*`` variable is defined, if such a variable is also
defined by the ``GNUInstallDirs`` module (shipped with CMake).
If ``KDE_INSTALL_DIRS_NO_CMAKE_VARIABLES`` is set to ``TRUE``, no variables with
a ``CMAKE_`` prefix will be defined by this module (other than
``CMAKE_INSTALL_DEFAULT_COMPONENT_NAME`` - see below).
The ``KDE_INSTALL_<dir>`` variables may be passed to the ``DESTINATION`` options of
``install()`` commands for the corresponding file type. They are set in the
CMake cache, and so the defaults above can be overridden by users.
Note that the ``KDE_INSTALL_<dir>`` or ``CMAKE_INSTALL_<dir>`` variables
can be changed using CMake command line variable definitions; in either case,
both forms of the variable will be affected. The effect of passing multiple
forms of the same variable on the command line
(such as ``KDE_INSTALL_BINDIR`` and ``CMAKE_INSTALL_BINDIR`` is undefined.
The variable ``KDE_INSTALL_TARGETS_DEFAULT_ARGS`` is also defined.
This should be used when libraries or user-executable applications are installed,
in the following manner:
.. code-block:: cmake
install(TARGETS mylib myapp ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
It MUST NOT be used for installing plugins, system admin executables or
executables only intended for use internally by other code. Those should use
``KDE_INSTALL_PLUGINDIR``, ``KDE_INSTALL_SBINDIR`` or
``KDE_INSTALL_LIBEXECDIR`` respectively.
Additionally, ``CMAKE_INSTALL_DEFAULT_COMPONENT_NAME`` will be set to
``${PROJECT_NAME}`` to provide a sensible default for this CMake option.
Note that mixing absolute and relative paths, particularly for ``BINDIR``,
``LIBDIR`` and ``INCLUDEDIR``, can cause issues with exported targets. Given
that the default values for these are relative paths, relative paths should
be used on the command line when possible (eg: use
``-DKDE_INSTALL_LIBDIR=lib64`` instead of
``-DKDE_INSTALL_LIBDIR=/usr/lib/lib64`` to override the library directory).
The ``KDE_INSTALL_PREFIX_SCRIPT`` option will install a ${CMAKE_INSTALL_PREFIX}/prefix.sh
file that allows to easily incorporate the necessary environment variables
for the prefix into a process.
#]=======================================================================]
set(KDE_INSTALL_DIRS_NO_DEPRECATED TRUE)
include(${CMAKE_CURRENT_LIST_DIR}/KDEInstallDirsCommon.cmake)
if(WIN32)
_define_non_cache(LIBEXECDIR_KF "${CMAKE_INSTALL_LIBEXECDIR}")
else()
_define_non_cache(LIBEXECDIR_KF "${CMAKE_INSTALL_LIBEXECDIR}/kf6")
endif()
include(${ECM_MODULE_DIR}/ECMQueryQt.cmake)
ecm_query_qt(qt_install_prefix_dir QT_INSTALL_PREFIX)
set(_qt_prefix_is_cmake_install_prefix FALSE)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
set(_qt_prefix_is_cmake_install_prefix TRUE)
endif()
set(_default_KDE_INSTALL_USE_QT_SYS_PATHS OFF)
if(NOT DEFINED KDE_INSTALL_USE_QT_SYS_PATHS)
if(_qt_prefix_is_cmake_install_prefix)
message(STATUS "Installing in the same prefix as Qt, adopting their path scheme.")
set(_default_KDE_INSTALL_USE_QT_SYS_PATHS ON)
endif()
endif()
option (KDE_INSTALL_USE_QT_SYS_PATHS
"Install mkspecs files, QCH files for Qt-based libs, Plugins and Imports to the Qt 6 install dir"
"${_default_KDE_INSTALL_USE_QT_SYS_PATHS}"
)
if(KDE_INSTALL_USE_QT_SYS_PATHS)
# Qt-specific vars
ecm_query_qt(qt_plugins_dir QT_INSTALL_PLUGINS)
if(_qt_prefix_is_cmake_install_prefix)
file(RELATIVE_PATH qt_plugins_dir ${qt_install_prefix_dir} ${qt_plugins_dir})
endif()
_define_absolute(QTPLUGINDIR ${qt_plugins_dir} "Qt plugins")
ecm_query_qt(qt_qml_dir QT_INSTALL_QML)
if(_qt_prefix_is_cmake_install_prefix)
file(RELATIVE_PATH qt_qml_dir ${qt_install_prefix_dir} ${qt_qml_dir})
endif()
_define_absolute(QMLDIR ${qt_qml_dir} "QtQuick2 imports")
else()
set(_pluginsDirParent LIBDIR)
if (ANDROID)
set(_pluginsDirParent)
#androiddeployqt wants plugins right in the prefix
endif()
_define_relative(QTPLUGINDIR "${_pluginsDirParent}" "plugins"
"Qt plugins")
_define_relative(QMLDIR LIBDIR "qml"
"QtQuick2 imports")
endif()
_define_relative(PLUGINDIR QTPLUGINDIR ""
"Plugins")
_define_non_cache(INCLUDEDIR_KF "${CMAKE_INSTALL_INCLUDEDIR}/KF6")
_define_non_cache(DATADIR_KF "${CMAKE_INSTALL_DATADIR}/kf6")
# Qt-specific data vars
if(KDE_INSTALL_USE_QT_SYS_PATHS)
ecm_query_qt(qt_docs_dir QT_INSTALL_DOCS)
_define_absolute(QTQCHDIR ${qt_docs_dir} "documentation bundles in QCH format for Qt-extending libraries")
else()
_define_relative(QTQCHDIR DATAROOTDIR "doc/qch"
"documentation bundles in QCH format for Qt-extending libraries")
endif()
# KDE Framework-specific things
_define_relative(KNOTIFYRCDIR DATAROOTDIR "knotifications6"
"knotify description files")
# TODO MOVE TO KXMLGUI
_define_relative(KXMLGUIDIR DATAROOTDIR "kxmlgui5"
"kxmlgui .rc files")
_define_relative(LOGGINGCATEGORIESDIR DATAROOTDIR "qlogging-categories6"
"Qt Logging categories files")
# For more documentation see above.
# Later on it will be possible to extend this for installing OSX frameworks
# The COMPONENT Devel argument has the effect that static libraries belong to the
# "Devel" install component. If we use this also for all install() commands
# for header files, it will be possible to install
# -everything: make install OR cmake -P cmake_install.cmake
# -only the development files: cmake -DCOMPONENT=Devel -P cmake_install.cmake
# -everything except the development files: cmake -DCOMPONENT=Unspecified -P cmake_install.cmake
# This can then also be used for packaging with cpack.
set(KDE_INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
OBJECTS DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT Devel
)
if(APPLE)
set(KDE_INSTALL_TARGETS_DEFAULT_ARGS ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}
BUNDLE DESTINATION "${KDE_INSTALL_BUNDLEDIR}" )
endif()
set(KF_INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
OBJECTS DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT Devel
)
# on macOS support an extra install directory for application bundles
if(APPLE)
set(KF_INSTALL_TARGETS_DEFAULT_ARGS ${KF_INSTALL_TARGETS_DEFAULT_ARGS}
BUNDLE DESTINATION "${KDE_INSTALL_BUNDLEDIR}" )
endif()
include(${CMAKE_CURRENT_LIST_DIR}/KDESetupPrefixScript.cmake)
@@ -0,0 +1,393 @@
# SPDX-FileCopyrightText: 2014-2015 Alex Merry <alex.merry@kde.org>
# SPDX-FileCopyrightText: 2013 Stephen Kelly <steveire@gmail.com>
# SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Common implementation details of KDEInstallDirsX.cmake, not public API.
#
# Figure out what the default install directory for libraries should be.
# This is based on the logic in GNUInstallDirs, but simplified (the
# GNUInstallDirs code deals with re-configuring, but that is dealt with
# by the _define_* macros in this module).
set(_LIBDIR_DEFAULT "lib")
# Override this default 'lib' with 'lib64' if:
# - we are on a Linux, kFreeBSD or Hurd system but NOT cross-compiling
# - we are NOT on debian
# - we are NOT on flatpak
# - we are NOT on NixOS
# - we are on a 64 bits system
# reason is: amd64 ABI: https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build
# For Debian with multiarch, use 'lib/${CMAKE_LIBRARY_ARCHITECTURE}' if
# CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
# See https://wiki.debian.org/Multiarch
if((CMAKE_SYSTEM_NAME MATCHES "Linux|kFreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "GNU")
AND NOT CMAKE_CROSSCOMPILING
AND NOT EXISTS "/etc/arch-release"
AND NOT DEFINED ENV{FLATPAK_ID}
AND NOT EXISTS "/etc/NIXOS")
if (EXISTS "/etc/debian_version") # is this a debian system ?
if(CMAKE_LIBRARY_ARCHITECTURE)
set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
endif()
else() # not debian, rely on CMAKE_SIZEOF_VOID_P:
if(NOT DEFINED CMAKE_SIZEOF_VOID_P)
message(AUTHOR_WARNING
"Unable to determine default LIB_INSTALL_LIBDIR directory because no target architecture is known. "
"Please enable at least one language before including KDEInstallDirs.")
else()
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(_LIBDIR_DEFAULT "lib64")
endif()
endif()
endif()
endif()
set(_gnu_install_dirs_vars
BINDIR
SBINDIR
LIBEXECDIR
SYSCONFDIR
SHAREDSTATEDIR
LOCALSTATEDIR
LIBDIR
INCLUDEDIR
OLDINCLUDEDIR
DATAROOTDIR
DATADIR
INFODIR
LOCALEDIR
MANDIR
DOCDIR)
# Macro for variables that are relative to another variable. We store an empty
# value in the cache (for documentation/GUI cache editor purposes), and store
# the default value in a local variable. If the cache variable is ever set to
# something non-empty, the local variable will no longer be set. However, if
# the cache variable remains (or is set to be) empty, the value will be
# relative to that of the parent variable.
#
# varname: the variable name suffix (eg: BINDIR for KDE_INSTALL_BINDIR)
# parent: the variable suffix of the variable this is relative to
# (eg: DATAROOTDIR for KDE_INSTALL_DATAROOTDIR)
# subdir: the path of the default value of KDE_INSTALL_${varname}
# relative to KDE_INSTALL_${parent}: no leading /
# docstring: documentation about the variable (not including the default value)
# oldstylename (optional): the old-style name of the variable
# alias (optional): alias for the variable (e.g. without '5' in the name)
macro(_define_relative varname parent subdir docstring)
set(_oldstylename)
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED AND ${ARGC} GREATER 4)
set(_oldstylename "${ARGV4}")
endif()
set(_aliasname)
if(${ARGC} GREATER 5)
set(_aliasname "${ARGV5}")
endif()
set(_cmakename)
if(NOT KDE_INSTALL_DIRS_NO_CMAKE_VARIABLES)
list(FIND _gnu_install_dirs_vars "${varname}" _list_offset)
set(_cmakename_is_deprecated FALSE)
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED OR NOT _list_offset EQUAL -1)
set(_cmakename CMAKE_INSTALL_${varname})
if(_list_offset EQUAL -1)
set(_cmakename_is_deprecated TRUE)
endif()
endif()
endif()
# Surprisingly complex logic to deal with joining paths.
# Note that we cannot use arg vars directly in if() because macro args are
# not proper variables.
set(_parent "${parent}")
set(_subdir "${subdir}")
if(_parent AND _subdir)
set(_docpath "${_parent}/${_subdir}")
if(KDE_INSTALL_${_parent})
set(_realpath "${KDE_INSTALL_${_parent}}/${_subdir}")
else()
set(_realpath "${_subdir}")
endif()
elseif(_parent)
set(_docpath "${_parent}")
set(_realpath "${KDE_INSTALL_${_parent}}")
else()
set(_docpath "${_subdir}")
set(_realpath "${_subdir}")
endif()
if(KDE_INSTALL_${varname})
# make sure the cache documentation is set correctly
get_property(_iscached CACHE KDE_INSTALL_${varname} PROPERTY VALUE SET)
if (_iscached)
# make sure the docs are still set if it was passed on the command line
set_property(CACHE KDE_INSTALL_${varname}
PROPERTY HELPSTRING "${docstring} (${_docpath})")
# make sure the type is correct if it was passed on the command line
set_property(CACHE KDE_INSTALL_${varname}
PROPERTY TYPE PATH)
endif()
elseif(${_oldstylename})
message(DEPRECATION "${_oldstylename} is deprecated, use KDE_INSTALL_${varname} instead.")
# The old name was given (probably on the command line): move
# it to the new name
set(KDE_INSTALL_${varname} "${${_oldstylename}}"
CACHE PATH
"${docstring} (${_docpath})"
FORCE)
elseif(${_aliasname})
# The alias variable was given (probably on the command line): move
# it to the new name
set(KDE_INSTALL_${varname} "${${_aliasname}}"
CACHE PATH
"${docstring} (${_docpath})"
FORCE)
elseif(${_cmakename})
if(_cmakename_is_deprecated)
message(DEPRECATION "${_cmakename} is deprecated, use KDE_INSTALL_${varname} instead.")
endif()
# The CMAKE_ name was given (probably on the command line): move
# it to the new name
set(KDE_INSTALL_${varname} "${${_cmakename}}"
CACHE PATH
"${docstring} (${_docpath})"
FORCE)
else()
# insert an empty value into the cache, indicating the default
# should be used (including compatibility vars above)
set(KDE_INSTALL_${varname} ""
CACHE PATH "${docstring} (${_docpath})")
set(KDE_INSTALL_${varname} "${_realpath}")
endif()
mark_as_advanced(KDE_INSTALL_${varname})
if(NOT IS_ABSOLUTE ${KDE_INSTALL_${varname}})
set(KDE_INSTALL_FULL_${varname}
"${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_${varname}}")
else()
set(KDE_INSTALL_FULL_${varname} "${KDE_INSTALL_${varname}}")
endif()
# Override compatibility vars at runtime, even though we don't touch
# them in the cache; this way, we keep the variables in sync where
# KDEInstallDirs is included, but don't interfere with, say,
# GNUInstallDirs in a parallel part of the CMake tree.
if(_cmakename)
set(${_cmakename} "${KDE_INSTALL_${varname}}")
set(CMAKE_INSTALL_FULL_${varname} "${KDE_INSTALL_FULL_${varname}}")
endif()
if(_oldstylename)
set(${_oldstylename} "${KDE_INSTALL_${varname}}")
endif()
if (_aliasname)
set(KDE_INSTALL_${_aliasname} "${KDE_INSTALL_${varname}}")
set(KDE_INSTALL_FULL_${_aliasname} "${KDE_INSTALL_FULL_${varname}}")
endif()
endmacro()
# varname: the variable name suffix (eg: BINDIR for KDE_INSTALL_BINDIR)
# dir: the relative path of the default value of KDE_INSTALL_${varname}
# relative to CMAKE_INSTALL_PREFIX: no leading /
# docstring: documentation about the variable (not including the default value)
# oldstylename (optional): the old-style name of the variable
macro(_define_absolute varname dir docstring)
_define_relative("${varname}" "" "${dir}" "${docstring}" ${ARGN})
endmacro()
macro(_define_non_cache varname value)
set(KDE_INSTALL_${varname} "${value}")
if(NOT IS_ABSOLUTE ${KDE_INSTALL_${varname}})
set(KDE_INSTALL_FULL_${varname}
"${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_${varname}}")
else()
set(KDE_INSTALL_FULL_${varname} "${KDE_INSTALL_${varname}}")
endif()
if(NOT KDE_INSTALL_DIRS_NO_CMAKE_VARIABLES)
list(FIND _gnu_install_dirs_vars "${varname}" _list_offset)
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED OR NOT _list_offset EQUAL -1)
set(CMAKE_INSTALL_${varname} "${KDE_INSTALL_${varname}}")
set(CMAKE_INSTALL_FULL_${varname} "${KDE_INSTALL_FULL_${varname}}")
endif()
endif()
endmacro()
if(APPLE)
_define_absolute(BUNDLEDIR "/Applications/KDE"
"application bundles"
BUNDLE_INSTALL_DIR)
endif()
# Only supported since cmake 3.7
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${ECM_PREFIX}" CACHE PATH "Install path prefix" FORCE)
endif()
_define_absolute(EXECROOTDIR ""
"executables and libraries"
EXEC_INSTALL_PREFIX)
_define_relative(BINDIR EXECROOTDIR "bin"
"user executables"
BIN_INSTALL_DIR)
_define_relative(SBINDIR EXECROOTDIR "sbin"
"system admin executables"
SBIN_INSTALL_DIR)
_define_relative(LIBDIR EXECROOTDIR "${_LIBDIR_DEFAULT}"
"object code libraries"
LIB_INSTALL_DIR)
if(WIN32)
_define_relative(LIBEXECDIR BINDIR ""
"executables for internal use by programs and libraries"
LIBEXEC_INSTALL_DIR)
else()
_define_relative(LIBEXECDIR LIBDIR "libexec"
"executables for internal use by programs and libraries"
LIBEXEC_INSTALL_DIR)
endif()
_define_relative(CMAKEPACKAGEDIR LIBDIR "cmake"
"CMake packages, including config files"
CMAKECONFIG_INSTALL_PREFIX)
_define_absolute(INCLUDEDIR "include"
"C and C++ header files"
INCLUDE_INSTALL_DIR)
_define_absolute(LOCALSTATEDIR "var"
"modifiable single-machine data")
_define_absolute(SHAREDSTATEDIR "com"
"modifiable architecture-independent data")
if (WIN32)
_define_relative(DATAROOTDIR BINDIR "data"
"read-only architecture-independent data root"
SHARE_INSTALL_PREFIX)
else()
_define_absolute(DATAROOTDIR "share"
"read-only architecture-independent data root"
SHARE_INSTALL_PREFIX)
endif()
_define_relative(DATADIR DATAROOTDIR ""
"read-only architecture-independent data"
DATA_INSTALL_DIR)
# KDE Framework-specific things
_define_relative(DOCBUNDLEDIR DATAROOTDIR "doc/HTML"
"documentation bundles generated using kdoctools"
HTML_INSTALL_DIR)
_define_relative(KCFGDIR DATAROOTDIR "config.kcfg"
"kconfig description files"
KCFG_INSTALL_DIR)
_define_relative(KCONFUPDATEDIR DATAROOTDIR "kconf_update"
"kconf_update scripts"
KCONF_UPDATE_INSTALL_DIR)
_define_relative(KAPPTEMPLATESDIR DATAROOTDIR "kdevappwizard/templates"
"KAppTemplate and KDevelop templates"
KDE_INSTALL_KTEMPLATESDIR
)
_define_relative(KFILETEMPLATESDIR DATAROOTDIR "kdevfiletemplates/templates"
"KDevelop file templates")
_define_relative(JARDIR "" "jar"
"Java AAR/JAR files for Android")
# Cross-desktop or other system things
_define_relative(ICONDIR DATAROOTDIR "icons"
"icons"
ICON_INSTALL_DIR)
_define_relative(LOCALEDIR DATAROOTDIR "locale"
"locale-dependent data"
LOCALE_INSTALL_DIR)
_define_relative(SOUNDDIR DATAROOTDIR "sounds"
"sound files"
SOUND_INSTALL_DIR)
_define_relative(TEMPLATEDIR DATAROOTDIR "templates"
"templates"
TEMPLATES_INSTALL_DIR)
_define_relative(WALLPAPERDIR DATAROOTDIR "wallpapers"
"desktop wallpaper images"
WALLPAPER_INSTALL_DIR)
_define_relative(APPDIR DATAROOTDIR "applications"
"application desktop files"
XDG_APPS_INSTALL_DIR)
_define_relative(DESKTOPDIR DATAROOTDIR "desktop-directories"
"desktop directories"
XDG_DIRECTORY_INSTALL_DIR)
_define_relative(MIMEDIR DATAROOTDIR "mime/packages"
"mime description files"
XDG_MIME_INSTALL_DIR)
_define_relative(METAINFODIR DATAROOTDIR "metainfo"
"AppStream component metadata")
_define_relative(QCHDIR DATAROOTDIR "doc/qch"
"documentation bundles in QCH format")
_define_relative(MANDIR DATAROOTDIR "man"
"man documentation"
MAN_INSTALL_DIR)
_define_relative(INFODIR DATAROOTDIR "info"
"info documentation")
_define_relative(DBUSDIR DATAROOTDIR "dbus-1"
"D-Bus")
_define_relative(DBUSINTERFACEDIR DBUSDIR "interfaces"
"D-Bus interfaces"
DBUS_INTERFACES_INSTALL_DIR)
_define_relative(DBUSSERVICEDIR DBUSDIR "services"
"D-Bus session services"
DBUS_SERVICES_INSTALL_DIR)
_define_relative(DBUSSYSTEMSERVICEDIR DBUSDIR "system-services"
"D-Bus system services"
DBUS_SYSTEM_SERVICES_INSTALL_DIR)
_define_relative(SYSTEMDUNITDIR CMAKE_INSTALL_PREFIX "lib/systemd"
"Systemd units"
SYSTEMD_UNIT_INSTALL_DIR)
_define_relative(SYSTEMDUSERUNITDIR SYSTEMDUNITDIR "user"
"Systemd user units"
SYSTEMD_USER_UNIT_INSTALL_DIR)
_define_relative(ZSHAUTOCOMPLETEDIR DATAROOTDIR "zsh/site-functions"
"Zsh functions and autocompletion definitions")
set(_default_sysconf_dir "etc")
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr")
set(_default_sysconf_dir "/etc")
endif()
_define_absolute(SYSCONFDIR "${_default_sysconf_dir}"
"read-only single-machine data"
SYSCONF_INSTALL_DIR)
_define_relative(CONFDIR SYSCONFDIR "xdg"
"application configuration files"
CONFIG_INSTALL_DIR)
_define_relative(AUTOSTARTDIR CONFDIR "autostart"
"autostart files"
AUTOSTART_INSTALL_DIR)
set(_mixed_core_path_styles FALSE)
if (IS_ABSOLUTE "${KDE_INSTALL_BINDIR}")
if (NOT IS_ABSOLUTE "${KDE_INSTALL_LIBDIR}" OR NOT IS_ABSOLUTE "${KDE_INSTALL_INCLUDEDIR}")
set(_mixed_core_path_styles )
endif()
else()
if (IS_ABSOLUTE "${KDE_INSTALL_LIBDIR}" OR IS_ABSOLUTE "${KDE_INSTALL_INCLUDEDIR}")
set(_mixed_core_path_styles TRUE)
endif()
endif()
if (_mixed_core_path_styles)
message(WARNING "KDE_INSTALL_BINDIR, KDE_INSTALL_LIBDIR and KDE_INSTALL_INCLUDEDIR should either all be absolute paths or all be relative paths.")
endif()
# new in cmake 2.8.9: this is used for all installed files which do not have a component set
# so set the default component name to the name of the project, if a project name has been set:
if(NOT "${PROJECT_NAME}" STREQUAL "Project")
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "${PROJECT_NAME}")
endif()
@@ -0,0 +1,79 @@
# SPDX-FileCopyrightText: 2022 Albert Astals Cid <aacid@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
KDEMetaInfoPlatformCheck
------------------------
By including this module there will be an automatic check between the supported
platforms listed in the metainfo.yaml file and the current platform
that is the target of the build
If the current platform that is the target of the build is not supported
a CMake ``FATAL_ERROR`` will be issued
The check can be ignored by setting ``KF_IGNORE_PLATFORM_CHECK`` to ``ON``.
Since 5.93
#]=======================================================================]
option(KF_IGNORE_PLATFORM_CHECK "Ignore the supported platform check against metainfo.yaml" OFF)
if ("$ENV{KF_IGNORE_PLATFORM_CHECK}" STREQUAL "ON")
message(WARNING "KF_IGNORE_PLATFORM_CHECK set to ON from the environment")
set(KF_IGNORE_PLATFORM_CHECK ON)
endif()
if (NOT "${KF_IGNORE_PLATFORM_CHECK}")
file(STRINGS metainfo.yaml MetaInfoContents)
set(_MetainfoParserInPlatforms false)
set(_MetainfoFoundSupportedPlatform false)
set(_MetainfoSupportedPlatforms "")
foreach(MetaInfoString IN LISTS MetaInfoContents)
if ("${MetaInfoString}" STREQUAL "platforms:")
set(_MetainfoParserInPlatforms true)
elseif(_MetainfoParserInPlatforms AND "${MetaInfoString}" MATCHES ".*name:[ \t\r\n]*(.*)")
list(APPEND _MetainfoSupportedPlatforms ${CMAKE_MATCH_1})
if (${CMAKE_MATCH_1} STREQUAL "Linux")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "FreeBSD")
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "OpenBSD")
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "Windows")
if (WIN32)
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "macOS")
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "Android")
if (ANDROID)
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "iOS")
if (IOS)
set(_MetainfoFoundSupportedPlatform true)
endif()
elseif (${CMAKE_MATCH_1} STREQUAL "All")
set(_MetainfoFoundSupportedPlatform true)
else()
list(POP_BACK _MetainfoSupportedPlatforms)
message(WARNING "Found platform not recognized by the metainfo platform parser: ${CMAKE_MATCH_1}")
endif()
elseif("${MetaInfoString}" MATCHES "^[A-Za-z0-9_]+:")
set(_MetainfoParserInPlatforms false)
endif()
endforeach()
if (NOT _MetainfoFoundSupportedPlatform)
message(FATAL_ERROR "Your current platform '${CMAKE_SYSTEM_NAME}' is not supported. The list of supported platorms is '${_MetainfoSupportedPlatforms}'.If you think this is a mistake or you are working on enabling the platform please build with the KF_IGNORE_PLATFORM_CHECK variable set to true")
endif()
endif()
@@ -0,0 +1,156 @@
# SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
# SPDX-FileCopyrightText: 2014 Simon Wächter <waechter.simon@gmail.com>
# SPDX-FileCopyrightText: 2013 Nico Kruber <nico.kruber@gmail.com>
# SPDX-FileCopyrightText: 2012 Jeremy Whiting <jpwhiting@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
KDEPackageAppTemplates
----------------------
Packages KApptemplate/KDevelop compatible application templates
This module provides a functionality to package in a tarball and
install project templates compatible with the format used by
KApptemplate and KDevelop. Useful for providing minimal examples
for the usage of the KDE Frameworks.
This module provides the following function:
::
kde_package_app_templates(TEMPLATES <template> [<template> [...]]
INSTALL_DIR <directory>)
``INSTALL_DIR`` is the directory to install the template package to.
In most cases you will want to use the variable ``KDE_INSTALL_KAPPTEMPLATESDIR``
from :kde-module:`KDEInstallDirs`.
``TEMPLATES`` lists subdirectories containing template files;
each ``<template>`` directory will be packaged into a file named
``<template>.tar.bz2`` and installed to the appropriate location.
The template is a minimal source tree of an application as if it was
an application project by itself, with names (file names or text inside)
the text files replaced by the following placeholders when needed:
``%{PROJECTDIRNAME}``
name of generated project base folder ex: ``%{APPNAMELC}`` for KAppTemplate
``%{APPNAME}``
project name as entered by user ex: MyKApp
``%{APPNAMELC}``
project name in lower case ex: mykapp
``%{APPNAMEUC}``
project name in upper case ex: MYKAPP
``%{CPP_TEMPLATE}``
license header for cpp file
``%{H_TEMPLATE}``
license header for h file
``%{AUTHOR}``
author name ex: George Ignacious
``%{EMAIL}``
author email ex: foo@bar.org
``%{VERSION}``
project version ex: 0.1
Deprecated:
``%{dest}``
path of generated project base folder, used in .kdevtemplate with the ``ShowFilesAfterGeneration`` entry
KDevelop >= 5.1.1 supports relative paths with that entry, making this placeholder obsolete
Multiple templates can be passed at once.
This function does nothing when cross-compiling.
Since 5.18
#]=======================================================================]
function(kde_package_app_templates)
if (CMAKE_CROSSCOMPILING)
return()
endif()
set(_oneValueArgs INSTALL_DIR)
set(_multiValueArgs TEMPLATES)
cmake_parse_arguments(ARG "" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN} )
if(NOT ARG_TEMPLATES)
message(FATAL_ERROR "No TEMPLATES argument given to kde_package_app_templates")
endif()
if(NOT ARG_INSTALL_DIR)
message(FATAL_ERROR "No INSTALL_DIR argument given to kde_package_app_templates")
endif()
find_program(_tar_executable NAMES gtar tar)
if(_tar_executable)
# NOTE: we also pass `--sort=name` here to check if the tar exe supports that
# this feature was only added in gnu tar v1.28
execute_process(
COMMAND ${_tar_executable} --sort=name --version
TIMEOUT 3
RESULT_VARIABLE _tar_exit
OUTPUT_VARIABLE _tar_version
ERROR_VARIABLE _tar_stderr
)
if("${_tar_exit}" EQUAL 0 AND "${_tar_version}" MATCHES "GNU tar")
set(GNU_TAR_FOUND ON)
else()
set(GNU_TAR_FOUND OFF)
endif()
else()
set(GNU_TAR_FOUND OFF)
endif()
foreach(_templateName ${ARG_TEMPLATES})
get_filename_component(_tmp_file ${_templateName} ABSOLUTE)
get_filename_component(_baseName ${_tmp_file} NAME_WE)
set(_template ${CMAKE_CURRENT_BINARY_DIR}/${_baseName}.tar.bz2)
# also enlist directories as deps to catch file removals
file(GLOB_RECURSE _subdirs_entries LIST_DIRECTORIES true CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_templateName}/*")
add_custom_target(${_baseName}_kapptemplate ALL DEPENDS ${_template})
if(GNU_TAR_FOUND)
# Honour SOURCE_DATE_EPOCH if set
if(DEFINED ENV{SOURCE_DATE_EPOCH})
set(TIMESTAMP $ENV{SOURCE_DATE_EPOCH})
else()
execute_process(
COMMAND "date" "+%s"
OUTPUT_VARIABLE TIMESTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# Make tar archive reproducible, the arguments are only available with GNU tar
add_custom_command(OUTPUT ${_template}
COMMAND ${_tar_executable} ARGS
--exclude .kdev_ignore --exclude .svn
--sort=name
--mode=go=rX,u+rw,a-s
--numeric-owner --owner=0 --group=0
--mtime="@${TIMESTAMP}"
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime
-c -j -f ${_template} .
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_templateName}
DEPENDS ${_subdirs_entries}
)
else()
add_custom_command(OUTPUT ${_template}
COMMAND ${CMAKE_COMMAND} -E tar "cvfj" ${_template} .
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_templateName}
DEPENDS ${_subdirs_entries}
)
endif()
install(FILES ${_template} DESTINATION ${ARG_INSTALL_DIR})
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_template}")
endforeach()
endfunction()
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2014-2015 Alex Merry <alex.merry@kde.org>
# SPDX-FileCopyrightText: 2013 Stephen Kelly <steveire@gmail.com>
# SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org>
# SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org>
# SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org>
# SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org>
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Prefix script setup code shared between KDEInstallDirsX.cmake, not public API.
#
if (CMAKE_CROSSCOMPILING)
# we can't run anything when cross-compiling, so no need to even bother with a prefix script in this case
return()
endif()
configure_file(${CMAKE_CURRENT_LIST_DIR}/prefix.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/prefix.sh @ONLY)
find_program(FISH_EXECUTABLE fish)
if(FISH_EXECUTABLE)
configure_file(${CMAKE_CURRENT_LIST_DIR}/prefix.sh.fish.cmake ${CMAKE_CURRENT_BINARY_DIR}/prefix.sh.fish @ONLY)
endif()
option(KDE_INSTALL_PREFIX_SCRIPT "Installs ${CMAKE_INSTALL_PREFIX}/prefix.sh that sets up the necessary environment variables" OFF)
if(KDE_INSTALL_PREFIX_SCRIPT)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/prefix.sh DESTINATION ${CMAKE_INSTALL_PREFIX} PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
endif()
if(NOT KDE_INSTALL_USE_QT_SYS_PATHS)
message("Installing in ${CMAKE_INSTALL_PREFIX}. Run ${CMAKE_CURRENT_BINARY_DIR}/prefix.sh to set the environment for ${CMAKE_PROJECT_NAME}.")
endif()
@@ -0,0 +1,37 @@
file(GLOB install_done "${INSTALL_FILES}")
if (install_done)
file(READ "${INSTALL_FILES}" out)
string(REPLACE "\n" ";" out "${out}")
else()
message("Not installed yet, skipping")
set(out "")
endif()
set(metadatafiles)
foreach(file IN LISTS out)
if(NOT (file MATCHES ".+\\.appdata.xml" OR file MATCHES ".+\\.metainfo.xml"))
continue()
endif()
if(EXISTS ${file})
list(APPEND metadatafiles ${file})
else()
message(WARNING "Could not find ${file}")
endif()
endforeach()
if(metadatafiles)
set(appstreamcliout "")
execute_process(COMMAND ${APPSTREAMCLI} validate --no-net ${metadatafiles}
ERROR_VARIABLE appstreamcliout
OUTPUT_VARIABLE appstreamcliout
RESULT_VARIABLE result
)
if(result EQUAL 0)
set(msgType STATUS)
else()
set(msgType FATAL_ERROR)
endif()
message(${msgType} ${appstreamcliout})
endif()
@@ -0,0 +1,91 @@
---
# SPDX-FileCopyrightText: 2019 Christoph Cullmann <cullmann@kde.org>
# SPDX-FileCopyrightText: 2019 Gernot Gebhard <gebhard@absint.com>
#
# SPDX-License-Identifier: MIT
# This file got automatically created by ECM, do not edit
# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the config options
# and https://community.kde.org/Policies/Frameworks_Coding_Style#Clang-format_automatic_code_formatting
# for clang-format tips & tricks
---
Language: JavaScript
DisableFormat: true
---
# Style for C++
Language: Cpp
# base is WebKit coding style: https://webkit.org/code-style-guidelines/
# below are only things set that diverge from this style!
BasedOnStyle: WebKit
# enforce C++11 (e.g. for std::vector<std::vector<lala>>
Standard: Cpp11
# 4 spaces indent
TabWidth: 4
# 2 * 80 wide lines
ColumnLimit: 160
# sort includes inside line separated groups
SortIncludes: true
# break before braces on function, namespace and class definitions.
BreakBeforeBraces: Linux
# CrlInstruction *a;
PointerAlignment: Right
# horizontally aligns arguments after an open bracket.
AlignAfterOpenBracket: Align
# don't move all parameters to new line
AllowAllParametersOfDeclarationOnNextLine: false
# no single line functions
AllowShortFunctionsOnASingleLine: None
# no single line enums
AllowShortEnumsOnASingleLine: false
# always break before you encounter multi line strings
AlwaysBreakBeforeMultilineStrings: true
# don't move arguments to own lines if they are not all on the same
BinPackArguments: false
# don't move parameters to own lines if they are not all on the same
BinPackParameters: false
# In case we have an if statement with multiple lines the operator should be at the beginning of the line
# but we do not want to break assignments
BreakBeforeBinaryOperators: NonAssignment
# format C++11 braced lists like function calls
Cpp11BracedListStyle: true
# do not put a space before C++11 braced lists
SpaceBeforeCpp11BracedList: false
# remove empty lines
KeepEmptyLinesAtTheStartOfBlocks: false
# no namespace indentation to keep indent level low
NamespaceIndentation: None
# we use template< without space.
SpaceAfterTemplateKeyword: false
# Always break after template declaration
AlwaysBreakTemplateDeclarations: true
# macros for which the opening brace stays attached.
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE , wl_resource_for_each, wl_resource_for_each_safe ]
# keep lambda formatting multi-line if not empty
AllowShortLambdasOnASingleLine: Empty
# We do not want clang-format to put all arguments on a new line
AllowAllArgumentsOnNextLine: false
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Based on okular/hooks/pre-commit, credits go to Albert Astals Cid
clang_format_major_version=@KDE_CLANG_FORMAT_MAJOR_VERSION@
if [[ ${clang_format_major_version:-1} -ge 14 ]]; then
readonly output=$(git clang-format --staged --extensions 'cpp,h,hpp,c' -v --diff)
else
readonly output=$(git clang-format --extensions 'cpp,h,hpp,c' -v --diff)
fi
if [[ ! -f .clang-format ]]; then
if [[ @HAS_CLANG_FORMAT_COMMAND_INCLUDED@ = TRUE ]]; then
echo "ERROR: no .clang-format file found in repository root, abort format"
echo " run cmake for this repository to generate it"
else
echo "ERROR: no .clang-format file found in repository root, abort format"
echo "Make sure the KDEClangFormat CMake module is included, which will copy the KDE .clang-format file during the CMake configuration."
echo "Alternatively you can manually copy a .clang-format file to the repository root directory."
fi
exit 1
fi
if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi
if [[ "$output" == *"clang-format did not modify any files"* ]]; then exit 0; fi
echo "ERROR: You have unformatted changes, please format your files. You can do this using the following commands:"
if [[ ${clang_format_major_version:-1} -ge 14 ]]; then
echo " git clang-format --staged --extensions 'cpp,h,hpp,c' # format the changed parts"
echo " git clang-format --staged --extensions 'cpp,h,hpp,c' --diff # preview the changes done by the formatter"
else
echo " git clang-format --extensions 'cpp,h,hpp,c' --force # format the changed parts"
echo " git clang-format --extensions 'cpp,h,hpp,c' --diff # preview the changes done by the formatter"
fi
exit 1
@@ -0,0 +1,9 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"if": {
"type": "object"
},
"then": {
"allOf": [@SCHEMA_INCLUDES@]
}
}
@@ -0,0 +1,3 @@
# Version in sysadmin/ci-utilities should be single source of truth
SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
SPDX-License-Identifier: BSD-2-Clause
@@ -0,0 +1,62 @@
#!/usr/bin/python3
# Version in sysadmin/ci-utilities should be single source of truth
# SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-License-Identifier: BSD-2-Clause
import os
import subprocess
import yaml
import sys
def get_changed_files():
result = subprocess.run(['git', 'diff', '--name-only', 'HEAD'], capture_output=True, text=True)
return [file for file in result.stdout.splitlines() if file.endswith('.json')]
def get_all_files():
files = []
for root, dirs, filenames in os.walk('.'):
for filename in filenames:
if filename.endswith('.json'):
files.append(os.path.join(root, filename))
return files
def filter_excluded_json_files(files):
config_file = '.kde-ci.yml'
# Check if the file exists
if os.path.exists(config_file):
with open(config_file, 'r') as file:
config = yaml.safe_load(file)
else:
print(f'{config_file} does not exist in current directory')
config = {}
# Extract excluded files, used for tests that intentionally have broken files
excluded_files = ['compile_commands.json', 'ci-utilities']
if 'Options' in config and 'json-validate-ignore' in config['Options']:
excluded_files += config['Options']['json-validate-ignore']
# Find JSON files
filtered_files = []
for file_path in files:
if not any(excluded_file in file_path for excluded_file in excluded_files):
filtered_files.append(file_path)
return filtered_files
is_kde_ci = "KDE_CI" in os.environ
if is_kde_ci:
files = get_all_files()
else:
files = get_changed_files()
files = filter_excluded_json_files(files)
if files:
files_option = ' '.join(files)
if len(sys.argv) > 1:
schemafile = sys.argv[1]
else:
schemafile = os.path.join(os.path.dirname(__file__), 'resources', 'kpluginmetadata.schema.json')
if is_kde_ci: # Only report files on CI, for pre-commit hook, we'd like to avoid verbose output in terminal sessions
print(f"Validating {files_option} with {schemafile}")
result = subprocess.run(['check-jsonschema', *files, '--schemafile', schemafile])
# Fail the pipeline if command failed
if result.returncode != 0:
exit(1)
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
${PRE_COMMIT_SCRIPTS}
@@ -0,0 +1,16 @@
export PATH=@KDE_INSTALL_FULL_BINDIR@:$PATH
# LD_LIBRARY_PATH only needed if you are building without rpath
# export LD_LIBRARY_PATH=@KDE_INSTALL_FULL_LIBDIR@:$LD_LIBRARY_PATH
export XDG_DATA_DIRS=@KDE_INSTALL_FULL_DATADIR@:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
export XDG_CONFIG_DIRS=@KDE_INSTALL_FULL_CONFDIR@:${XDG_CONFIG_DIRS:-/etc/xdg}
export QT_PLUGIN_PATH=@KDE_INSTALL_FULL_QTPLUGINDIR@:$QT_PLUGIN_PATH
export QML2_IMPORT_PATH=@KDE_INSTALL_FULL_QMLDIR@:$QML2_IMPORT_PATH
export QT_QUICK_CONTROLS_STYLE_PATH=@KDE_INSTALL_FULL_QMLDIR@/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH
export MANPATH=@KDE_INSTALL_FULL_DATADIR@/man:${MANPATH:-/usr/local/share/man:/usr/share/man}
export SASL_PATH=@KDE_INSTALL_FULL_LIBDIR@/sasl2:${SASL_PATH:-/usr/@CMAKE_INSTALL_LIBDIR@/sasl2}
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
# SPDX-License-Identifier: BSD-3-Clause
set PATH "@KDE_INSTALL_FULL_BINDIR@:$PATH"
# LD_LIBRARY_PATH only needed if you are building without rpath
# set -x LD_LIBRARY_PATH "@KDE_INSTALL_FULL_LIBDIR@:$LD_LIBRARY_PATH"
if test -z "$XDG_DATA_DIRS"
set -x --path XDG_DATA_DIRS /usr/local/share/ /usr/share/
end
set -x --path XDG_DATA_DIRS "@KDE_INSTALL_FULL_DATADIR@" $XDG_DATA_DIRS
if test -z "$XDG_CONFIG_DIRS"
set -x --path XDG_CONFIG_DIRS /etc/xdg
end
set -x --path XDG_CONFIG_DIRS "@KDE_INSTALL_FULL_CONFDIR@" $XDG_CONFIG_DIRS
set -x --path QT_PLUGIN_PATH "@KDE_INSTALL_FULL_QTPLUGINDIR@" $QT_PLUGIN_PATH
set -x --path QML2_IMPORT_PATH "@KDE_INSTALL_FULL_QMLDIR@" $QML2_IMPORT_PATH
set -x --path QT_QUICK_CONTROLS_STYLE_PATH "@KDE_INSTALL_FULL_QMLDIR@/QtQuick/Controls.2/" $QT_QUICK_CONTROLS_STYLE_PATH