CMake: improve branding support

- Fix broken subdirectory call
 - Automatically process lang/ if there isn't a CMakeLists.txt,
   this was a bogus restriction
 - Add support macros for installing branding and translations
This commit is contained in:
Adriaan de Groot 2018-03-08 13:09:53 -05:00
parent 2fee85907d
commit 345118aec9

View File

@ -1,22 +1,32 @@
include( CMakeParseArguments)
include( CMakeColors ) include( CMakeColors )
function( calamares_add_branding_subdirectory ) # Usage calamares_add_branding( NAME <name> [SUBDIRECTORY <dir>])
set( SUBDIRECTORY ${ARGV0} ) #
# Adds a branding component to the build:
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" ) # - the component's top-level files are copied into the build-dir;
add_subdirectory( $SUBDIRECTORY ) # CMakeLists.txt is excluded from the glob.
message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} branding component: ${BoldRed}${SUBDIRECTORY}${ColorReset}" ) # - the component's top-level files are installed into the component branding dir
#
elseif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/branding.desc" ) # The branding component lives in <dir> if given, otherwise the
set( BRANDING_DIR share/calamares/branding ) # current source directory. The branding component is installed
set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${SUBDIRECTORY} ) # with the given <name>, which is usually the name of the
# directory containing the component, and which must match the
if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" ) # *componentName* in `branding.desc`.
message( "-- ${BoldYellow}Warning:${ColorReset} branding component ${BoldRed}${SUBDIRECTORY}${ColorReset} has a translations subdirectory but no CMakeLists.txt." ) function( calamares_add_branding )
message( "" ) set( _CABT_SUBDIRECTORY "." )
return() cmake_parse_arguments( _CABT "" "NAME;SUBDIRECTORY" "" ${ARGN} )
if ( NOT _CABT_NAME )
message( FATAL_ERROR "Branding component must have a NAME" )
endif() endif()
set( NAME ${_CABT_NAME} )
set( SUBDIRECTORY ${_CABT_SUBDIRECTORY} )
set( BRANDING_DIR share/calamares/branding )
set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
# We glob all the files inside the subdirectory, and we make sure they are # We glob all the files inside the subdirectory, and we make sure they are
# synced with the bindir structure and installed. # synced with the bindir structure and installed.
file( GLOB BRANDING_COMPONENT_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY} "${SUBDIRECTORY}/*" ) file( GLOB BRANDING_COMPONENT_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY} "${SUBDIRECTORY}/*" )
@ -29,15 +39,61 @@ function( calamares_add_branding_subdirectory )
endif() endif()
endforeach() endforeach()
message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} branding component: ${BoldRed}${SUBDIRECTORY}${ColorReset}" ) message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} branding component: ${BoldRed}${NAME}${ColorReset}" )
if( NOT CMAKE_BUILD_TYPE STREQUAL "Release" ) if( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
message( " ${Green}TYPE:${ColorReset} branding component" ) message( " ${Green}TYPE:${ColorReset} branding component" )
# message( " ${Green}FILES:${ColorReset} ${BRANDING_COMPONENT_FILES}" )
message( " ${Green}BRANDING_COMPONENT_DESTINATION:${ColorReset} ${BRANDING_COMPONENT_DESTINATION}" ) message( " ${Green}BRANDING_COMPONENT_DESTINATION:${ColorReset} ${BRANDING_COMPONENT_DESTINATION}" )
message( "" ) endif()
endfunction()
# Usage calamares_add_branding_translations( NAME <name> [SUBDIRECTORY <dir>])
#
# Adds the translations for a branding component to the build:
# - the component's lang/ directory is scanned for .ts files
# - the component's translations are installed into the component branding dir
#
# Translation files must be called calamares-<name>_<lang>.ts . Optionally
# the lang/ dir is found in the given <dir> instead of the current source
# directory.
function( calamares_add_branding_translations )
set( _CABT_SUBDIRECTORY "." )
cmake_parse_arguments( _CABT "" "NAME;SUBDIRECTORY" "" ${ARGN} )
if ( NOT _CABT_NAME )
message( FATAL_ERROR "Branding component must have a NAME" )
endif()
set( NAME ${_CABT_NAME} )
set( SUBDIRECTORY ${_CABT_SUBDIRECTORY} )
set( BRANDING_DIR share/calamares/branding )
set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
file( GLOB BRANDING_TRANSLATION_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIRECTORY}/lang/calamares-${NAME}_*.ts" )
if ( BRANDING_TRANSLATION_FILES )
qt5_add_translation( QM_FILES ${BRANDING_TRANSLATION_FILES} )
add_custom_target( branding-translation-${NAME} ALL DEPENDS ${QM_FILES} )
install( FILES ${QM_FILES} DESTINATION ${BRANDING_COMPONENT_DESTINATION}/lang/ )
list( LENGTH BRANDING_TRANSLATION_FILES _branding_count )
message( " ${Green}BRANDING_TRANSLATIONS:${ColorReset} ${_branding_count} language(s)" )
endif()
endfunction()
# Usage calamares_add_branding_subdirectory( <dir> )
#
# Adds a branding component from a subdirectory:
# - if there is a CMakeLists.txt, use that
# - otherwise assume a "standard" setup with top-level files and a lang/ dir for translations
#
function( calamares_add_branding_subdirectory SUBDIRECTORY )
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" )
add_subdirectory( ${SUBDIRECTORY} )
elseif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/branding.desc" )
calamares_add_branding( NAME ${SUBDIRECTORY} SUBDIRECTORY ${SUBDIRECTORY} )
if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" )
calamares_add_branding_translations( NAME ${SUBDIRECTORY} SUBDIRECTORY ${SUBDIRECTORY} )
endif() endif()
else() else()
message( "-- ${BoldYellow}Warning:${ColorReset} tried to add branding component subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no branding.desc." ) message( "-- ${BoldYellow}Warning:${ColorReset} tried to add branding component subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no branding.desc." )
message( "" )
endif() endif()
message( "" )
endfunction() endfunction()