2020-08-25 16:05:56 +02:00
# === This file is part of Calamares - <https://calamares.io> ===
2018-03-09 17:13:42 +01:00
#
2020-08-26 00:24:40 +02:00
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
2020-08-25 16:05:56 +02:00
# Calamares is Free Software: see the License-Identifier above.
2018-03-09 17:13:42 +01:00
#
#
###
#
# Function and support code for adding a Calamares module (either a Qt / C++ plugin,
# or a Python module, or whatever) to the build.
#
2017-08-15 10:34:28 +02:00
include ( CalamaresAddTranslations )
2014-07-14 16:26:10 +02:00
2015-09-09 18:55:08 +02:00
set ( MODULE_DATA_DESTINATION share/calamares/modules )
2017-12-24 22:08:48 +01:00
# Convenience function to indicate that a module has been skipped
# (optionally also why). Call this in the module's CMakeLists.txt
macro ( calamares_skip_module )
set ( SKIPPED_MODULES ${ SKIPPED_MODULES } ${ ARGV } PARENT_SCOPE )
endmacro ( )
2018-01-10 15:20:49 +01:00
function ( calamares_explain_skipped_modules )
if ( ARGN )
message ( "${ColorReset}-- Skipped modules:" )
foreach ( SUBDIRECTORY ${ ARGN } )
message ( "${ColorReset}-- Skipped ${BoldRed}${SUBDIRECTORY}${ColorReset}." )
endforeach ( )
message ( "" )
endif ( )
endfunction ( )
2014-07-14 16:26:10 +02:00
function ( calamares_add_module_subdirectory )
set ( SUBDIRECTORY ${ ARGV0 } )
2017-12-24 22:08:48 +01:00
set ( SKIPPED_MODULES )
2017-10-12 18:37:54 +02:00
set ( MODULE_CONFIG_FILES "" )
2018-01-15 22:41:06 +01:00
set ( _mod_dir "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" )
2014-07-14 16:26:10 +02:00
# If this subdirectory has a CMakeLists.txt, we add_subdirectory it...
2018-01-15 22:41:06 +01:00
if ( EXISTS "${_mod_dir}/CMakeLists.txt" )
2014-07-14 16:26:10 +02:00
add_subdirectory ( ${ SUBDIRECTORY } )
2018-01-15 22:41:06 +01:00
file ( GLOB MODULE_CONFIG_FILES RELATIVE ${ _mod_dir } "${SUBDIRECTORY}/*.conf" )
2017-12-24 22:08:48 +01:00
# Module has indicated it should be skipped, show that in
# the calling CMakeLists (which is src/modules/CMakeLists.txt normally).
if ( SKIPPED_MODULES )
set ( SKIPPED_MODULES ${ SKIPPED_MODULES } PARENT_SCOPE )
2018-02-07 13:31:50 +01:00
set ( MODULE_CONFIG_FILES "" )
2017-12-24 22:08:48 +01:00
endif ( )
2014-08-06 16:01:39 +02:00
# ...otherwise, we look for a module.desc.
2018-01-15 22:41:06 +01:00
elseif ( EXISTS "${_mod_dir}/module.desc" )
2014-07-14 16:26:10 +02:00
set ( MODULES_DIR ${ CMAKE_INSTALL_LIBDIR } /calamares/modules )
2020-06-12 12:05:35 +02:00
# The module subdirectory may be given as a/b/c, but the module
# needs to be installed as "c", so we split off any intermediate
# directories.
get_filename_component ( _dirname "${SUBDIRECTORY}" DIRECTORY )
if ( _dirname )
# Remove the dirname and any leftover leading /s
string ( REGEX REPLACE "^${_dirname}/*" "" _modulename "${SUBDIRECTORY}" )
set ( MODULE_DESTINATION ${ MODULES_DIR } / ${ _modulename } )
else ( )
set ( MODULE_DESTINATION ${ MODULES_DIR } / ${ SUBDIRECTORY } )
endif ( )
2014-07-14 16:26:10 +02:00
2018-01-15 22:41:06 +01:00
# Read module.desc, check that the interface type is supported.
2019-04-28 15:06:10 +02:00
#
# _mod_enabled boolean if the module should be built (only if the interface is supported)
# _mod_reason is a human-readable explanation why it isn't built
# _mod_testing boolean if the module should be added to the loadmodule tests
2018-01-15 22:41:06 +01:00
file ( STRINGS "${_mod_dir}/module.desc" MODULE_INTERFACE REGEX "^interface" )
if ( MODULE_INTERFACE MATCHES "pythonqt" )
2020-06-12 11:35:23 +02:00
set ( _mod_enabled ${ Calamares_WITH_PYTHONQT } )
2018-01-15 22:41:06 +01:00
set ( _mod_reason "No PythonQt support" )
2019-04-28 15:06:10 +02:00
set ( _mod_testing OFF )
2018-01-15 22:41:06 +01:00
elseif ( MODULE_INTERFACE MATCHES "python" )
2020-06-12 11:35:23 +02:00
set ( _mod_enabled ${ Calamares_WITH_PYTHON } )
2018-01-15 22:41:06 +01:00
set ( _mod_reason "No Python support" )
2019-04-28 15:06:10 +02:00
set ( _mod_testing ON ) # Will check syntax and imports, at least
2019-04-27 17:30:16 +02:00
elseif ( MODULE_INTERFACE MATCHES "qtplugin" )
set ( _mod_enabled OFF )
set ( _mod_reason "C++ modules must have a CMakeLists.txt instead" )
2019-04-28 15:06:10 +02:00
set ( _mod_testing OFF )
2019-04-27 17:30:16 +02:00
elseif ( MODULE_INTERFACE MATCHES "process" )
2018-01-15 22:41:06 +01:00
set ( _mod_enabled ON )
set ( _mod_reason "" )
2019-04-28 15:06:10 +02:00
set ( _mod_testing OFF )
2019-04-27 17:30:16 +02:00
else ( )
set ( _mod_enabled OFF )
set ( _mod_reason "Unknown module interface '${MODULE_INTERFACE}'" )
2019-04-28 15:06:10 +02:00
set ( _mod_testing OFF )
2018-01-15 22:41:06 +01:00
endif ( )
if ( _mod_enabled )
# We glob all the files inside the subdirectory, and we make sure they are
# synced with the bindir structure and installed.
file ( GLOB MODULE_FILES RELATIVE ${ _mod_dir } "${SUBDIRECTORY}/*" )
foreach ( MODULE_FILE ${ MODULE_FILES } )
if ( NOT IS_DIRECTORY ${ _mod_dir } / ${ MODULE_FILE } )
configure_file ( ${ SUBDIRECTORY } / ${ MODULE_FILE } ${ SUBDIRECTORY } / ${ MODULE_FILE } COPYONLY )
2014-08-05 18:18:57 +02:00
2018-01-15 22:41:06 +01:00
get_filename_component ( FLEXT ${ MODULE_FILE } EXT )
2018-06-27 19:20:52 +02:00
if ( "${FLEXT}" STREQUAL ".conf" )
if ( INSTALL_CONFIG )
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } / ${ SUBDIRECTORY } / ${ MODULE_FILE }
D E S T I N A T I O N $ { M O D U L E _ D A T A _ D E S T I N A T I O N } )
endif ( )
2018-01-15 22:41:06 +01:00
list ( APPEND MODULE_CONFIG_FILES ${ MODULE_FILE } )
else ( )
install ( FILES ${ CMAKE_CURRENT_BINARY_DIR } / ${ SUBDIRECTORY } / ${ MODULE_FILE }
D E S T I N A T I O N $ { M O D U L E _ D E S T I N A T I O N } )
endif ( )
2014-08-05 18:18:57 +02:00
endif ( )
2018-01-15 22:41:06 +01:00
endforeach ( )
2014-07-14 16:26:10 +02:00
2018-01-15 22:41:06 +01:00
message ( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} module: ${BoldRed}${SUBDIRECTORY}${ColorReset}" )
2018-09-14 11:33:04 +02:00
message ( " ${Green}TYPE:${ColorReset} jobmodule" )
message ( " ${Green}MODULE_DESTINATION:${ColorReset} ${MODULE_DESTINATION}" )
if ( MODULE_CONFIG_FILES )
if ( INSTALL_CONFIG )
set ( _destination "${MODULE_DATA_DESTINATION}" )
else ( )
set ( _destination "[Build directory only]" )
2016-11-21 01:32:04 +01:00
endif ( )
2018-09-14 11:33:04 +02:00
message ( " ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => ${_destination}" )
2015-09-09 18:55:08 +02:00
endif ( )
2018-09-14 11:33:04 +02:00
message ( "" )
2018-01-15 22:41:06 +01:00
# We copy over the lang directory, if any
2020-05-15 14:38:45 +02:00
if ( IS_DIRECTORY "${_mod_dir}/lang" )
2018-01-15 22:41:06 +01:00
install_calamares_gettext_translations (
$ { S U B D I R E C T O R Y }
2020-05-15 14:38:45 +02:00
S O U R C E _ D I R " $ { _ m o d _ d i r } / l a n g "
2018-01-15 22:41:06 +01:00
F I L E N A M E $ { S U B D I R E C T O R Y } . m o
R E N A M E c a l a m a r e s - $ { S U B D I R E C T O R Y } . m o
)
endif ( )
else ( )
# Module disabled due to missing dependencies / unsupported interface
set ( SKIPPED_MODULES "${SUBDIRECTORY} (${_mod_reason})" PARENT_SCOPE )
2017-08-15 10:34:28 +02:00
endif ( )
2014-07-14 16:26:10 +02:00
else ( )
2014-08-06 16:01:39 +02:00
message ( "-- ${BoldYellow}Warning:${ColorReset} tried to add module subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no CMakeLists.txt or module.desc." )
2014-07-14 16:26:10 +02:00
message ( "" )
endif ( )
2017-10-12 18:37:54 +02:00
# Check any config files for basic correctness
if ( BUILD_TESTING AND MODULE_CONFIG_FILES )
set ( _count 0 )
foreach ( _config_file ${ MODULE_CONFIG_FILES } )
set ( _count_str "-${_count}" )
if ( _count EQUAL 0 )
set ( _count_str "" )
endif ( )
add_test (
N A M E c o n f i g - $ { S U B D I R E C T O R Y } $ { _ c o u n t _ s t r }
C O M M A N D t e s t _ c o n f $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { S U B D I R E C T O R Y } / $ { _ c o n f i g _ f i l e } )
math ( EXPR _count "${_count} + 1" )
endforeach ( )
endif ( )
2019-04-27 17:58:29 +02:00
# Check that the module can be loaded. Since this calls exec(), the module
# may try to do things to the running system. Needs work to make that a
# safe thing to do.
#
2020-05-15 14:38:45 +02:00
# If the module has a tests/ subdirectory with *.global and *.job
# files (YAML files holding global and job-configurations for
# testing purposes) then those files are used to drive additional
# tests. The files must be numbered (starting from 1) for this to work;
# 1.global and 1.job together make the configuration for test 1.
#
# If the module has a tests/CMakeLists.txt while it doesn't have its
# own CMakeLists.txt (e.g. a Python module), then the subdirectory
# for tests/ is added on its own.
#
2019-04-28 15:06:10 +02:00
if ( BUILD_TESTING AND _mod_enabled AND _mod_testing )
add_test (
N A M E l o a d - $ { S U B D I R E C T O R Y }
C O M M A N D l o a d m o d u l e $ { S U B D I R E C T O R Y }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R }
)
2020-05-08 21:50:11 +02:00
# Try it with the tests/ configurations shipped with the module
set ( _count 1 )
2020-05-15 14:38:45 +02:00
set ( _testdir ${ _mod_dir } /tests )
2020-05-08 21:50:11 +02:00
while ( EXISTS "${_testdir}/${_count}.global" OR EXISTS "${_testdir}/${_count}.job" )
set ( _dash_g "" )
set ( _dash_j "" )
if ( EXISTS "${_testdir}/${_count}.global" )
set ( _dash_g -g ${ _testdir } / ${ _count } .global )
endif ( )
if ( EXISTS "${_testdir}/${_count}.job" )
set ( _dash_j -j ${ _testdir } / ${ _count } .job )
endif ( )
add_test (
N A M E l o a d - $ { S U B D I R E C T O R Y } - $ { _ c o u n t }
C O M M A N D l o a d m o d u l e $ { _ d a s h _ g } $ { _ d a s h _ j } $ { S U B D I R E C T O R Y }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R }
)
math ( EXPR _count "${_count} + 1" )
endwhile ( )
2020-05-15 14:38:45 +02:00
if ( EXISTS ${ _testdir } /CMakeTests.txt AND NOT EXISTS ${ _mod_dir } /CMakeLists.txt )
include ( ${ _testdir } /CMakeTests.txt )
endif ( )
2019-04-28 15:06:10 +02:00
endif ( )
2014-07-14 16:26:10 +02:00
endfunction ( )