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

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

sync with github

File size: 6.4 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# Function and support code for adding a Calamares module (either a Qt / C++ plugin,
22# or a Python module, or whatever) to the build.
23#
24include( CalamaresAddTranslations )
25
26set( MODULE_DATA_DESTINATION share/calamares/modules )
27
28# Convenience function to indicate that a module has been skipped
29# (optionally also why). Call this in the module's CMakeLists.txt
30macro( calamares_skip_module )
31    set( SKIPPED_MODULES ${SKIPPED_MODULES} ${ARGV} PARENT_SCOPE )
32endmacro()
33
34function( calamares_explain_skipped_modules )
35    if ( ARGN )
36        message( "${ColorReset}-- Skipped modules:" )
37        foreach( SUBDIRECTORY ${ARGN} )
38            message( "${ColorReset}--   Skipped ${BoldRed}${SUBDIRECTORY}${ColorReset}." )
39        endforeach()
40        message( "" )
41    endif()
42endfunction()
43
44function( calamares_add_module_subdirectory )
45    set( SUBDIRECTORY ${ARGV0} )
46
47    set( SKIPPED_MODULES )
48    set( MODULE_CONFIG_FILES "" )
49
50    set( _mod_dir "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" )
51    # If this subdirectory has a CMakeLists.txt, we add_subdirectory it...
52    if( EXISTS "${_mod_dir}/CMakeLists.txt" )
53        add_subdirectory( ${SUBDIRECTORY} )
54        file( GLOB MODULE_CONFIG_FILES RELATIVE ${_mod_dir} "${SUBDIRECTORY}/*.conf" )
55        # Module has indicated it should be skipped, show that in
56        # the calling CMakeLists (which is src/modules/CMakeLists.txt normally).
57        if ( SKIPPED_MODULES )
58            set( SKIPPED_MODULES ${SKIPPED_MODULES} PARENT_SCOPE )
59            set( MODULE_CONFIG_FILES "" )
60        endif()
61    # ...otherwise, we look for a module.desc.
62    elseif( EXISTS "${_mod_dir}/module.desc" )
63        set( MODULES_DIR ${CMAKE_INSTALL_LIBDIR}/calamares/modules )
64        set( MODULE_DESTINATION ${MODULES_DIR}/${SUBDIRECTORY} )
65
66        # Read module.desc, check that the interface type is supported.
67        file(STRINGS "${_mod_dir}/module.desc" MODULE_INTERFACE REGEX "^interface")
68        if ( MODULE_INTERFACE MATCHES "pythonqt" )
69            set( _mod_enabled ${WITH_PYTHONQT} )
70            set( _mod_reason "No PythonQt support" )
71        elseif ( MODULE_INTERFACE MATCHES "python" )
72            set( _mod_enabled ${WITH_PYTHON} )
73            set( _mod_reason "No Python support" )
74        else()
75            set( _mod_enabled ON )
76            set( _mod_reason "" )
77        endif()
78
79        if ( _mod_enabled )
80            # We glob all the files inside the subdirectory, and we make sure they are
81            # synced with the bindir structure and installed.
82            file( GLOB MODULE_FILES RELATIVE ${_mod_dir} "${SUBDIRECTORY}/*" )
83            foreach( MODULE_FILE ${MODULE_FILES} )
84                if( NOT IS_DIRECTORY ${_mod_dir}/${MODULE_FILE} )
85                    configure_file( ${SUBDIRECTORY}/${MODULE_FILE} ${SUBDIRECTORY}/${MODULE_FILE} COPYONLY )
86
87                    get_filename_component( FLEXT ${MODULE_FILE} EXT )
88                    if( "${FLEXT}" STREQUAL ".conf" AND INSTALL_CONFIG)
89                        install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${MODULE_FILE}
90                                 DESTINATION ${MODULE_DATA_DESTINATION} )
91                        list( APPEND MODULE_CONFIG_FILES ${MODULE_FILE} )
92                    else()
93                        install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${MODULE_FILE}
94                                 DESTINATION ${MODULE_DESTINATION} )
95                    endif()
96                endif()
97            endforeach()
98
99            message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} module: ${BoldRed}${SUBDIRECTORY}${ColorReset}" )
100            if( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
101                message( "   ${Green}TYPE:${ColorReset} jobmodule" )
102                message( "   ${Green}MODULE_DESTINATION:${ColorReset} ${MODULE_DESTINATION}" )
103                if( MODULE_CONFIG_FILES )
104                    if ( INSTALL_CONFIG )
105                        message( "   ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => ${MODULE_DATA_DESTINATION}" )
106                    else()
107                        message( "   ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => [Skipping installation]" )
108                    endif()
109                endif()
110                message( "" )
111            endif()
112            # We copy over the lang directory, if any
113            if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" )
114                install_calamares_gettext_translations(
115                    ${SUBDIRECTORY}
116                    SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang"
117                    FILENAME ${SUBDIRECTORY}.mo
118                    RENAME calamares-${SUBDIRECTORY}.mo
119                )
120            endif()
121        else()
122            # Module disabled due to missing dependencies / unsupported interface
123            set( SKIPPED_MODULES "${SUBDIRECTORY} (${_mod_reason})" PARENT_SCOPE )
124        endif()
125    else()
126        message( "-- ${BoldYellow}Warning:${ColorReset} tried to add module subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no CMakeLists.txt or module.desc." )
127        message( "" )
128    endif()
129
130    # Check any config files for basic correctness
131    if ( BUILD_TESTING AND MODULE_CONFIG_FILES )
132        set( _count 0 )
133        foreach( _config_file ${MODULE_CONFIG_FILES} )
134            set( _count_str "-${_count}" )
135            if ( _count EQUAL 0 )
136                set( _count_str "" )
137            endif()
138            add_test(
139                NAME config-${SUBDIRECTORY}${_count_str}
140                COMMAND test_conf ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${_config_file} )
141            math( EXPR _count "${_count} + 1" )
142        endforeach()
143    endif()
144endfunction()
Note: See TracBrowser for help on using the repository browser.