OSDN Git Service

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