myx-cmake/MyxCMake/modules/MyxCMakeCPackDeb.cmake

81 lines
4.0 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# По умолчанию пакет собирается для дистрибутива unstable
if(NOT DEBIAN_PACKAGE_TYPE)
set(DEBIAN_PACKAGE_TYPE "unstable")
endif()
if(NOT CPACK_DEBIAN_PACKAGE_SECTION)
set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
endif()
if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
endif()
# По умолчанию пакет для Debian делится на компоненты
if(NOT CPACK_DEB_COMPONENT_INSTALL)
set(CPACK_DEB_COMPONENT_INSTALL ON)
endif()
if(MYX_CMAKE_CPACK_DEFAULT_SCHEME)
# Если имя компонента по умолчанию не определено, то устанавливается MAIN
if(NOT CMAKE_INSTALL_DEFAULT_COMPONENT_NAME)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME main)
endif()
# В списке компонентов обязательно должны быть main, dev, static и doc
list(APPEND CPACK_COMPONENTS_ALL main dev static doc)
list(REMOVE_DUPLICATES CPACK_COMPONENTS_ALL)
# Правило формирования имени пакета и файла для компонента main
set(CPACK_DEBIAN_MAIN_PACKAGE_NAME "${MYX_CMAKE_PROJECT_NAME_LOWER}")
set(CPACK_DEBIAN_MAIN_FILE_NAME
${MYX_CMAKE_PROJECT_NAME_LOWER}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb)
# Правило формирования имени пакета и файла для компонента dev
set(CPACK_DEBIAN_DEV_PACKAGE_NAME "lib${MYX_CMAKE_PROJECT_NAME_LOWER}-dev")
set(CPACK_DEBIAN_DEV_FILE_NAME
lib${MYX_CMAKE_PROJECT_NAME_LOWER}-dev_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb)
# Правило формирования имени пакета и файла для компонента static
set(CPACK_DEBIAN_STATIC_PACKAGE_NAME "lib${MYX_CMAKE_PROJECT_NAME_LOWER}-static-dev")
set(CPACK_DEBIAN_STATIC_FILE_NAME
lib${MYX_CMAKE_PROJECT_NAME_LOWER}-static-dev_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb)
set(CPACK_DEBIAN_STATIC_PACKAGE_DEPENDS "lib${MYX_CMAKE_PROJECT_NAME_LOWER}-dev")
# Правило формирования имени пакета и файла для компонента doc
set(CPACK_DEBIAN_DOC_PACKAGE_NAME "${MYX_CMAKE_PROJECT_NAME_LOWER}-doc")
set(CPACK_DEBIAN_DOC_FILE_NAME
${MYX_CMAKE_PROJECT_NAME_LOWER}-doc_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb)
foreach(component ${CPACK_COMPONENTS_ALL})
string(TOLOWER ${component} _cl)
string(TOUPPER ${component} _cu)
# Правила формирования имени пакета и файла для остальных компонентов
if(NOT ${_cl} STREQUAL main AND NOT ${_cl} STREQUAL dev AND NOT ${_cl} STREQUAL static)
set(CPACK_DEBIAN_${_cu}_PACKAGE_NAME "${MYX_CMAKE_PROJECT_NAME_LOWER}-${_cl}")
set(CPACK_DEBIAN_${_cu}_FILE_NAME
"${MYX_CMAKE_PROJECT_NAME_LOWER}-${_cl}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb")
endif()
# Если в каталоге ${CMAKE_SOURCE_DIR}/cmake/deb/${_cl} находятся сценарии сопровождающего
# postinst, preinst, postrm и prerm, то они будут добавлены к пакету.
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/preinst")
list(APPEND CPACK_DEBIAN_${_cu}_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/preinst")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/postinst")
list(APPEND CPACK_DEBIAN_${_cu}_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/postinst")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/prerm")
list(APPEND CPACK_DEBIAN_${_cu}_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/prerm")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/postrm")
list(APPEND CPACK_DEBIAN_${_cu}_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/deb/${_cl}/postrm")
endif()
endforeach()
endif()
if(UNIX AND NOT TARGET deb)
add_custom_target(deb WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cpack -G DEB)
endif()