OSDN Git Service

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