source: calamares/trunk/fuentes/CMakeLists.txt @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 17.2 KB
Line 
1# === This file is part of Calamares - <https://github.com/calamares> ===
2#
3#   Calamares is free software: you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation, either version 3 of the License, or
6#   (at your option) any later version.
7#
8#   Calamares is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11#   GNU General Public License for more details.
12#
13#   You should have received a copy of the GNU General Public License
14#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
15#
16#   SPDX-License-Identifier: GPL-3.0+
17#   License-Filename: LICENSE
18#
19###
20#
21# Generally, this CMakeLists.txt will find all the dependencies for Calamares
22# and complain appropriately. See below (later in this file) for CMake-level
23# options. There are some "secret" options as well:
24#
25#   SKIP_MODULES    : a space or semicolon-separated list of directory names
26#                     under src/modules that should not be built.
27#
28# Example usage:
29#
30#   cmake . -DSKIP_MODULES="partition luksbootkeycfg"
31
32project( calamares C CXX )
33
34cmake_minimum_required( VERSION 3.2 )
35
36
37### OPTIONS
38#
39option( INSTALL_CONFIG "Install configuration files" ON )
40option( INSTALL_POLKIT "Install Polkit configuration" ON )
41option( BUILD_TESTING "Build the testing tree." ON )
42option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON )
43option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." ON )
44option( WITH_KF5Crash "Enable crash reporting with KCrash." ON )
45
46
47### Calamares application info
48#
49set( CALAMARES_ORGANIZATION_NAME "Calamares" )
50set( CALAMARES_ORGANIZATION_DOMAIN "github.com/calamares" )
51set( CALAMARES_APPLICATION_NAME  "Calamares" )
52set( CALAMARES_DESCRIPTION_SUMMARY
53    "The distribution-independent installer framework" )
54
55set( CALAMARES_VERSION_MAJOR 3 )
56set( CALAMARES_VERSION_MINOR 2 )
57set( CALAMARES_VERSION_PATCH 0 )
58set( CALAMARES_VERSION_RC 0 )
59
60
61### Transifex (languages) info
62#
63# complete = 100% translated,
64# good = nearly complete (use own judgement, right now >= 75%)
65# ok = incomplete (more than 25% untranslated),
66# bad = 0% translated, placeholder in tx; these are not included.
67#
68# Language en (source language) is added later. It isn't listed in
69# Transifex either. Get the list of languages and their status
70# from https://transifex.com/calamares/calamares/ .
71#
72# When adding a new language, take care that it is properly loaded
73# by the translation framework. Languages with alternate scripts
74# (sr@latin in particular) may need special handling in CalamaresUtils.cpp.
75#
76# TODO: drop the es_ES translation from Transifex
77# TODO: move eo (Esperanto) to _ok once Qt can actually create a
78#       locale for it.
79#
80# NOTE: when updating the list from Transifex, copy these four lines
81#       and prefix each variable name with "p", so that the automatic
82#       checks for new languages and misspelled ones are done (that is,
83#       copy these four lines to four backup lines, add "p", and then update
84#       the original four lines with the current translations).
85set( _tx_complete da pt_PT ro tr_TR zh_TW zh_CN pt_BR fr hr ca lt id cs_CZ )
86set( _tx_good sq es pl ja sk it_IT hu ru he de nl bg uk )
87set( _tx_ok ast is ar sv el es_MX gl en_GB th fi_FI hi eu sr nb
88            sl sr@latin mr es_PR kk kn et be )
89set( _tx_bad uz lo ur gu fr_CH fa eo ko )
90
91
92### Required versions
93#
94# See DEPENDENCIES section below.
95set( QT_VERSION 5.7.0 )
96set( YAMLCPP_VERSION 0.5.1 )
97set( ECM_VERSION 5.18 )
98set( PYTHONLIBS_VERSION 3.3 )
99set( BOOSTPYTHON_VERSION 1.54.0 )
100
101
102### CMAKE SETUP
103#
104set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules" )
105
106# CMake 3.9, 3.10 compatibility
107if( POLICY CMP0071 )
108    cmake_policy( SET CMP0071 NEW )
109endif()
110if(NOT CMAKE_VERSION VERSION_LESS "3.10.0")
111    list(APPEND CMAKE_AUTOMOC_MACRO_NAMES
112        "K_PLUGIN_FACTORY_WITH_JSON"
113        "K_EXPORT_PLASMA_DATAENGINE_WITH_JSON"
114        "K_EXPORT_PLASMA_RUNNER"
115    )
116endif()
117
118
119### C++ SETUP
120#
121set( CMAKE_CXX_STANDARD 14 )
122set( CMAKE_CXX_STANDARD_REQUIRED ON )
123set( CMAKE_C_STANDARD 99 )
124set( CMAKE_C_STANDARD_REQUIRED ON )
125
126set( CMAKE_C_FLAGS                  "${CMAKE_C_FLAGS} -Wall" )
127if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
128    message( STATUS "Found Clang ${CMAKE_CXX_COMPILER_VERSION}, setting up Clang-specific compiler flags." )
129    set( CMAKE_C_FLAGS                  "${CMAKE_C_FLAGS} -Wall" )
130    set( CMAKE_C_FLAGS_DEBUG            "-g" )
131    set( CMAKE_C_FLAGS_MINSIZEREL       "-Os -DNDEBUG" )
132    set( CMAKE_C_FLAGS_RELEASE          "-O4 -DNDEBUG" )
133    set( CMAKE_C_FLAGS_RELWITHDEBINFO   "-O2 -g" )
134
135    # Clang warnings: doing *everything* is counter-productive, since it warns
136    # about things which we can't fix (e.g. C++98 incompatibilities, but
137    # Calamares is C++14).
138    foreach( CLANG_WARNINGS
139        -Weverything
140        -Wno-c++98-compat
141        -Wno-c++98-compat-pedantic
142        -Wno-padded
143        -Wno-undefined-reinterpret-cast
144        -Wno-global-constructors
145        -Wno-exit-time-destructors
146        -Wno-missing-prototypes
147        -Wno-documentation-unknown-command
148    )
149        string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" )
150    endforeach()
151
152    # Third-party code where we don't care so much about compiler warnings
153    # (because it's uncomfortable to patch) get different flags; use
154    #       mark_thirdparty_code( <file> [<file>...] )
155    # to switch off warnings for those sources.
156    set( SUPPRESS_3RDPARTY_WARNINGS "-Wno-everything" )
157    set( SUPPRESS_BOOST_WARNINGS " -Wno-zero-as-null-pointer-constant -Wno-disabled-macro-expansion" )
158
159    set( CMAKE_CXX_FLAGS_DEBUG          "-g" )
160    set( CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG" )
161    set( CMAKE_CXX_FLAGS_RELEASE        "-O4 -DNDEBUG" )
162    set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
163
164    set( CMAKE_TOOLCHAIN_PREFIX "llvm-" )
165
166    set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
167else()
168    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" )
169    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
170
171    set( SUPPRESS_3RDPARTY_WARNINGS "" )
172    set( SUPPRESS_BOOST_WARNINGS "" )
173endif()
174
175# Use mark_thirdparty_code() to reduce warnings from the compiler
176# on code that we're not going to fix. Call this with a list of files.
177macro(mark_thirdparty_code)
178    set_source_files_properties( ${ARGV}
179        PROPERTIES
180            COMPILE_FLAGS "${SUPPRESS_3RDPARTY_WARNINGS}"
181            COMPILE_DEFINITIONS "THIRDPARTY"
182    )
183endmacro()
184
185if( CMAKE_COMPILER_IS_GNUCXX )
186    if( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR
187        CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9 )
188        message( STATUS "Found GNU g++ ${CMAKE_CXX_COMPILER_VERSION}, enabling colorized error messages." )
189        set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )
190    endif()
191endif()
192
193include( FeatureSummary )
194include( CMakeColors )
195
196
197### DEPENDENCIES
198#
199find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core Gui Widgets LinguistTools Svg Quick QuickWidgets )
200find_package( YAMLCPP ${YAMLCPP_VERSION} REQUIRED )
201if( INSTALL_POLKIT )
202    find_package( PolkitQt5-1 REQUIRED )
203else()
204    # Find it anyway, for dependencies-reporting
205    find_package( PolkitQt5-1 )
206endif()
207set_package_properties(
208    PolkitQt5-1 PROPERTIES
209    DESCRIPTION "Qt5 support for Polkit"
210    URL "https://cgit.kde.org/polkit-qt-1.git"
211    PURPOSE "PolkitQt5-1 helps with installing Polkit configuration"
212)
213
214# Find ECM once, and add it to the module search path; Calamares
215# modules that need ECM can do
216#   find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE),
217# no need to mess with the module path after.
218find_package(ECM ${ECM_VERSION} NO_MODULE)
219if( ECM_FOUND )
220    set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
221endif()
222
223find_package( KF5 COMPONENTS CoreAddons Crash )
224if( NOT KF5Crash_FOUND )
225    set( WITH_KF5Crash OFF )
226endif()
227
228if( BUILD_TESTING )
229    enable_testing()
230endif ()
231
232find_package( PythonLibs ${PYTHONLIBS_VERSION} )
233set_package_properties(
234    PythonLibs PROPERTIES
235    DESCRIPTION "C interface libraries for the Python 3 interpreter."
236    URL "http://python.org"
237    PURPOSE "Python 3 is used for Python job modules."
238)
239
240if ( PYTHONLIBS_FOUND )
241    include( BoostPython3 )
242    find_boost_python3( ${BOOSTPYTHON_VERSION} ${PYTHONLIBS_VERSION_STRING} CALAMARES_BOOST_PYTHON3_FOUND )
243    set_package_properties(
244        Boost PROPERTIES
245        PURPOSE "Boost.Python is used for Python job modules."
246    )
247
248    find_package( PythonQt )
249    set_package_properties( PythonQt PROPERTIES
250        DESCRIPTION "A Python embedding solution for Qt applications."
251        URL "http://pythonqt.sourceforge.net"
252        PURPOSE "PythonQt is used for Python view modules."
253    )
254endif()
255
256if( NOT PYTHONLIBS_FOUND OR NOT CALAMARES_BOOST_PYTHON3_FOUND )
257    message(STATUS "Disabling Boost::Python modules")
258    set( WITH_PYTHON OFF )
259endif()
260if( NOT PYTHONLIBS_FOUND OR NOT PYTHONQT_FOUND )
261    message(STATUS "Disabling PythonQt modules")
262    set( WITH_PYTHONQT OFF )
263endif()
264
265### Transifex Translation status
266#
267# Construct language lists for use. If there are p_tx* variables,
268# then run an extra cmake-time check for consistency of the old
269# (p_tx*) and new (_tx*) lists.
270#
271set( prev_tx ${p_tx_complete} ${p_tx_good} ${p_tx_ok} ${p_tx_bad} )
272set( curr_tx ${_tx_complete} ${_tx_good} ${_tx_ok} ${_tx_bad} )
273if ( prev_tx )
274    # Gone in new list
275    foreach( l ${prev_tx} )
276        list( FIND curr_tx ${l} p_l )
277        if( p_l EQUAL -1 )
278            message(WARNING "Language ${l} was present in previous translations and is now absent.")
279        endif()
280    endforeach()
281
282    # New in list
283    foreach( l ${curr_tx} )
284        list( FIND prev_tx ${l} p_l )
285        if( p_l EQUAL -1 )
286            message(WARNING "Language ${l} is new.")
287        endif()
288        set( p_l "lang/calamares_${l}.ts" )
289        if( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${p_l} )
290            message(WARNING "Language ${l} has no .ts file yet.")
291        endif()
292    endforeach()
293
294    unset( p_l )
295    unset( l )
296endif()
297unset( prev_tx )
298unset( curr_tx )
299
300set( CALAMARES_TRANSLATION_LANGUAGES en ${_tx_complete} ${_tx_good} ${_tx_ok} )
301list( SORT CALAMARES_TRANSLATION_LANGUAGES )
302
303add_subdirectory( lang )  # i18n tools
304
305
306### Example Distro
307#
308# For testing purposes Calamares includes a very, very, limited sample
309# distro called "Generic". The root filesystem of "Generic" lives in
310# data/example-root and can be squashed up as part of the build, so
311# that a pure-upstream run of ./calamares -d from the build directory
312# (with all the default settings and configurations) can actually
313# do an complete example run.
314#
315# Some binaries from the build host (e.g. /bin and /lib) are also
316# squashed into the example filesystem.
317#
318# To build the example distro (for use by the default, example,
319# unsquashfs module), build the target 'example-distro', eg.:
320#
321#   make example-distro
322#
323find_program( mksquashfs_PROGRAM mksquashfs )
324if( mksquashfs_PROGRAM )
325    set( mksquashfs_FOUND ON )
326    set( src_fs ${CMAKE_SOURCE_DIR}/data/example-root/ )
327    set( dst_fs ${CMAKE_BINARY_DIR}/example.sqfs )
328    if( EXISTS ${src_fs} )
329        # based on the build host. If /lib64 exists, assume it is needed.
330        # Collect directories needed for a minimal binary distro,
331        # Note that the last path component is added to the root, so
332        # if you add /usr/sbin here, it will be put into /sbin_1.
333        # Add such paths to /etc/profile under ${src_fs}.
334        set( candidate_fs /sbin /bin /lib /lib64 )
335        set( host_fs "" )
336        foreach( c_fs ${candidate_fs} )
337            if( EXISTS ${c_fs} )
338                list( APPEND host_fs ${c_fs} )
339            endif()
340        endforeach()
341        add_custom_command(
342            OUTPUT ${dst_fs}
343            COMMAND ${mksquashfs_PROGRAM} ${src_fs} ${dst_fs} -all-root
344            COMMAND ${mksquashfs_PROGRAM} ${host_fs} ${dst_fs} -all-root
345        )
346        add_custom_target(example-distro DEPENDS ${dst_fs})
347    endif()
348else()
349    set( mksquashfs_FOUND OFF )
350endif()
351# Doesn't list mksquashfs as an optional dep, though, because it
352# hasn't been sent through the find_package() scheme.
353#
354# "http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html"
355add_feature_info( ExampleDistro ${mksquashfs_FOUND} "Create example-distro target.")
356
357
358### CALAMARES PROPER
359#
360set( CALAMARES_VERSION ${CALAMARES_VERSION_MAJOR}.${CALAMARES_VERSION_MINOR}.${CALAMARES_VERSION_PATCH} )
361set( CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}" )
362if( CALAMARES_VERSION_RC )
363    set( CALAMARES_VERSION ${CALAMARES_VERSION}rc${CALAMARES_VERSION_RC} )
364endif()
365
366# additional info for non-release builds
367if( NOT BUILD_RELEASE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" )
368    include( CMakeDateStamp )
369    set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" )
370    if( CALAMARES_VERSION_DATE GREATER 0 )
371        set( CALAMARES_VERSION ${CALAMARES_VERSION}.${CALAMARES_VERSION_DATE} )
372    endif()
373
374    include( CMakeVersionSource )
375    if( CMAKE_VERSION_SOURCE )
376        set( CALAMARES_VERSION ${CALAMARES_VERSION}-${CMAKE_VERSION_SOURCE} )
377    endif()
378endif()
379
380# enforce using constBegin, constEnd for const-iterators
381add_definitions( "-DQT_STRICT_ITERATORS" )
382
383# set paths
384set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
385set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
386set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
387
388# Better default installation paths: GNUInstallDirs defines
389# CMAKE_INSTALL_FULL_SYSCONFDIR to be CMAKE_INSTALL_PREFIX/etc by default
390# but we really want /etc
391if( NOT DEFINED CMAKE_INSTALL_SYSCONFDIR )
392    set( CMAKE_INSTALL_SYSCONFDIR "/etc" )
393endif()
394
395# make predefined install dirs available everywhere
396include( GNUInstallDirs )
397
398# make uninstall support
399configure_file(
400    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
401    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
402    IMMEDIATE @ONLY
403)
404
405# Early configure these files as we need them later on
406set( CALAMARES_CMAKE_DIR "${CMAKE_SOURCE_DIR}/CMakeModules" )
407set( CALAMARES_LIBRARIES calamares )
408
409add_subdirectory( src )
410
411add_feature_info(Python ${WITH_PYTHON} "Python job modules")
412add_feature_info(PythonQt ${WITH_PYTHONQT} "Python view modules")
413add_feature_info(Config ${INSTALL_CONFIG} "Install Calamares configuration")
414add_feature_info(KCrash ${WITH_KF5Crash} "Crash dumps via KCrash")
415
416# Add all targets to the build-tree export set
417set( CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Calamares" CACHE PATH  "Installation directory for CMake files" )
418set( CMAKE_INSTALL_FULL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" )
419export( TARGETS calamares
420    FILE "${PROJECT_BINARY_DIR}/CalamaresLibraryDepends.cmake" )
421
422# Export the package for use from the build-tree
423# (this registers the build-tree with a global CMake-registry)
424export( PACKAGE Calamares )
425
426# Create a CalamaresBuildTreeSettings.cmake file for the use from the build tree
427configure_file( CalamaresBuildTreeSettings.cmake.in "${PROJECT_BINARY_DIR}/CalamaresBuildTreeSettings.cmake" @ONLY )
428
429# Create the CalamaresConfig.cmake and CalamaresConfigVersion files
430file( RELATIVE_PATH CONF_REL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_CMAKEDIR}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}" )
431
432configure_file( CalamaresConfig.cmake.in "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake" @ONLY )
433configure_file( CalamaresConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake" @ONLY )
434configure_file( CalamaresUse.cmake.in "${PROJECT_BINARY_DIR}/CalamaresUse.cmake" @ONLY )
435
436# Install the cmake files
437install(
438    FILES
439        "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake"
440        "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake"
441        "${PROJECT_BINARY_DIR}/CalamaresUse.cmake"
442        "CMakeModules/CalamaresAddPlugin.cmake"
443        "CMakeModules/CalamaresAddModuleSubdirectory.cmake"
444        "CMakeModules/CalamaresAddLibrary.cmake"
445        "CMakeModules/CalamaresAddBrandingSubdirectory.cmake"
446        "CMakeModules/CalamaresAddTranslations.cmake"
447        "CMakeModules/CMakeColors.cmake"
448    DESTINATION
449        "${CMAKE_INSTALL_CMAKEDIR}"
450)
451
452# Install the export set for use with the install-tree
453install(
454    EXPORT
455        CalamaresLibraryDepends
456    DESTINATION
457        "${CMAKE_INSTALL_CMAKEDIR}"
458)
459
460if( INSTALL_CONFIG )
461    install(
462        FILES
463            settings.conf
464        DESTINATION
465            share/calamares
466    )
467endif()
468
469if( INSTALL_POLKIT )
470    install(
471        FILES
472            com.github.calamares.calamares.policy
473        DESTINATION
474          "${POLKITQT-1_POLICY_FILES_INSTALL_DIR}"
475    )
476endif()
477
478install(
479  FILES
480      calamares.desktop
481  DESTINATION
482      ${CMAKE_INSTALL_DATADIR}/applications
483)
484
485install(
486    FILES
487        man/calamares.8
488    DESTINATION
489        ${CMAKE_INSTALL_MANDIR}/man8/
490)
491
492# uninstall target
493configure_file(
494    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
495    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
496    IMMEDIATE @ONLY
497)
498
499add_custom_target( uninstall
500    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
501)
502
503### CMAKE SUMMARY REPORT
504#
505feature_summary(WHAT ALL)
506
507get_directory_property( SKIPPED_MODULES
508    DIRECTORY src/modules
509    DEFINITION LIST_SKIPPED_MODULES
510)
511calamares_explain_skipped_modules( ${SKIPPED_MODULES} )
Note: See TracBrowser for help on using the repository browser.