Debian Codegraph @

CMakeModules/CalamaresAddBrandingSubdirectory.cmake

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