CMake: introduce USE_<foo>

When there are multiple modules doing a thing and it really only
makes sense to have one of them in a given Calamares compilation,
the USE_<foo> variables allow you to select one, while ignoring
all the other implementations. If USE_<foo> is not set, all
implementations are included (as usual).
main
Adriaan de Groot 7 years ago
parent 29830bc1e1
commit b2c2b91645

@ -43,6 +43,22 @@ option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON )
option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." ON ) option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." ON )
option( WITH_KF5Crash "Enable crash reporting with KCrash." ON ) option( WITH_KF5Crash "Enable crash reporting with KCrash." ON )
### USE_*
#
# By convention, when there are multiple modules that implement similar
# functionality, and it only makes sense to have **at most one** of them
# enabled at any time, those modules are named <foo>-<implementation>.
# For example, services-systemd and services-openrc.
#
# Setting up SKIP_MODULES to ignore "the ones you don't want" can be
# annoying and error-prone (e.g. if a new module shows up). The USE_*
# modules provide a way to do automatic selection. To pick exactly
# one of the implementations from group <foo>, set USE_<foo> to the
# name of the implementation. If USE_<foo> is unset, or empty, then
# all the implementations are enabled (this just means they are
# **available** to `settings.conf`, not that they are used).
#
# Currently, no USE_<foo> variables exist.
### Calamares application info ### Calamares application info
# #

@ -15,13 +15,31 @@ string( REPLACE " " ";" SKIP_LIST "${SKIP_MODULES}" )
file( GLOB SUBDIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*" ) file( GLOB SUBDIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*" )
list( SORT SUBDIRECTORIES ) list( SORT SUBDIRECTORIES )
# Handle the USE_<foo> variables by looking for subdirectories
# with a <foo>-<implementation> kind of name.
foreach( SUBDIRECTORY ${SUBDIRECTORIES} )
endforeach()
foreach( SUBDIRECTORY ${SUBDIRECTORIES} ) foreach( SUBDIRECTORY ${SUBDIRECTORIES} )
list( FIND SKIP_LIST ${SUBDIRECTORY} DO_SKIP ) list( FIND SKIP_LIST ${SUBDIRECTORY} DO_SKIP )
set( _skip_reason "user request" )
if( SUBDIRECTORY MATCHES "^[a-zA-Z0-9_]+-" )
string( REGEX REPLACE "^[^-]+-" "" _implementation ${SUBDIRECTORY} )
string( REGEX REPLACE "-.*" "" _category ${SUBDIRECTORY} )
if( USE_${_category} )
if( NOT "${_implementation}" STREQUAL "${USE_${_category}}" )
list( APPEND SKIP_LIST ${SUBDIRECTORY} )
set( _skip_reason "USE_${_category}=${USE_${_category}}" )
set( DO_SKIP 1 )
endif()
endif()
endif()
if( NOT DO_SKIP EQUAL -1 ) if( NOT DO_SKIP EQUAL -1 )
message( "${ColorReset}-- Skipping module ${BoldRed}${SUBDIRECTORY}${ColorReset}." ) message( "${ColorReset}-- Skipping module ${BoldRed}${SUBDIRECTORY}${ColorReset}." )
message( "" ) message( "" )
list( APPEND LIST_SKIPPED_MODULES "${SUBDIRECTORY} (user request)" ) list( APPEND LIST_SKIPPED_MODULES "${SUBDIRECTORY} (${_skip_reason})" )
elseif( ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" ) AND elseif( ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" ) AND
( DO_SKIP EQUAL -1 ) ) ( DO_SKIP EQUAL -1 ) )
set( SKIPPED_MODULES ) set( SKIPPED_MODULES )

Loading…
Cancel
Save