source: calamares/trunk/fuentes/CMakeModules/CalamaresAddBrandingSubdirectory.cmake @ 7538

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

sync with github

File size: 6.8 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# Support macros for creating Calamares branding components.
22#
23# Calamares branding components have two parts:
24# - a branding.desc file that tells Calamares how to describe the product
25#   (e.g. strings like "Generic GNU/Linux") and the name of a QML file
26#   (the "slideshow") that is displayed during installation.
27# - the QML files themselves, plus supporting images etc.
28#
29# Branding components can be created inside the Calamares source tree
30# (there is one example the `default/` branding, which is also connected
31# to the default configuration shipped with Calamares), but they can be
32# built outside of, and largely independently of, Calamares by using
33# these CMake macros.
34#
35# See the calamares-examples repository for more examples.
36#
37include( CMakeParseArguments)
38
39include( CMakeColors )
40
41# Usage calamares_add_branding( <name> [DIRECTORY <dir>] [SUBDIRECTORIES <dir> ...])
42#
43# Adds a branding component to the build:
44# - the component's top-level files are copied into the build-dir;
45#   CMakeLists.txt is excluded from the glob.
46# - the component's top-level files are installed into the component branding dir
47#
48# The branding component lives in <dir> if given, otherwise the
49# current source directory. The branding component is installed
50# with the given <name>, which is usually the name of the
51# directory containing the component, and which must match the
52# *componentName* in `branding.desc`.
53#
54# If SUBDIRECTORIES are given, then those are copied (each one level deep)
55# to the installation location as well, preserving the subdirectory name.
56function( calamares_add_branding NAME )
57    cmake_parse_arguments( _CABT "" "DIRECTORY" "SUBDIRECTORIES" ${ARGN} )
58    if (NOT _CABT_DIRECTORY)
59        set(_CABT_DIRECTORY ".")
60    endif()
61
62    set( SUBDIRECTORY ${_CABT_DIRECTORY} )
63    set( _brand_dir ${_CABT_DIRECTORY} )
64
65    set( BRANDING_DIR share/calamares/branding )
66    set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
67
68    foreach( _subdir "" ${_CABT_SUBDIRECTORIES} )
69        file( GLOB BRANDING_COMPONENT_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${_brand_dir} "${_brand_dir}/${_subdir}/*" )
70        foreach( BRANDING_COMPONENT_FILE ${BRANDING_COMPONENT_FILES} )
71            set( _subpath ${_brand_dir}/${BRANDING_COMPONENT_FILE} )
72            if( NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_subpath} )
73                configure_file( ${_subpath} ${_subpath} COPYONLY )
74
75                install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_subpath}
76                            DESTINATION ${BRANDING_COMPONENT_DESTINATION}/${_subdir}/ )
77            endif()
78        endforeach()
79    endforeach()
80
81    message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} branding component: ${BoldRed}${NAME}${ColorReset}" )
82    if( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
83        message( "   ${Green}TYPE:${ColorReset} branding component" )
84        message( "   ${Green}BRANDING_COMPONENT_DESTINATION:${ColorReset} ${BRANDING_COMPONENT_DESTINATION}" )
85    endif()
86endfunction()
87
88# Usage calamares_add_branding_translations( <name> [DIRECTORY <dir>])
89#
90# Adds the translations for a branding component to the build:
91# - the component's lang/ directory is scanned for .ts files
92# - the component's translations are installed into the component branding dir
93#
94# Translation files must be called calamares-<name>_<lang>.ts . Optionally
95# the lang/ dir is found in the given <dir> instead of the current source
96# directory.
97function( calamares_add_branding_translations NAME )
98    cmake_parse_arguments( _CABT "" "DIRECTORY" "" ${ARGN} )
99    if (NOT _CABT_DIRECTORY)
100        set(_CABT_DIRECTORY ".")
101    endif()
102
103    set( SUBDIRECTORY ${_CABT_DIRECTORY} )
104    set( _brand_dir ${_CABT_DIRECTORY} )
105
106    set( BRANDING_DIR share/calamares/branding )
107    set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
108
109    file( GLOB BRANDING_TRANSLATION_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIRECTORY}/lang/calamares-${NAME}_*.ts" )
110    if ( BRANDING_TRANSLATION_FILES )
111        qt5_add_translation( QM_FILES ${BRANDING_TRANSLATION_FILES} )
112        add_custom_target( branding-translation-${NAME} ALL DEPENDS ${QM_FILES} )
113        install( FILES ${QM_FILES} DESTINATION ${BRANDING_COMPONENT_DESTINATION}/lang/ )
114        list( LENGTH BRANDING_TRANSLATION_FILES _branding_count )
115        message( "   ${Green}BRANDING_TRANSLATIONS:${ColorReset} ${_branding_count} language(s)" )
116    endif()
117endfunction()
118
119# Usage calamares_add_branding_subdirectory( <dir> [NAME <name>] [SUBDIRECTORIES <dir> ...])
120#
121# Adds a branding component from a subdirectory:
122# - if there is a CMakeLists.txt, use that (that CMakeLists.txt should
123#   call suitable calamares_add_branding() and other macros to install
124#   the branding component).
125# - otherwise assume a "standard" setup with top-level files and a lang/
126#   subdirectory for translations.
127#
128# If NAME is given, this is used instead of <dir> as the name of
129# the branding component. This is needed if <dir> is more than
130# one level deep, or to rename a component as it gets installed.
131#
132# If SUBDIRECTORIES are given, they are relative to <dir>, and are
133# copied (one level deep) to the install location as well.
134function( calamares_add_branding_subdirectory SUBDIRECTORY )
135    cmake_parse_arguments( _CABS "" "NAME" "SUBDIRECTORIES" ${ARGN} )
136    if (NOT _CABS_NAME)
137        set(_CABS_NAME "${SUBDIRECTORY}")
138    endif()
139
140    if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" )
141        add_subdirectory( ${SUBDIRECTORY} )
142    elseif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/branding.desc" )
143        calamares_add_branding( ${_CABS_NAME} DIRECTORY ${SUBDIRECTORY} SUBDIRECTORIES ${_CABS_SUBDIRECTORIES} )
144        if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" )
145            calamares_add_branding_translations( ${_CABS_NAME} DIRECTORY ${SUBDIRECTORY} )
146        endif()
147    else()
148        message( "-- ${BoldYellow}Warning:${ColorReset} tried to add branding component subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no branding.desc." )
149    endif()
150    message( "" )
151endfunction()
Note: See TracBrowser for help on using the repository browser.