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}/${_abs_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 cmake_policy(PUSH) 0164 cmake_policy(SET CMP0064 NEW) # enable TEST operator 0165 if(APPSTREAMCLI AND NOT TEST appstreamtest) 0166 add_test(NAME appstreamtest COMMAND ${CMAKE_COMMAND} -DAPPSTREAMCLI=${APPSTREAMCLI} -DINSTALL_FILES=${CMAKE_BINARY_DIR}/install_manifest.txt -P ${CMAKE_CURRENT_LIST_DIR}/appstreamtest.cmake) 0167 else() 0168 message(STATUS "Could not set up the appstream test. appstreamcli is missing.") 0169 endif() 0170 cmake_policy(POP) 0171 endfunction() 0172 0173 if(NOT KDE_SKIP_TEST_SETTINGS) 0174 0175 # If there is a CTestConfig.cmake, include CTest. 0176 # Otherwise, there will not be any useful settings, so just 0177 # fake the functionality we care about from CTest. 0178 0179 if (EXISTS ${CMAKE_SOURCE_DIR}/CTestConfig.cmake) 0180 include(CTest) 0181 else() 0182 option(BUILD_TESTING "Build the testing tree." ON) 0183 if(BUILD_TESTING) 0184 enable_testing() 0185 appstreamtest() 0186 endif () 0187 endif () 0188 0189 endif() 0190 0191 0192 0193 ################ Build-related settings ########################### 0194 0195 if(NOT KDE_SKIP_BUILD_SETTINGS) 0196 0197 # Always include srcdir and builddir in include path 0198 # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} in about every subdir 0199 # since cmake 2.4.0 0200 set(CMAKE_INCLUDE_CURRENT_DIR ON) 0201 0202 # put the include dirs which are in the source or build tree 0203 # before all other include dirs, so the headers in the sources 0204 # are preferred over the already installed ones 0205 # since cmake 2.4.1 0206 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 0207 0208 # Add the src and build dir to the BUILD_INTERFACE include directories 0209 # of all targets. Similar to CMAKE_INCLUDE_CURRENT_DIR, but transitive. 0210 # Since CMake 2.8.11 0211 set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) 0212 0213 # When a shared library changes, but its includes do not, don't relink 0214 # all dependencies. It is not needed. 0215 # Since CMake 2.8.11 0216 set(CMAKE_LINK_DEPENDS_NO_SHARED ON) 0217 0218 # Default to shared libs for KDE, if no type is explicitly given to add_library(): 0219 set(BUILD_SHARED_LIBS TRUE CACHE BOOL "If enabled, shared libs will be built by default, otherwise static libs") 0220 0221 # Enable automoc in cmake 0222 # Since CMake 2.8.6 0223 set(CMAKE_AUTOMOC ON) 0224 0225 # Enable autorcc and in cmake so qrc files get generated. 0226 # Since CMake 3.0 0227 # TODO KF6: discuss enabling AUTOUIC and note porting requirements. autouic 0228 # acts on all #include "ui_*.h" assuming *.ui exists 0229 set(CMAKE_AUTORCC ON) 0230 0231 # By default, create 'GUI' executables. This can be reverted on a per-target basis 0232 # using ECMMarkNonGuiExecutable 0233 # Since CMake 2.8.8 0234 set(CMAKE_WIN32_EXECUTABLE ON) 0235 set(CMAKE_MACOSX_BUNDLE ON) 0236 0237 # By default, don't put a prefix on MODULE targets. add_library(MODULE) is basically for plugin targets, 0238 # and in KDE plugins don't have a prefix. 0239 set(CMAKE_SHARED_MODULE_PREFIX "") 0240 0241 unset(EXECUTABLE_OUTPUT_PATH) 0242 unset(LIBRARY_OUTPUT_PATH) 0243 unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 0244 unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) 0245 unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY) 0246 0247 # under Windows, output all executables and dlls into 0248 # one common directory, and all static|import libraries and plugins 0249 # into another one. This way test executables can find their dlls 0250 # even without installation. 0251 0252 # We do the same under Unix to make it possible to run tests and apps without installing 0253 if (WIN32 OR ECM_GLOBAL_FIND_VERSION VERSION_GREATER_EQUAL 5.38.0) 0254 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 0255 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0256 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0257 endif() 0258 0259 # For Android we need to put shared libraries into "lib" for androiddeployqt to work without prior installation. 0260 # That fact that this conflicts with the above isn't really an issue, as we can't run things while cross-compiling 0261 # for Android anyway. 0262 if (ANDROID) 0263 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 0264 endif() 0265 0266 if (APPLE) 0267 # Disable detection of X11 and related package on OS X because when using 0268 # brew or macports, X11 can be installed and thus is detected. 0269 option(APPLE_FORCE_X11 "Force enable X11 related detection on OS X" OFF) 0270 option(APPLE_SUPPRESS_X11_WARNING "Suppress X11 and related technologies search disabling warning on OS X" OFF) 0271 0272 if(NOT APPLE_FORCE_X11) 0273 if (NOT APPLE_SUPPRESS_X11_WARNING) 0274 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.") 0275 endif() 0276 set(CMAKE_DISABLE_FIND_PACKAGE_X11 true) 0277 set(CMAKE_DISABLE_FIND_PACKAGE_XCB true) 0278 set(CMAKE_DISABLE_FIND_PACKAGE_Qt5X11Extras true) 0279 endif() 0280 endif() 0281 0282 option(KDE_SKIP_UNINSTALL_TARGET "Prevent an \"uninstall\" target from being generated." OFF) 0283 if(NOT KDE_SKIP_UNINSTALL_TARGET) 0284 include("${ECM_MODULE_DIR}/ECMUninstallTarget.cmake") 0285 endif() 0286 0287 endif() 0288 0289 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 0290 option(ENABLE_CLAZY "Enable Clazy warnings" OFF) 0291 0292 if(ENABLE_CLAZY) 0293 find_library(CLAZY_v1_5_FOUND ClazyPlugin${CMAKE_SHARED_LIBRARY_SUFFIX}) 0294 if(CLAZY_v1_5_FOUND) # clazy >= 1.5 0295 set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClazyPlugin${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clazy") 0296 else() # clazy < 1.5 0297 set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} -Xclang -load -Xclang ClangLazy${CMAKE_SHARED_LIBRARY_SUFFIX} -Xclang -add-plugin -Xclang clang-lazy") 0298 endif() 0299 endif() 0300 endif() 0301 0302 ################################################################### 0303 # Download translations 0304 0305 function(_repository_name reponame dir) 0306 execute_process(COMMAND git rev-parse --symbolic-full-name @{u} 0307 OUTPUT_VARIABLE upstream_ref 0308 RESULT_VARIABLE exitCode 0309 WORKING_DIRECTORY "${dir}") 0310 if(exitCode EQUAL 0) 0311 string(REGEX REPLACE "refs/remotes/([^/]+)/.*" "\\1" gitorigin "${upstream_ref}") 0312 message(DEBUG "Git upstream inferred as ${gitorigin}, upstream ref was ${upstream_ref}") 0313 else() 0314 set(gitorigin "origin") 0315 message(DEBUG "Assuming origin as the git remote as we are in detached mode") 0316 endif() 0317 0318 execute_process(COMMAND git remote get-url --all "${gitorigin}" 0319 OUTPUT_VARIABLE giturl 0320 RESULT_VARIABLE exitCode 0321 WORKING_DIRECTORY "${dir}") 0322 0323 if(exitCode EQUAL 0) 0324 message(DEBUG "Git URL inferred as ${giturl}") 0325 string(REGEX MATCHALL ".+kde\\.org[:\\/]([-A-Za-z0-9\\/]+)(.git)?\\s*" "" ${giturl}) 0326 set(${reponame} ${CMAKE_MATCH_1}) 0327 message(DEBUG "Repository inferred as ${${reponame}}") 0328 endif() 0329 0330 if(NOT ${reponame}) 0331 set(${reponame} ${CMAKE_PROJECT_NAME}) 0332 endif() 0333 set(${reponame} ${${reponame}} PARENT_SCOPE) 0334 endfunction() 0335 0336 if(NOT EXISTS ${CMAKE_SOURCE_DIR}/po AND NOT TARGET fetch-translations) 0337 option(KDE_L10N_AUTO_TRANSLATIONS "Automatically 'make fetch-translations`" OFF) 0338 option(KDE_L10N_SYNC_TRANSLATIONS "Fetch translations when KDECMakeSettings.cmake is processed." OFF) 0339 set(KDE_L10N_BRANCH "trunk" CACHE STRING "Branch from l10n.kde.org to fetch from: trunk | stable | lts | trunk_kde4 | stable_kde4") 0340 0341 if(KDE_L10N_AUTO_TRANSLATIONS AND NOT KDE_L10N_SYNC_TRANSLATIONS) 0342 set(_EXTRA_ARGS "ALL") 0343 else() 0344 set(_EXTRA_ARGS) 0345 endif() 0346 0347 set(_reponame "") 0348 _repository_name(_reponame "${CMAKE_SOURCE_DIR}") 0349 0350 set(releaseme_clone_commands 0351 COMMAND git clone --depth 1 https://invent.kde.org/sdk/releaseme.git 0352 ) 0353 add_custom_command( 0354 OUTPUT "${CMAKE_BINARY_DIR}/releaseme" 0355 ${releaseme_clone_commands} 0356 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" 0357 COMMENT "Fetching releaseme scripts to download translations..." 0358 ) 0359 0360 set(_l10n_po_dir "${CMAKE_BINARY_DIR}/po") 0361 set(_l10n_poqm_dir "${CMAKE_BINARY_DIR}/poqm") 0362 0363 set(extra BYPRODUCTS ${_l10n_po_dir} ${_l10n_poqm_dir}) 0364 0365 set(fetch_commands 0366 COMMAND ruby "${CMAKE_BINARY_DIR}/releaseme/fetchpo.rb" 0367 --origin ${KDE_L10N_BRANCH} 0368 --project "${_reponame}" 0369 --output-dir "${_l10n_po_dir}" 0370 --output-poqm-dir "${_l10n_poqm_dir}" 0371 "${CMAKE_CURRENT_SOURCE_DIR}" 0372 ) 0373 0374 add_custom_target(fetch-translations ${_EXTRA_ARGS} 0375 COMMENT "Downloading translations for ${_reponame} branch ${KDE_L10N_BRANCH}..." 0376 COMMAND git -C "${CMAKE_BINARY_DIR}/releaseme" pull 0377 COMMAND cmake -E remove_directory ${_l10n_po_dir} 0378 COMMAND cmake -E remove_directory ${_l10n_poqm_dir} 0379 ${fetch_commands} 0380 ${extra} 0381 DEPENDS "${CMAKE_BINARY_DIR}/releaseme" 0382 ) 0383 0384 if (KDE_L10N_SYNC_TRANSLATIONS AND (NOT EXISTS ${_l10n_po_dir} OR NOT EXISTS ${_l10n_poqm_dir})) 0385 execute_process(${releaseme_clone_commands}) 0386 execute_process(${fetch_commands}) 0387 endif() 0388 endif()