Обновления правил для формирования пакетов

This commit is contained in:
Andrei Astafev 2020-04-10 23:24:38 +03:00
parent 3ff1662e6c
commit d116e4db89
5 changed files with 84 additions and 13 deletions

25
CMLibCPack.cmake Normal file
View File

@ -0,0 +1,25 @@
# Общие настройки для пакета: организация, автор, версия
set(CPACK_PACKAGE_VENDOR ${CMLIB_ORGANIZATION_NAME_LOWER})
set(CPACK_PACKAGE_NAME ${CMLIB_PROJECT_NAME_LOWER})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
# Параметры для архива исходных текстов
set(CPACK_SOURCE_GENERATOR TXZ)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}-${CPACK_PACKAGE_VERSION}")
# Параметры для архива собранного проекта
set(CPACK_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CPACK_TARGET_ARCH "amd64")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}_${CPACK_TARGET_ARCH}_${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}-${CPACK_PACKAGE_VERSION}")
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_CURRENT_LIST_DIR}/CMLibCPackProject.cmake)
# Правила для сборки пакетов для Debian
include(CMLibCPackDeb)
# Подключение модуля, выполняющего сборку архивов и пакетов
include(CPack)

52
CMLibCPackDeb.cmake Normal file
View File

@ -0,0 +1,52 @@
# По умолчанию пакет собирается для дистрибутива unstable
if(NOT DEBIAN_PACKAGE_TYPE)
set(DEBIAN_PACKAGE_TYPE "unstable")
endif()
# По умолчанию пакет для Debian делится на компоненты
if(NOT CPACK_DEB_COMPONENT_INSTALL)
set(CPACK_DEB_COMPONENT_INSTALL ON)
endif()
# Если имя компонента по умолчанию не определено, то устанавливается MAIN
if(NOT CMAKE_INSTALL_DEFAULT_COMPONENT_NAME)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME MAIN)
endif()
# В списке компонентов обязательно должны быть MAIN и DEV
list(APPEND CPACK_COMPONENTS_ALL MAIN DEV)
list(REMOVE_DUPLICATES CPACK_COMPONENTS_ALL)
# Правило формирования имени пакета и файла для компонента MAIN
set(CPACK_DEBIAN_MAIN_PACKAGE_NAME "${CMLIB_PROJECT_NAME_LOWER}")
set(CPACK_DEBIAN_MAIN_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb")
# Правило формирования имени пакета и файла для остальных компонентов
foreach(C ${CPACK_COMPONENTS_ALL})
if(NOT "${C}" STREQUAL "MAIN")
string(TOLOWER "${C}" cl)
set(CPACK_DEBIAN_${C}_PACKAGE_NAME "${CMLIB_PROJECT_NAME_LOWER}-${cl}")
set(CPACK_DEBIAN_${C}_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}-${cl}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb")
endif()
endforeach()
# Если в каталоге ${CMAKE_SOURCE_DIR}/cmake/deb находятся сценарии сопровождающего
# postinst, preinst, postrm и prerm, то они будут добавлены к пакету.
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/preinst")
list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/preinst")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/postinst")
list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/postinst")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/prerm")
list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/prerm")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/postrm")
list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/postrm")
endif()
if(UNIX AND NOT TARGET deb)
add_custom_target(deb
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND cpack -G DEB)
endif()

6
CMLibCPackProject.cmake Normal file
View File

@ -0,0 +1,6 @@
if(CPACK_GENERATOR MATCHES "DEB")
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/${CPACK_PACKAGE_VENDOR}/${CPACK_PACKAGE_NAME}")
else()
set(CPACK_PACKAGING_INSTALL_PREFIX "${PROJECT_NAME}")
endif()

View File

@ -1,12 +0,0 @@
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR TXZ)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}-${CPACK_PACKAGE_VERSION}")
set(CPACK_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CPACK_TARGET_ARCH "amd64")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CMLIB_PROJECT_NAME_LOWER}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}")
include(CPack)
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)

View File

@ -45,5 +45,5 @@ include(CMLibQtTranslation)
include(CMLibToday)
include(CMLibAuxilarySymlinks)
include(CMLibConfigHPPGenerate)
include(CMLibCPackSources)
include(CMLibCPack)
include(CMLibUninstall)