include ( CMakeColors )
include ( CalamaresAddTranslations )
set ( MODULE_DATA_DESTINATION share/calamares/modules )
function ( calamares_add_module_subdirectory )
set ( SUBDIRECTORY ${ ARGV0 } )
set ( MODULE_CONFIG_FILES "" )
# If this subdirectory has a CMakeLists.txt, we add_subdirectory it...
if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" )
add_subdirectory ( ${ SUBDIRECTORY } )
file ( GLOB MODULE_CONFIG_FILES RELATIVE ${ CMAKE_CURRENT_SOURCE_DIR } / ${ SUBDIRECTORY } "${SUBDIRECTORY}/*.conf" )
# ...otherwise, we look for a module.desc.
elseif ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/module.desc" )
set ( MODULES_DIR ${ CMAKE_INSTALL_LIBDIR } /calamares/modules )
set ( MODULE_DESTINATION ${ MODULES_DIR } / ${ SUBDIRECTORY } )
# 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 ${ CMAKE_CURRENT_SOURCE_DIR } / ${ SUBDIRECTORY } "${SUBDIRECTORY}/*" )
foreach ( MODULE_FILE ${ MODULE_FILES } )
if ( NOT IS_DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } / ${ SUBDIRECTORY } / ${ MODULE_FILE } )
configure_file ( ${ SUBDIRECTORY } / ${ MODULE_FILE } ${ SUBDIRECTORY } / ${ MODULE_FILE } COPYONLY )
get_filename_component ( FLEXT ${ MODULE_FILE } EXT )
if ( "${FLEXT}" STREQUAL ".conf" AND 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 } )
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 ( )
endif ( )
endforeach ( )
message ( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} module: ${BoldRed}${SUBDIRECTORY}${ColorReset}" )
if ( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
message ( " ${Green}TYPE:${ColorReset} jobmodule" )
# message( " ${Green}FILES:${ColorReset} ${MODULE_FILES}" )
message ( " ${Green}MODULE_DESTINATION:${ColorReset} ${MODULE_DESTINATION}" )
if ( MODULE_CONFIG_FILES )
if ( INSTALL_CONFIG )
message ( " ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => ${MODULE_DATA_DESTINATION}" )
else ( )
message ( " ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => [Skipping installation]" )
endif ( )
endif ( )
message ( "" )
endif ( )
# We copy over the lang directory, if any
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" )
install_calamares_gettext_translations (
$ { S U B D I R E C T O R Y }
S O U R C E _ D I R " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { S U B D I R E C T O R Y } / l a n g "
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 ( )
message ( "-- ${BoldYellow}Warning:${ColorReset} tried to add module subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no CMakeLists.txt or module.desc." )
message ( "" )
endif ( )
# 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 ( )
endfunction ( )