Warning, /frameworks/extra-cmake-modules/kde-modules/KDECMakeSettings.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kde.org> 0002 # SPDX-FileCopyrightText: 2013 Aleix Pol <aleixpol@kde.org> 0003 # SPDX-FileCopyrightText: 2012-2013 Stephen Kelly <steveire@gmail.com> 0004 # SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org> 0005 # SPDX-FileCopyrightText: 2006-2007 Laurent Montel <montel@kde.org> 0006 # SPDX-FileCopyrightText: 2006-2013 Alex Neundorf <neundorf@kde.org> 0007 # 0008 # SPDX-License-Identifier: BSD-3-Clause 0009 0010 #[=======================================================================[.rst: 0011 KDECMakeSettings 0012 ---------------- 0013 0014 Changes various CMake settings to what the KDE community views as more 0015 sensible defaults. 0016 0017 It is recommended to include this module with the ``NO_POLICY_SCOPE`` flag, 0018 otherwise you may get spurious warnings with some versions of CMake. 0019 0020 It is split into three parts, which can be independently disabled if desired. 0021 0022 Runtime Paths 0023 ~~~~~~~~~~~~~ 0024 0025 The default runtime path (used on Unix systems to search for 0026 dynamically-linked libraries) is set to include the location that libraries 0027 will be installed to (as set in ``LIB_INSTALL_DIR`` or, if the former is not set, 0028 ``KDE_INSTALL_LIBDIR``), and also the linker search path. 0029 0030 .. note:: 0031 ``LIB_INSTALL_DIR`` or alternatively ``KDE_INSTALL_LIBDIR`` needs 0032 to be set before including this module. 0033 Typically, this is done by including the :kde-module:`KDEInstallDirs` module. 0034 0035 This section can be disabled by setting ``KDE_SKIP_RPATH_SETTINGS`` to ``TRUE`` 0036 before including this module. 0037 0038 0039 Testing 0040 ~~~~~~~ 0041 0042 Testing is enabled by default, and an option ``BUILD_TESTING`` is provided for 0043 users to control this. See the CTest module documentation in the CMake manual 0044 for more details. 0045 0046 This section can be disabled by setting ``KDE_SKIP_TEST_SETTINGS`` to ``TRUE`` 0047 before including this module. 0048 0049 0050 Build Settings 0051 ~~~~~~~~~~~~~~ 0052 0053 Various CMake build defaults are altered, such as searching source and build 0054 directories for includes first, enabling automoc by default. 0055 0056 When ``find_package(ECM 5.38)`` or higher is called, this also selects 0057 a layout for the build dir that helps running executables without installing: 0058 all executables are built into a toplevel "bin" dir, making it possible to find 0059 helper binaries, and to find uninstalled plugins (provided that you use 0060 ``kcoreaddons_add_plugin()`` or set ``LIBRARY_OUTPUT_DIRECTORY`` as documented on 0061 https://community.kde.org/Guidelines_and_HOWTOs/Making_apps_run_uninstalled). 0062 0063 This section can be disabled by setting ``KDE_SKIP_BUILD_SETTINGS`` to ``TRUE`` 0064 before including this module. 0065 0066 This section also provides an ``uninstall`` target that can be individually 0067 disabled by setting ``KDE_SKIP_UNINSTALL_TARGET`` to ``TRUE`` before including 0068 this module. 0069 0070 By default on OS X, X11 and XCB related detections are disabled. However if 0071 the need would arise to use these technologies, the detection can be enabled 0072 by setting ``APPLE_FORCE_X11`` to ``ON``. 0073 0074 A warning is printed for the developer to know that the detection is disabled on OS X. 0075 This message can be turned off by setting ``APPLE_SUPPRESS_X11_WARNING`` to ``ON``. 0076 0077 Since pre-1.0.0. 0078 0079 ``ENABLE_CLAZY`` option is added (``OFF`` by default) when clang is being used. 0080 Turning this option on will force clang to load the clazy plugins for richer 0081 warnings on Qt-related code. 0082 0083 If clang is not being used, this won't have an effect. 0084 See https://commits.kde.org/clazy?path=README.md 0085 0086 Since 5.17.0 0087 0088 - ``uninstall`` target functionality since 1.7.0 0089 - ``APPLE_FORCE_X11`` option since 5.14.0 (detecting X11 was previously the default behavior) 0090 - ``APPLE_SUPPRESS_X11_WARNING`` option since 5.14.0 0091 - ``CMAKE_AUTORCC`` enabled by default when supported by CMake (>= 3.0) since 5.62.0 0092 0093 Translations (deprecated) 0094 ~~~~~~~~~~~~~~~~~~~~~~~~~ 0095 A fetch-translations target will be set up that will download translations 0096 for projects using l10n.kde.org. 0097 0098 ``KDE_L10N_BRANCH`` will be responsible for choosing which l10n branch to use 0099 for the translations. 0100 0101 ``KDE_L10N_AUTO_TRANSLATIONS`` (``OFF`` by default) will indicate whether translations 0102 should be downloaded when building the project. 0103 0104 Since 5.34.0 0105 0106 ``KDE_L10N_SYNC_TRANSLATIONS`` (``OFF`` by default) will download the translations at configuration 0107 time instead of build time. 0108 0109 Since 5.50.0 0110 0111 All ``KDE_L10N_*`` options have been deprecated since 5.102.0, as translations 0112 are meanwhile present inside the source code repositories. 0113 #]=======================================================================] 0114 0115 ################# RPATH handling ################################## 0116 0117 if(NOT KDE_SKIP_RPATH_SETTINGS) 0118 0119 # Set the default RPATH to point to useful locations, namely where the 0120 # libraries will be installed and the linker search path 0121 0122 # First look for the old LIB_INSTALL_DIR, then fallback to newer KDE_INSTALL_LIBDIR 0123 if(NOT LIB_INSTALL_DIR) 0124 if(NOT KDE_INSTALL_LIBDIR) 0125 message(FATAL_ERROR "Neither KDE_INSTALL_LIBDIR nor LIB_INSTALL_DIR is set. Setting one is necessary for using the RPATH settings.") 0126 else() 0127 set(_abs_LIB_INSTALL_DIR "${KDE_INSTALL_LIBDIR}") 0128 endif() 0129 else() 0130 set(_abs_LIB_INSTALL_DIR "${LIB_INSTALL_DIR}") 0131 endif() 0132 0133 if (NOT IS_ABSOLUTE "${_abs_LIB_INSTALL_DIR}") 0134 set(_abs_LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") 0135 endif() 0136 0137 if (UNIX) 0138 # for mac os: add install name dir in addition 0139 # check: is the rpath stuff below really required on mac os? at least it seems so to use a stock qt from qt.io 0140 if (APPLE) 0141 set(CMAKE_INSTALL_NAME_DIR ${_abs_LIB_INSTALL_DIR}) 0142 endif () 0143 0144 # add our LIB_INSTALL_DIR to the RPATH (but only when it is not one of 0145 # the standard system link directories - such as /usr/lib on UNIX) 0146 list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemLibDir) 0147 list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemCxxLibDir) 0148 list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${_abs_LIB_INSTALL_DIR}" _isSystemCLibDir) 0149 if("${_isSystemLibDir}" STREQUAL "-1" AND "${_isSystemCxxLibDir}" STREQUAL "-1" AND "${_isSystemCLibDir}" STREQUAL "-1") 0150 set(CMAKE_INSTALL_RPATH "${_abs_LIB_INSTALL_DIR}") 0151 endif() 0152 0153 # Append directories in the linker search path (but outside the project) 0154 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 0155 endif (UNIX) 0156 0157 endif() 0158 0159 ################ Testing setup #################################### 0160 0161 find_program(APPSTREAMCLI appstreamcli) 0162 function(appstreamtest) 0163 if(APPSTREAMCLI AND NOT appstreamtest_added) 0164 set(appstreamtest_added TRUE PARENT_SCOPE) 0165 add_test(NAME appstreamtest COMMAND ${CMAKE_COMMAND} -DAPPSTREAMCLI=${APPSTREAMCLI} -DINSTALL_FILES=${CMAKE_BINARY_DIR}/install_manifest.txt -P ${CMAKE_CURRENT_LIST_DIR}/appstreamtest.cmake) 0166 else() 0167 message(STATUS "Could not set up the appstream test. appstreamcli is missing.") 0168 endif() 0169 endfunction() 0170 0171 if(NOT KDE_SKIP_TEST_SETTINGS) 0172 0173 # If there is a CTestConfig.cmake, include CTest. 0174 # Otherwise, there will not be any useful settings, so just 0175 # fake the functionality we care about from CTest. 0176 0177 if (EXISTS ${CMAKE_SOURCE_DIR}/CTestConfig.cmake) 0178 include(CTest) 0179 else() 0180 option(BUILD_TESTING "Build the testing tree." ON) 0181 if(BUILD_TESTING) 0182 enable_testing() 0183 appstreamtest() 0184 endif () 0185 endif () 0186 0187 endif() 0188 0189 0190 0191 ################ Build-related settings ########################### 0192 0193 if(NOT KDE_SKIP_BUILD_SETTINGS) 0194 0195 # Always include srcdir and builddir in include path 0196 # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} in about every subdir 0197 # since cmake 2.4.0 0198 set(CMAKE_INCLUDE_CURRENT_DIR ON) 0199 0200 # put the include dirs which are in the source or build tree 0201 # before all other include dirs, so the headers in the sources 0202 # are preferred over the already installed ones 0203 # since cmake 2.4.1 0204 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 0205 0206 # Add the src and build dir to the BUILD_INTERFACE include directories 0207 # of all targets. Similar to CMAKE_INCLUDE_CURRENT_DIR, but transitive. 0208 # Since CMake 2.8.11 0209 set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) 0210 0211 # When a shared library changes, but its includes do not, don't relink 0212 # all dependencies. It is not needed. 0213 # Since CMake 2.8.11 0214 set(CMAKE_LINK_DEPENDS_NO_SHARED ON) 0215 0216 # Default to shared libs for KDE, if no type is explicitly given to add_library(): 0217 set(BUILD_SHARED_LIBS TRUE CACHE BOOL "If enabled, shared libs will be built by default, otherwise static libs") 0218 0219 # Enable automoc in cmake 0220 # Since CMake 2.8.6 0221 set(CMAKE_AUTOMOC ON) 0222 0223 # Enable autorcc and in cmake so qrc files get generated. 0224 # Since CMake 3.0 0225 # TODO KF6: discuss enabling AUTOUIC and note porting requirements. autouic 0226 # acts on all #include "ui_*.h" assuming *.ui exists 0227 set(CMAKE_AUTORCC ON) 0228 0229 # By default, create 'GUI' executables. This can be reverted on a per-target basis 0230 # using ECMMarkNonGuiExecutable 0231 # Since CMake 2.8.8 0232 set(CMAKE_WIN32_EXECUTABLE ON) 0233 set(CMAKE_MACOSX_BUNDLE ON) 0234 0235 # By default, don't put a prefix on MODULE targets. add_library(MODULE) is basically for plugin targets, 0236 # and in KDE plugins don't have a prefix. 0237 set(CMAKE_SHARED_MODULE_PREFIX "") 0238 0239 unset(EXECUTABLE_OUTPUT_PATH) 0240 unset(LIBRARY_OUTPUT_PATH) 0241 unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 0242 unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) 0243 unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY) 0244 0245 # under Windows, output all executables and dlls into 0246 # one common directory, and all static|import libraries and plugins 0247 # into another one. This way test executables can find their dlls 0248 # even without installation. 0249 0250 # We do the same under Unix to make it possible to run tests and apps without installing 0251 if (WIN32 OR ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.38.0) 0252 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 0253 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0254 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0255 endif() 0256 0257 # For Android we need to put shared libraries into "lib" for androiddeployqt to work without prior installation. 0258 # That fact that this conflicts with the above isn't really an issue, as we can't run things while cross-compiling 0259 # for Android anyway. 0260 if (ANDROID) 0261 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 0262 endif() 0263 0264 if (APPLE) 0265 # Disable detection of X11 and related package on OS X because when using 0266 # brew or macports, X11 can be installed and thus is detected. 0267 option(APPLE_FORCE_X11 "Force enable X11 related detection on OS X" OFF) 0268 option(APPLE_SUPPRESS_X11_WARNING "Suppress X11 and related technologies search disabling warning on OS X" OFF) 0269 0270 if(NOT APPLE_FORCE_X11) 0271 if (NOT APPLE_SUPPRESS_X11_WARNING) 0272 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.") 0273 endif() 0274 set(CMAKE_DISABLE_FIND_PACKAGE_X11 true) 0275 set(CMAKE_DISABLE_FIND_PACKAGE_XCB true) 0276 set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true) 0277 endif() 0278 endif() 0279 0280 option(KDE_SKIP_UNINSTALL_TARGET "Prevent an \"uninstall\" target from being generated." OFF) 0281 if(NOT KDE_SKIP_UNINSTALL_TARGET) 0282 include("${ECM_MODULE_DIR}/ECMUninstallTarget.cmake") 0283 endif() 0284 0285 endif() 0286 0287 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 0288 option(ENABLE_CLAZY "Enable Clazy warnings" OFF) 0289 0290 if(ENABLE_CLAZY) 0291 find_library(CLAZY_v1_5_FOUND ClazyPlugin${CMAKE_SHARED_LIBRARY_SUFFIX}) 0292 if(CLAZY_v1_5_FOUND) # clazy >= 1.5 0293 set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClazyPlugin${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clazy") 0294 else() # clazy < 1.5 0295 set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClangLazy${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clang-lazy") 0296 endif() 0297 endif() 0298 endif() 0299 0300 ################################################################### 0301 # Download translations 0302 0303 function(_repository_name reponame dir) 0304 execute_process(COMMAND git rev-parse --symbolic-full-name @{u} 0305 OUTPUT_VARIABLE upstream_ref 0306 RESULT_VARIABLE exitCode 0307 WORKING_DIRECTORY "${dir}") 0308 if(exitCode EQUAL 0) 0309 string(REGEX REPLACE "refs/remotes/([^/]+)/.*" "\\1" gitorigin "${upstream_ref}") 0310 message(DEBUG "Git upstream inferred as ${gitorigin}, upstream ref was ${upstream_ref}") 0311 else() 0312 set(gitorigin "origin") 0313 message(DEBUG "Assuming origin as the git remote as we are in detached mode") 0314 endif() 0315 0316 execute_process(COMMAND git remote get-url --all "${gitorigin}" 0317 OUTPUT_VARIABLE giturl 0318 RESULT_VARIABLE exitCode 0319 WORKING_DIRECTORY "${dir}") 0320 0321 if(exitCode EQUAL 0) 0322 message(DEBUG "Git URL inferred as ${giturl}") 0323 string(REGEX MATCHALL ".+kde\\.org[:\\/]([-A-Za-z0-9\\/]+)(.git)?\\s*" "" ${giturl}) 0324 set(${reponame} ${CMAKE_MATCH_1}) 0325 message(DEBUG "Repository inferred as ${${reponame}}") 0326 endif() 0327 0328 if(NOT ${reponame}) 0329 set(${reponame} ${CMAKE_PROJECT_NAME}) 0330 endif() 0331 set(${reponame} ${${reponame}} PARENT_SCOPE) 0332 endfunction() 0333 0334 if(NOT EXISTS ${CMAKE_SOURCE_DIR}/po AND NOT TARGET fetch-translations) 0335 option(KDE_L10N_AUTO_TRANSLATIONS "Automatically 'make fetch-translations`" OFF) 0336 option(KDE_L10N_SYNC_TRANSLATIONS "Fetch translations when KDECMakeSettings.cmake is processed." OFF) 0337 set(KDE_L10N_BRANCH "trunk" CACHE STRING "Branch from l10n.kde.org to fetch from: trunk | stable | lts | trunk_kde4 | stable_kde4") 0338 0339 if(KDE_L10N_AUTO_TRANSLATIONS AND NOT KDE_L10N_SYNC_TRANSLATIONS) 0340 set(_EXTRA_ARGS "ALL") 0341 else() 0342 set(_EXTRA_ARGS) 0343 endif() 0344 0345 set(_reponame "") 0346 _repository_name(_reponame "${CMAKE_SOURCE_DIR}") 0347 0348 set(releaseme_clone_commands 0349 COMMAND git clone --depth 1 https://invent.kde.org/sdk/releaseme.git 0350 ) 0351 add_custom_command( 0352 OUTPUT "${CMAKE_BINARY_DIR}/releaseme" 0353 ${releaseme_clone_commands} 0354 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" 0355 COMMENT "Fetching releaseme scripts to download translations..." 0356 ) 0357 0358 set(_l10n_po_dir "${CMAKE_BINARY_DIR}/po") 0359 set(_l10n_poqm_dir "${CMAKE_BINARY_DIR}/poqm") 0360 0361 set(extra BYPRODUCTS ${_l10n_po_dir} ${_l10n_poqm_dir}) 0362 0363 set(fetch_commands 0364 COMMAND ruby "${CMAKE_BINARY_DIR}/releaseme/fetchpo.rb" 0365 --origin ${KDE_L10N_BRANCH} 0366 --project "${_reponame}" 0367 --output-dir "${_l10n_po_dir}" 0368 --output-poqm-dir "${_l10n_poqm_dir}" 0369 "${CMAKE_CURRENT_SOURCE_DIR}" 0370 ) 0371 0372 add_custom_target(fetch-translations ${_EXTRA_ARGS} 0373 COMMENT "Downloading translations for ${_reponame} branch ${KDE_L10N_BRANCH}..." 0374 COMMAND git -C "${CMAKE_BINARY_DIR}/releaseme" pull 0375 COMMAND cmake -E remove_directory ${_l10n_po_dir} 0376 COMMAND cmake -E remove_directory ${_l10n_poqm_dir} 0377 ${fetch_commands} 0378 ${extra} 0379 DEPENDS "${CMAKE_BINARY_DIR}/releaseme" 0380 ) 0381 0382 if (KDE_L10N_SYNC_TRANSLATIONS AND (NOT EXISTS ${_l10n_po_dir} OR NOT EXISTS ${_l10n_poqm_dir})) 0383 execute_process(${releaseme_clone_commands}) 0384 execute_process(${fetch_commands}) 0385 endif() 0386 endif()