OSDN Git Service

CMake: simplify C and C++ flags
[alterlinux/alterlinux-calamares.git] / CMakeLists.txt
1 # === This file is part of Calamares - <https://calamares.io> ===
2 #
3 #   SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
4 #   SPDX-License-Identifier: BSD-2-Clause
5 #
6 ###
7 #
8 #   Calamares is Free Software: see the License-Identifier above.
9 #
10 #   Individual files may have different licenses (like the CMake
11 #   infrastructure, which is BSD-2-Clause licensed). Check the SPDX
12 #   identifiers in each file.
13 #
14 ###
15 #
16 # Generally, this CMakeLists.txt will find all the dependencies for Calamares
17 # and complain appropriately. See below (later in this file) for CMake-level
18 # options. There are some "secret" options as well:
19 #
20 #   SKIP_MODULES    : a space or semicolon-separated list of directory names
21 #                     under src/modules that should not be built.
22 #   USE_<foo>       : fills in SKIP_MODULES for modules called <foo>-<something>
23 #   WITH_<foo>      : try to enable <foo> (these usually default to ON). For
24 #                     a list of WITH_<foo> grep CMakeCache.txt after running
25 #                     CMake once. These affect the ABI offered by Calamares.
26 #                       - PYTHON (enable Python Job modules)
27 #                       - QML (enable QML UI View modules)
28 #                       - PYTHONQT # TODO:3.3: remove
29 #   BUILD_<foo>     : choose additional things to build
30 #                       - TESTING (standard CMake option)
31 #                       - SCHEMA_TESTING (requires Python, see ci/configvalidator.py)
32 #   DEBUG_<foo>     : special developer flags for debugging
33 #
34 # Example usage:
35 #
36 #   cmake . -DSKIP_MODULES="partition luksbootkeycfg"
37 #
38 # One special target is "show-version", which can be built
39 # to obtain the version number from here.
40
41 # TODO:3.3: Require CMake 3.12
42 cmake_minimum_required( VERSION 3.3 FATAL_ERROR )
43 project( CALAMARES
44     VERSION 3.2.33
45     LANGUAGES C CXX )
46
47 set( CALAMARES_VERSION_RC 1 )  # Set to 0 during release cycle, 1 during development
48
49 ### OPTIONS
50 #
51 option( INSTALL_CONFIG "Install configuration files" OFF )
52 option( INSTALL_POLKIT "Install Polkit configuration" ON )
53 option( INSTALL_COMPLETION "Install shell completions" OFF )
54 # Options for the calamares executable
55 option( WITH_KF5Crash "Enable crash reporting with KCrash." ON )  # TODO:3.3: WITH->BUILD (this isn't an ABI thing)
56 option( WITH_KF5DBus "Use DBus service for unique-application." OFF )  # TODO:3.3: WITH->BUILD
57 # When adding WITH_* that affects the ABI offered by libcalamares,
58 # also update libcalamares/CalamaresConfig.h.in
59 option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON )
60 option( WITH_PYTHONQT "Enable Python view modules API (deprecated, requires PythonQt)." OFF )  # TODO:3.3: remove
61 option( WITH_QML "Enable QML UI options." ON )
62 #
63 # Additional parts to build
64 option( BUILD_SCHEMA_TESTING "Enable schema-validation-tests" ON )
65
66
67 # Possible debugging flags are:
68 #  - DEBUG_TIMEZONES draws latitude and longitude lines on the timezone
69 #    widget and enables chatty debug logging, for dealing with the timezone
70 #    location database.
71 #  - DEBUG_FILESYSTEMS does extra logging and checking when looking at
72 #    partition configuration. Lists known KPMCore FS types.
73 #  - DEBUG_PARTITION_UNSAFE (see partition/CMakeLists.txt)
74 #  - DEBUG_PARTITION_LAME (see partition/CMakeLists.txt)
75
76
77 ### USE_*
78 #
79 # By convention, when there are multiple modules that implement similar
80 # functionality, and it only makes sense to have **at most one** of them
81 # enabled at any time, those modules are named <foo>-<implementation>.
82 # For example, services-systemd and services-openrc.
83 #
84 # Setting up SKIP_MODULES to ignore "the ones you don't want" can be
85 # annoying and error-prone (e.g. if a new module shows up). The USE_*
86 # modules provide a way to do automatic selection. To pick exactly
87 # one of the implementations from group <foo>, set USE_<foo> to the
88 # name of the implementation. If USE_<foo> is unset, or empty, then
89 # all the implementations are enabled (this just means they are
90 # **available** to `settings.conf`, not that they are used).
91 #
92 # To explicitly disable a set of modules, set USE_<foo>=none
93 # (e.g. the literal string none), which won't match any of the
94 # modules but is handled specially. This is the default for
95 # USE_os, which are modules for specialty non-Linux distributions.
96 #
97 # The following USE_* functionalities are available:
98 #  - *services* picks one of the two service-configuration modules,
99 #    for either systemd or openrc. This defaults to empty so that
100 #    **both** modules are available.
101 #  - *os* picks an OS-specific module for things-that-are-not-Linux.
102 #    It is generally discouraged to use this unless your distro is
103 #    completely unable to use standard Linux tools for configuration.
104 #    This defaults to *none* so that nothing gets picked up and nothing
105 #    is packaged -- you must explicitly set it to empty to get all of
106 #    the modules, but that hardly makes sense. Note, too that there
107 #    are currently no os-* modules shipped with Calamares.
108 set( USE_services "" CACHE STRING "Select the services module to use" )
109 set( USE_os "none" CACHE STRING "Select the OS-specific module to include" )
110
111 ### Calamares application info
112 #
113 set( CALAMARES_ORGANIZATION_NAME "Calamares" )
114 set( CALAMARES_ORGANIZATION_DOMAIN "github.com/calamares" )
115 set( CALAMARES_APPLICATION_NAME  "Calamares" )
116 set( CALAMARES_DESCRIPTION_SUMMARY
117     "The distribution-independent installer framework" )
118
119 ### Transifex (languages) info
120 #
121 # complete = 100% translated,
122 # good = nearly complete (use own judgement, right now >= 75%)
123 # ok = incomplete (more than 25% untranslated, at least 5% translated),
124 # incomplete = <5% translated, placeholder in tx; these are not included.
125 #
126 # Language en (source language) is added later. It isn't listed in
127 # Transifex either. Get the list of languages and their status
128 # from https://transifex.com/calamares/calamares/ , or (preferably)
129 # use ci/txstats.py to automatically check.
130 #
131 # When adding a new language, take care that it is properly loaded
132 # by the translation framework. Languages with alternate scripts
133 # (sr@latin in particular) may need special handling in CalamaresUtils.cpp.
134 #
135 # TODO: drop the es_ES translation from Transifex
136 #
137 # NOTE: move eo (Esperanto) to _ok once Qt can actually create a
138 #       locale for it. (Qt 5.12.2 can, see Translation Status section).
139 # NOTE: move ie (Interlingue) to _ok once Qt supports it.
140 # NOTE: update these lines by running `txstats.py`, or for full automation
141 #       `txstats.py -e`. See also
142 #
143 # Total 70 languages
144 set( _tx_complete ca cs_CZ he hr sq tr_TR uk )
145 set( _tx_good as ast az az_AZ be da de es fa fi_FI fr hi hu it_IT
146     ja ko lt ml nl pt_BR pt_PT ru sk sv tg zh_CN zh_TW )
147 set( _tx_ok ar bg bn el en_GB es_MX es_PR et eu fur gl id is mr nb
148     pl ro sl sr sr@latin th )
149 set( _tx_incomplete ca@valencia eo fr_CH gu ie kk kn lo lv mk ne_NP
150     te ur uz )
151
152 ### Required versions
153 #
154 # See DEPENDENCIES section below.
155 set( QT_VERSION 5.9.0 )
156 set( YAMLCPP_VERSION 0.5.1 )
157 set( ECM_VERSION 5.18 )
158 set( PYTHONLIBS_VERSION 3.3 )
159 set( BOOSTPYTHON_VERSION 1.55.0 )
160
161
162 ### CMAKE SETUP
163 #
164 set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules" )
165
166 # Enable IN_LIST
167 if( POLICY CMP0057 )
168     cmake_policy( SET CMP0057 NEW )
169 endif()
170 # Let ``AUTOMOC`` and ``AUTOUIC`` process ``GENERATED`` files.
171 if( POLICY CMP0071 )
172     cmake_policy( SET CMP0071 NEW )
173 endif()
174 # Recognize more macros to trigger automoc
175 if(NOT CMAKE_VERSION VERSION_LESS "3.10.0")
176     list(APPEND CMAKE_AUTOMOC_MACRO_NAMES
177         "K_PLUGIN_FACTORY_WITH_JSON"
178         "K_EXPORT_PLASMA_DATAENGINE_WITH_JSON"
179         "K_EXPORT_PLASMA_RUNNER"
180     )
181 endif()
182
183 # CMake Modules
184 include( CMakePackageConfigHelpers )
185 include( CTest )
186 include( FeatureSummary )
187
188 # Calamares Modules
189 include( CMakeColors )
190
191 ### C++ SETUP
192 #
193 set( CMAKE_CXX_STANDARD 17 )
194 set( CMAKE_CXX_STANDARD_REQUIRED ON )
195 set( CMAKE_CXX_FLAGS                "${CMAKE_CXX_FLAGS} -Wall -Werror=return-type -Wl,--no-undefined" )
196 set( CMAKE_CXX_FLAGS_DEBUG          "-g ${CMAKE_CXX_FLAGS_DEBUG}" )
197 set( CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG" )
198 set( CMAKE_CXX_FLAGS_RELEASE        "-O3 -DNDEBUG" )
199 set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
200
201 set( CMAKE_C_STANDARD 99 )
202 set( CMAKE_C_STANDARD_REQUIRED ON )
203 set( CMAKE_C_FLAGS                  "${CMAKE_C_FLAGS} -Wall" )
204 set( CMAKE_C_FLAGS_DEBUG            "-g" )
205 set( CMAKE_C_FLAGS_MINSIZEREL       "-Os -DNDEBUG" )
206 set( CMAKE_C_FLAGS_RELEASE          "-O4 -DNDEBUG" )
207 set( CMAKE_C_FLAGS_RELWITHDEBINFO   "-O2 -g" )
208
209 set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
210
211 if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
212     message( STATUS "Found Clang ${CMAKE_CXX_COMPILER_VERSION}, setting up Clang-specific compiler flags." )
213
214     # Clang warnings: doing *everything* is counter-productive, since it warns
215     # about things which we can't fix (e.g. C++98 incompatibilities, but
216     # Calamares is C++17).
217     foreach( CLANG_WARNINGS
218         -Weverything
219         -Wno-c++98-compat
220         -Wno-c++98-compat-pedantic
221         -Wno-padded
222         -Wno-undefined-reinterpret-cast
223         -Wno-global-constructors
224         -Wno-exit-time-destructors
225         -Wno-missing-prototypes
226         -Wno-documentation-unknown-command
227         -Wno-unknown-warning-option
228     )
229         string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" )
230     endforeach()
231     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='//' -DFALLTHRU='[[clang::fallthrough]]'")
232
233     # Third-party code where we don't care so much about compiler warnings
234     # (because it's uncomfortable to patch) get different flags; use
235     #       mark_thirdparty_code( <file> [<file>...] )
236     # to switch off warnings for those sources.
237     set( SUPPRESS_3RDPARTY_WARNINGS "-Wno-everything" )
238
239     set( CMAKE_TOOLCHAIN_PREFIX "llvm-" )
240
241     # The path prefix is only relevant for CMake 3.16 and later, fixes #1286
242     set( CMAKE_AUTOMOC_PATH_PREFIX OFF )
243     set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" )
244     set( CALAMARES_AUTOUIC_OPTIONS --include utils/moc-warnings.h )
245 else()
246     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual" )
247
248     set( SUPPRESS_3RDPARTY_WARNINGS "" )
249
250     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='__builtin_unreachable();' -DFALLTHRU='/* */'" )
251 endif()
252
253 # Use mark_thirdparty_code() to reduce warnings from the compiler
254 # on code that we're not going to fix. Call this with a list of files.
255 macro(mark_thirdparty_code)
256     set_source_files_properties( ${ARGV}
257         PROPERTIES
258             COMPILE_FLAGS "${SUPPRESS_3RDPARTY_WARNINGS}"
259             COMPILE_DEFINITIONS "THIRDPARTY"
260     )
261 endmacro()
262
263 if( CMAKE_COMPILER_IS_GNUCXX )
264     if( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR
265         CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9 )
266         message( STATUS "Found GNU g++ ${CMAKE_CXX_COMPILER_VERSION}, enabling colorized error messages." )
267         set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )
268     endif()
269 endif()
270
271
272 ### DEPENDENCIES
273 #
274 find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Concurrent Core Gui LinguistTools Network Svg Widgets )
275 if( WITH_QML )
276     find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Quick QuickWidgets )
277 endif()
278 # Optional Qt parts
279 find_package( Qt5DBus CONFIG )
280
281 find_package( YAMLCPP ${YAMLCPP_VERSION} REQUIRED )
282 if( INSTALL_POLKIT )
283     find_package( PolkitQt5-1 REQUIRED )
284 else()
285     # Find it anyway, for dependencies-reporting
286     find_package( PolkitQt5-1 )
287 endif()
288 set_package_properties(
289     PolkitQt5-1 PROPERTIES
290     DESCRIPTION "Qt5 support for Polkit"
291     URL "https://cgit.kde.org/polkit-qt-1.git"
292     PURPOSE "PolkitQt5-1 helps with installing Polkit configuration"
293 )
294
295 # Find ECM once, and add it to the module search path; Calamares
296 # modules that need ECM can do
297 #   find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE),
298 # no need to mess with the module path after.
299 find_package(ECM ${ECM_VERSION} NO_MODULE)
300 if( ECM_FOUND )
301     set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
302     if ( BUILD_TESTING )
303         # ECM implies that we can build the tests, too
304         find_package( Qt5 COMPONENTS Test REQUIRED )
305         include( ECMAddTests )
306     endif()
307     include(KDEInstallDirs)
308 endif()
309
310 find_package( KF5 QUIET COMPONENTS CoreAddons Crash DBusAddons )
311 set_package_properties(
312     KF5::CoreAddons PROPERTIES
313     TYPE REQUIRED
314     DESCRIPTION "Classes built on QtCore for About Data"
315     URL "https://api.kde.org/frameworks/kcoreaddons/"
316     PURPOSE "About Calamares"
317 )
318 if( NOT KF5Crash_FOUND )
319     if( WITH_KF5Crash )
320         message(WARNING "WITH_KF5Crash is set, but KF5::Crash is not available.")
321     endif()
322     set( WITH_KF5Crash OFF )
323 endif()
324 if( NOT KF5DBusAddons_FOUND )
325     if( WITH_KF5DBus )
326         message(WARNING "WITH_KF5DBus is set, but KF5::DBusAddons is not available.")
327     endif()
328     set( WITH_KF5DBus OFF )
329 endif()
330
331 # TODO:3.3: Use FindPython3 instead
332 find_package( PythonInterp ${PYTHONLIBS_VERSION} )
333 set_package_properties(
334     PythonInterp PROPERTIES
335     DESCRIPTION "Python 3 interpreter."
336     URL "https://python.org"
337     PURPOSE "Python 3 interpreter for certain tests."
338 )
339
340 set( _schema_explanation "" )
341 if ( PYTHONINTERP_FOUND )
342     if ( BUILD_SCHEMA_TESTING )
343         # The configuration validator script has some dependencies,
344         # and if they are not installed, don't run. If errors out
345         # with exit(1) on missing dependencies.
346         if ( CALAMARES_CONFIGVALIDATOR_CHECKED )
347             set( _validator_deps ${CALAMARES_CONFIGVALIDATOR_RESULT} )
348         else()
349             exec_program( ${PYTHON_EXECUTABLE} ARGS "${CMAKE_SOURCE_DIR}/ci/configvalidator.py" -x RETURN_VALUE _validator_deps )
350             set( CALAMARES_CONFIGVALIDATOR_CHECKED TRUE CACHE INTERNAL "Dependencies for configvalidator checked" )
351             set( CALAMARES_CONFIGVALIDATOR_RESULT ${_validator_deps} CACHE INTERNAL "Result of configvalidator dependency check" )
352         endif()
353         # It should never succeed, but only returns 1 when the imports fail
354         if ( _validator_deps EQUAL 1 )
355             set( _schema_explanation " Missing dependencies for configvalidator.py." )
356             set( BUILD_SCHEMA_TESTING OFF )
357         endif()
358     endif()
359 else()
360     # Can't run schema tests without Python3.
361     set( _schema_explanation " Missing Python3." )
362     set( BUILD_SCHEMA_TESTING OFF )
363 endif()
364 add_feature_info( yaml-schema BUILD_SCHEMA_TESTING "Validate YAML (config files) with schema.${_schema_explanation}" )
365
366 find_package( PythonLibs ${PYTHONLIBS_VERSION} )
367 set_package_properties(
368     PythonLibs PROPERTIES
369     DESCRIPTION "C interface libraries for the Python 3 interpreter."
370     URL "https://python.org"
371     PURPOSE "Python 3 is used for Python job modules."
372 )
373
374 if ( PYTHONLIBS_FOUND )
375     # TODO:3.3: Require Boost + CMake; sort out Boost::Python
376     # Since Boost provides CMake config files (starting with Boost 1.70.
377     # or so) the mess that is the Calamares find code picks the wrong
378     # bits. Suppress those CMake config files, as suggested by @jmrcpn
379     set(Boost_NO_BOOST_CMAKE ON)
380     include( BoostPython3 )
381     find_boost_python3( ${BOOSTPYTHON_VERSION} ${PYTHONLIBS_VERSION_STRING} CALAMARES_BOOST_PYTHON3_FOUND )
382     set_package_properties(
383         Boost PROPERTIES
384         PURPOSE "Boost.Python is used for Python job modules."
385     )
386     # TODO:3.3: Remove PythonQt support
387     find_package( PythonQt )
388     set_package_properties( PythonQt PROPERTIES
389         DESCRIPTION "A Python embedding solution for Qt applications."
390         URL "http://pythonqt.sourceforge.net"
391         PURPOSE "PythonQt is used for Python view modules."
392     )
393 endif()
394
395 if( NOT PYTHONLIBS_FOUND OR NOT CALAMARES_BOOST_PYTHON3_FOUND )
396     message(STATUS "Disabling Boost::Python modules")
397     set( WITH_PYTHON OFF )
398 endif()
399 if( NOT PYTHONLIBS_FOUND OR NOT PYTHONQT_FOUND )
400     message(STATUS "Disabling PythonQt modules")
401     set( WITH_PYTHONQT OFF )
402 endif()
403
404 # Now we know the state of the ABI-options, copy them into "Calamares_"
405 # prefixed variables, to match how the variables would-be-named
406 # when building out-of-tree.
407 set(Calamares_WITH_PYTHON ${WITH_PYTHON})
408 set(Calamares_WITH_PYTHONQT ${WITH_PYTHONQT})
409 set(Calamares_WITH_QML ${WITH_QML})
410
411 ### Transifex Translation status
412 #
413 # Construct language lists for use.
414 #
415 if( Qt5_VERSION VERSION_GREATER 5.12.1 )
416     # At least Qt 5.12.2 seems to support Esperanto in QLocale
417     if( "eo" IN_LIST _tx_incomplete )
418         message(STATUS "Esperanto support since Qt 5.12.2, enabling Esperanto locale")
419         list( REMOVE_ITEM _tx_incomplete "eo" )
420         list( APPEND _tx_ok "eo" )
421     endif()
422 endif()
423
424 set( curr_tx ${_tx_complete} ${_tx_good} ${_tx_ok} ${_tx_incomplete} )
425 set( tx_errors OFF )
426 if ( curr_tx )
427     # New in list
428     foreach( l ${curr_tx} )
429         set( p_l "lang/calamares_${l}.ts" )
430         if( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${p_l} )
431             message(WARNING "Language ${l} has no .ts file yet.")
432             set( tx_errors ON )
433         endif()
434     endforeach()
435
436     unset( p_l )
437     unset( l )
438 endif()
439 unset( curr_tx )
440 if( tx_errors )
441     message( FATAL_ERROR "Translation warnings, see above." )
442 endif()
443
444 set( CALAMARES_TRANSLATION_LANGUAGES en ${_tx_complete} ${_tx_good} ${_tx_ok} )
445 list( SORT CALAMARES_TRANSLATION_LANGUAGES )
446
447 add_subdirectory( lang )  # i18n tools
448
449 ### Example Distro
450 #
451 # For testing purposes Calamares includes a very, very, limited sample
452 # distro called "Generic". The root filesystem of "Generic" lives in
453 # data/example-root and can be squashed up as part of the build, so
454 # that a pure-upstream run of ./calamares -d from the build directory
455 # (with all the default settings and configurations) can actually
456 # do an complete example run.
457 #
458 # Some binaries from the build host (e.g. /bin and /lib) are also
459 # squashed into the example filesystem.
460 #
461 # To build the example distro (for use by the default, example,
462 # unsquashfs module), build the target 'example-distro', eg.:
463 #
464 #   make example-distro
465 #
466 find_program( mksquashfs_PROGRAM mksquashfs )
467 if( mksquashfs_PROGRAM )
468     set( mksquashfs_FOUND ON )
469     set( src_fs ${CMAKE_SOURCE_DIR}/data/example-root/ )
470     set( dst_fs ${CMAKE_BINARY_DIR}/example.sqfs )
471     if( EXISTS ${src_fs} )
472         # based on the build host. If /lib64 exists, assume it is needed.
473         # Collect directories needed for a minimal binary distro,
474         # Note that the last path component is added to the root, so
475         # if you add /usr/sbin here, it will be put into /sbin_1.
476         # Add such paths to /etc/profile under ${src_fs}.
477         set( candidate_fs /sbin /bin /lib /lib64 )
478         set( host_fs "" )
479         foreach( c_fs ${candidate_fs} )
480             if( EXISTS ${c_fs} )
481                 list( APPEND host_fs ${c_fs} )
482             endif()
483         endforeach()
484         add_custom_command(
485             OUTPUT ${dst_fs}
486             COMMAND ${mksquashfs_PROGRAM} ${src_fs} ${dst_fs} -all-root
487             COMMAND ${mksquashfs_PROGRAM} ${host_fs} ${dst_fs} -all-root
488         )
489         add_custom_target(example-distro DEPENDS ${dst_fs})
490     endif()
491 else()
492     set( mksquashfs_FOUND OFF )
493 endif()
494 # Doesn't list mksquashfs as an optional dep, though, because it
495 # hasn't been sent through the find_package() scheme.
496 #
497 # "http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html"
498 add_feature_info( ExampleDistro ${mksquashfs_FOUND} "Create example-distro target.")
499
500
501 ### CALAMARES PROPER
502 #
503 set( CALAMARES_VERSION ${CALAMARES_VERSION_MAJOR}.${CALAMARES_VERSION_MINOR}.${CALAMARES_VERSION_PATCH} )
504 # In rare cases we have hotfix-releases with a tweak
505 if( CALAMARES_VERSION_TWEAK )
506     set( CALAMARES_VERSION "${CALAMARES_VERSION}.${CALAMARES_VERSION_TWEAK}" )
507 endif()
508 set( CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}" )
509 if( CALAMARES_VERSION_RC )
510     set( CALAMARES_VERSION ${CALAMARES_VERSION}rc${CALAMARES_VERSION_RC} )
511 endif()
512
513 # Additional info for non-release builds. The "extended" version information
514 # with date and git information (commit, dirty status) is used only
515 # by CalamaresVersionX.h, which is included by consumers that need a full
516 # version number with all that information; normal consumers can include
517 # CalamaresVersion.h with more stable numbers.
518 if( NOT BUILD_RELEASE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" )
519     include( CMakeDateStamp )
520     set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" )
521     if( CALAMARES_VERSION_DATE GREATER 0 )
522         set( CALAMARES_VERSION ${CALAMARES_VERSION}.${CALAMARES_VERSION_DATE} )
523     endif()
524
525     include( CMakeVersionSource )
526     if( CMAKE_VERSION_SOURCE )
527         set( CALAMARES_VERSION ${CALAMARES_VERSION}-${CMAKE_VERSION_SOURCE} )
528     endif()
529 endif()
530
531 # Special target for not-RC (e.g. might-be-release) builds.
532 # This is used by the release script to get the version.
533 if ( CALAMARES_VERSION_RC EQUAL 0 )
534     add_custom_target(show-version
535         ${CMAKE_COMMAND} -E echo CALAMARES_VERSION=${CALAMARES_VERSION_SHORT}
536         USES_TERMINAL
537     )
538 endif()
539
540 # enforce using constBegin, constEnd for const-iterators
541 add_definitions(
542     -DQT_STRICT_ITERATORS
543     -DQT_SHARED
544     -DQT_SHAREDPOINTER_TRACK_POINTERS
545 )
546
547 # set paths
548 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
549 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
550 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
551
552 # Better default installation paths: GNUInstallDirs defines
553 # CMAKE_INSTALL_FULL_SYSCONFDIR to be CMAKE_INSTALL_PREFIX/etc by default
554 # but we really want /etc
555 if( NOT DEFINED CMAKE_INSTALL_SYSCONFDIR )
556     set( CMAKE_INSTALL_SYSCONFDIR "/etc" )
557 endif()
558
559 # make predefined install dirs available everywhere
560 include( GNUInstallDirs )
561
562 # This is used by CalamaresAddLibrary; once Calamares is installed,
563 # the CalamaresConfig.cmake module sets this variable to the IMPORTED
564 # libraries for Calamares.
565 set( Calamares_LIBRARIES calamares )
566
567 add_subdirectory( src )
568
569 add_feature_info(Python ${WITH_PYTHON} "Python job modules")
570 add_feature_info(PythonQt ${WITH_PYTHONQT} "Python view modules")
571 add_feature_info(Config ${INSTALL_CONFIG} "Install Calamares configuration")
572 add_feature_info(KCrash ${WITH_KF5Crash} "Crash dumps via KCrash")
573 add_feature_info(KDBusAddons ${WITH_KF5DBus} "Unique-application via DBus")
574
575 ### CMake infrastructure installation
576 #
577 #
578 set( CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Calamares" CACHE PATH  "Installation directory for CMake files" )
579 set( CMAKE_INSTALL_FULL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" )
580
581 export( PACKAGE Calamares )
582 configure_package_config_file(
583     "CalamaresConfig.cmake.in"
584     "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake"
585     INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
586     PATH_VARS
587         CMAKE_INSTALL_INCLUDEDIR
588         CMAKE_INSTALL_LIBDIR
589         CMAKE_INSTALL_DATADIR
590 )
591 write_basic_package_version_file(
592     ${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake
593     VERSION ${PROJECT_VERSION}
594     COMPATIBILITY SameMajorVersion
595 )
596 install(
597     EXPORT Calamares
598     DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
599     FILE "CalamaresTargets.cmake"
600     NAMESPACE Calamares::
601 )
602
603 # Install the cmake files
604 install(
605     FILES
606         "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake"
607         "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake"
608         "CMakeModules/CalamaresAddBrandingSubdirectory.cmake"
609         "CMakeModules/CalamaresAddLibrary.cmake"
610         "CMakeModules/CalamaresAddModuleSubdirectory.cmake"
611         "CMakeModules/CalamaresAddPlugin.cmake"
612         "CMakeModules/CalamaresAddTest.cmake"
613         "CMakeModules/CalamaresAddTranslations.cmake"
614         "CMakeModules/CalamaresAutomoc.cmake"
615         "CMakeModules/CMakeColors.cmake"
616         "CMakeModules/FindYAMLCPP.cmake"
617     DESTINATION
618         "${CMAKE_INSTALL_CMAKEDIR}"
619 )
620
621 ### Miscellaneous installs
622 #
623 #
624 if( INSTALL_CONFIG )
625     install(
626         FILES settings.conf
627         DESTINATION share/calamares
628     )
629 endif()
630
631 if( INSTALL_POLKIT )
632     install(
633         FILES com.github.calamares.calamares.policy
634         DESTINATION "${POLKITQT-1_POLICY_FILES_INSTALL_DIR}"
635     )
636 endif()
637
638 if ( INSTALL_COMPLETION )
639     if( NOT CMAKE_INSTALL_BASHCOMPLETIONDIR )
640         set( CMAKE_INSTALL_BASHCOMPLETIONDIR "${CMAKE_INSTALL_DATADIR}/bash-completion/completions" )
641     endif()
642
643     install( FILES ${CMAKE_SOURCE_DIR}/data/completion/bash/calamares DESTINATION "${CMAKE_INSTALL_BASHCOMPLETIONDIR}" )
644 endif()
645
646 install(
647   FILES calamares.desktop
648   DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
649 )
650
651 install(
652     FILES man/calamares.8
653     DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/
654 )
655
656 # uninstall target
657 configure_file(
658     "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
659     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
660     IMMEDIATE @ONLY
661 )
662
663 add_custom_target( uninstall
664     COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
665 )
666
667 ### CMAKE SUMMARY REPORT
668 #
669 get_directory_property( SKIPPED_MODULES
670     DIRECTORY src/modules
671     DEFINITION LIST_SKIPPED_MODULES
672 )
673 calamares_explain_skipped_modules( ${SKIPPED_MODULES} )
674
675 feature_summary(
676     WHAT DISABLED_FEATURES
677     DESCRIPTION "The following features have been disabled:"
678     QUIET_ON_EMPTY
679 )
680 feature_summary(
681     WHAT OPTIONAL_PACKAGES_NOT_FOUND
682     DESCRIPTION "The following OPTIONAL packages were not found:"
683     QUIET_ON_EMPTY
684 )
685 feature_summary(
686     WHAT REQUIRED_PACKAGES_NOT_FOUND
687     FATAL_ON_MISSING_REQUIRED_PACKAGES
688     DESCRIPTION "The following REQUIRED packages were not found:"
689     QUIET_ON_EMPTY
690 )