CalamaresAddBrandingSubdirectory.cmake 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # Support macros for creating Calamares branding components.
  22. #
  23. # Calamares branding components have two parts:
  24. # - a branding.desc file that tells Calamares how to describe the product
  25. # (e.g. strings like "Generic GNU/Linux") and the name of a QML file
  26. # (the "slideshow") that is displayed during installation.
  27. # - the QML files themselves, plus supporting images etc.
  28. #
  29. # Branding components can be created inside the Calamares source tree
  30. # (there is one example the `default/` branding, which is also connected
  31. # to the default configuration shipped with Calamares), but they can be
  32. # built outside of, and largely independently of, Calamares by using
  33. # these CMake macros.
  34. #
  35. # See the calamares-examples repository for more examples.
  36. #
  37. include( CMakeParseArguments)
  38. include( CMakeColors )
  39. # Usage calamares_add_branding( <name> [DIRECTORY <dir>] [SUBDIRECTORIES <dir> ...])
  40. #
  41. # Adds a branding component to the build:
  42. # - the component's top-level files are copied into the build-dir;
  43. # CMakeLists.txt is excluded from the glob.
  44. # - the component's top-level files are installed into the component branding dir
  45. #
  46. # The branding component lives in <dir> if given, otherwise the
  47. # current source directory. The branding component is installed
  48. # with the given <name>, which is usually the name of the
  49. # directory containing the component, and which must match the
  50. # *componentName* in `branding.desc`.
  51. #
  52. # If SUBDIRECTORIES are given, then those are copied (each one level deep)
  53. # to the installation location as well, preserving the subdirectory name.
  54. function( calamares_add_branding NAME )
  55. cmake_parse_arguments( _CABT "" "DIRECTORY" "SUBDIRECTORIES" ${ARGN} )
  56. if (NOT _CABT_DIRECTORY)
  57. set(_CABT_DIRECTORY ".")
  58. endif()
  59. set( SUBDIRECTORY ${_CABT_DIRECTORY} )
  60. set( _brand_dir ${_CABT_DIRECTORY} )
  61. set( BRANDING_DIR share/calamares/branding )
  62. set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
  63. foreach( _subdir "" ${_CABT_SUBDIRECTORIES} )
  64. file( GLOB BRANDING_COMPONENT_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${_brand_dir} "${_brand_dir}/${_subdir}/*" )
  65. foreach( BRANDING_COMPONENT_FILE ${BRANDING_COMPONENT_FILES} )
  66. set( _subpath ${_brand_dir}/${BRANDING_COMPONENT_FILE} )
  67. if( NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_subpath} )
  68. configure_file( ${_subpath} ${_subpath} COPYONLY )
  69. install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_subpath}
  70. DESTINATION ${BRANDING_COMPONENT_DESTINATION}/${_subdir}/ )
  71. endif()
  72. endforeach()
  73. endforeach()
  74. message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} branding component: ${BoldRed}${NAME}${ColorReset}" )
  75. message( " ${Green}TYPE:${ColorReset} branding component" )
  76. message( " ${Green}BRANDING_COMPONENT_DESTINATION:${ColorReset} ${BRANDING_COMPONENT_DESTINATION}" )
  77. endfunction()
  78. # Usage calamares_add_branding_translations( <name> [DIRECTORY <dir>])
  79. #
  80. # Adds the translations for a branding component to the build:
  81. # - the component's lang/ directory is scanned for .ts files
  82. # - the component's translations are installed into the component branding dir
  83. #
  84. # Translation files must be called calamares-<name>_<lang>.ts . Optionally
  85. # the lang/ dir is found in the given <dir> instead of the current source
  86. # directory.
  87. function( calamares_add_branding_translations NAME )
  88. cmake_parse_arguments( _CABT "" "DIRECTORY" "" ${ARGN} )
  89. if (NOT _CABT_DIRECTORY)
  90. set(_CABT_DIRECTORY ".")
  91. endif()
  92. set( SUBDIRECTORY ${_CABT_DIRECTORY} )
  93. set( _brand_dir ${_CABT_DIRECTORY} )
  94. set( BRANDING_DIR share/calamares/branding )
  95. set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
  96. file( GLOB BRANDING_TRANSLATION_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIRECTORY}/lang/calamares-${NAME}_*.ts" )
  97. if ( BRANDING_TRANSLATION_FILES )
  98. qt5_add_translation( QM_FILES ${BRANDING_TRANSLATION_FILES} )
  99. add_custom_target( branding-translation-${NAME} ALL DEPENDS ${QM_FILES}
  100. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/lang/
  101. COMMAND ${CMAKE_COMMAND} -E copy ${QM_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/lang/
  102. )
  103. install( FILES ${QM_FILES} DESTINATION ${BRANDING_COMPONENT_DESTINATION}/lang/ )
  104. list( LENGTH BRANDING_TRANSLATION_FILES _branding_count )
  105. message( " ${Green}BRANDING_TRANSLATIONS:${ColorReset} ${_branding_count} language(s)" )
  106. endif()
  107. endfunction()
  108. # Usage calamares_add_branding_subdirectory( <dir> [NAME <name>] [SUBDIRECTORIES <dir> ...])
  109. #
  110. # Adds a branding component from a subdirectory:
  111. # - if there is a CMakeLists.txt, use that (that CMakeLists.txt should
  112. # call suitable calamares_add_branding() and other macros to install
  113. # the branding component).
  114. # - otherwise assume a "standard" setup with top-level files and a lang/
  115. # subdirectory for translations.
  116. #
  117. # If NAME is given, this is used instead of <dir> as the name of
  118. # the branding component. This is needed if <dir> is more than
  119. # one level deep, or to rename a component as it gets installed.
  120. #
  121. # If SUBDIRECTORIES are given, they are relative to <dir>, and are
  122. # copied (one level deep) to the install location as well.
  123. function( calamares_add_branding_subdirectory SUBDIRECTORY )
  124. cmake_parse_arguments( _CABS "" "NAME" "SUBDIRECTORIES" ${ARGN} )
  125. if (NOT _CABS_NAME)
  126. set(_CABS_NAME "${SUBDIRECTORY}")
  127. endif()
  128. if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" )
  129. add_subdirectory( ${SUBDIRECTORY} )
  130. elseif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/branding.desc" )
  131. calamares_add_branding( ${_CABS_NAME} DIRECTORY ${SUBDIRECTORY} SUBDIRECTORIES ${_CABS_SUBDIRECTORIES} )
  132. if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" )
  133. calamares_add_branding_translations( ${_CABS_NAME} DIRECTORY ${SUBDIRECTORY} )
  134. endif()
  135. else()
  136. message( "-- ${BoldYellow}Warning:${ColorReset} tried to add branding component subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no branding.desc." )
  137. endif()
  138. message( "" )
  139. endfunction()