This commit is contained in:
Andrei Astafev 2022-10-09 04:23:55 +03:00
parent d8713fa8a6
commit 703b8045ed
12 changed files with 198 additions and 17 deletions

View File

@ -59,6 +59,7 @@ include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/PrivateConfigHeader.cmake) include(${MYX_CMAKE_LIB_DIR}/generators/PrivateConfigHeader.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/GitInfoHeader.cmake) include(${MYX_CMAKE_LIB_DIR}/generators/GitInfoHeader.cmake)
include(${MYX_CMAKE_LIB_DIR}/CreatePackages.cmake)
include(${MYX_CMAKE_LIB_DIR}/Uninstall.cmake) include(${MYX_CMAKE_LIB_DIR}/Uninstall.cmake)
unset(MYX_CMAKE_SOURCE_DIR) unset(MYX_CMAKE_SOURCE_DIR)

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "2.0.16") set(MYX_CMAKE_PACKAGE_VERSION "2.0.17")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE) set(PACKAGE_VERSION_COMPATIBLE FALSE)
else() else()

View File

@ -148,7 +148,7 @@ function(myx_add_library NAME TYPE)
install(EXPORT ${NAME}Targets install(EXPORT ${NAME}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME}
COMPONENT dev COMPONENT DEV
) )
install( install(
@ -156,7 +156,7 @@ function(myx_add_library NAME TYPE)
${PROJECT_BINARY_DIR}/${NAME}ConfigVersion.cmake ${PROJECT_BINARY_DIR}/${NAME}ConfigVersion.cmake
${PROJECT_BINARY_DIR}/${NAME}Config.cmake ${PROJECT_BINARY_DIR}/${NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME}
COMPONENT dev COMPONENT DEV
) )
# Формирование файла для pkg-config # Формирование файла для pkg-config
@ -187,7 +187,7 @@ function(myx_add_library NAME TYPE)
# Установка файла для pkg-config # Установка файла для pkg-config
install( install(
FILES "${PROJECT_BINARY_DIR}/${NAME}.pc" FILES "${PROJECT_BINARY_DIR}/${NAME}.pc"
COMPONENT dev COMPONENT DEV
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if(TYPE STREQUAL "OBJECT") if(TYPE STREQUAL "OBJECT")
@ -197,7 +197,7 @@ function(myx_add_library NAME TYPE)
TARGETS ${NAME}_shared TARGETS ${NAME}_shared
EXPORT ${NAME}Targets EXPORT ${NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT lib COMPONENT LIB
) )
endif() endif()
@ -207,7 +207,7 @@ function(myx_add_library NAME TYPE)
TARGETS ${NAME}_static TARGETS ${NAME}_static
EXPORT ${NAME}Targets EXPORT ${NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT static COMPONENT STATIC
) )
endif() endif()
endif() endif()
@ -218,7 +218,7 @@ function(myx_add_library NAME TYPE)
install( install(
TARGETS ${NAME} TARGETS ${NAME}
EXPORT ${NAME}Targets EXPORT ${NAME}Targets
COMPONENT lib COMPONENT LIB
) )
endif() endif()
endfunction() endfunction()

View File

@ -0,0 +1,180 @@
include_guard(GLOBAL)
function(myx_create_packages NAME)
set(options)
set(oneValueArgs DEBIAN_PACKAGE_TYPE CPACK_DEBIAN_PACKAGE_SECTION CPACK_DEBIAN_PACKAGE_PRIORITY
CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CPACK_PACKAGE_CONTACT)
set(multiValueArgs CPACK_SOURCE_GENERATOR CPACK_GENERATOR CPACK_SOURCE_IGNORE_FILES
CPACK_PACKAGING_INSTALL_PREFIX)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Общие настройки для пакета: организация, автор, версия
if(NOT ${PROJECT_NAME}_VENDOR)
set(CPACK_PACKAGE_VENDOR "unknown vendor")
myx_message_warning("\${PROJECT_NAME}_VENDOR variable is required for packaging but unset")
else()
set(CPACK_PACKAGE_VENDOR ${${PROJECT_NAME}_VENDOR})
endif()
if(NOT ${PROJECT_NAME}_CONTACT)
set(CPACK_PACKAGE_CONTACT "unknown maintainer")
myx_message_warning("\${PROJECT_NAME}_CONTACT variable is required for packaging but unset")
else()
set(CPACK_PACKAGE_CONTACT ${${PROJECT_NAME}_CONTACT})
endif()
string(TOLOWER ${PROJECT_NAME} PN)
set(CPACK_PACKAGE_NAME ${PN})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
# Параметры для архива исходных текстов
if(NOT ARG_CPACK_SOURCE_GENERATOR)
set(CPACK_SOURCE_GENERATOR "TXZ")
else()
set(ARG_CPACK_SOURCE_GENERATOR ${CPACK_SOURCE_GENERATOR})
endif()
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PN}-${CPACK_PACKAGE_VERSION}")
# Типы генераторов для бинарных архивов
if(NOT ARG_CPACK_GENERATOR)
set(CPACK_GENERATOR "TXZ" "DEB")
else()
set(CPACK_GENERATOR ${ARG_CPACK_GENERATOR})
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
list(REMOVE_ITEM CPACK_GENERATOR "DEB")
endif()
# Параметры для архива собранного проекта
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 "${PN}_${CPACK_PACKAGE_VERSION}")
# Список масок для исключения из архива исходных текстов
set(CPACK_SOURCE_IGNORE_FILES
${ARG_CPACK_SOURCE_IGNORE_FILES}
${CMAKE_BINARY_DIR}
"^${CMAKE_SOURCE_DIR}/.?build.?/"
"^${CMAKE_SOURCE_DIR}/.?output.?/"
"^${CMAKE_SOURCE_DIR}/files/var"
"^${CMAKE_SOURCE_DIR}/files/log"
"CMakeLists.txt.user.*"
".*.autosave"
".*.status"
"~$"
"\\\\.swp$")
option(MYX_COMPACT_SOURCE_PACKAGE "Make compact source package" ON)
if(MYX_COMPACT_SOURCE_PACKAGE)
# Список масок для исключения из архива исходных текстов для более компактного архива
set(CPACK_SOURCE_IGNORE_FILES
${CPACK_SOURCE_IGNORE_FILES}
"\\\\.git"
"/\\\\.git/"
"/\\\\.gitlab-ci/"
"\\\\.clang-tidy$"
"\\\\.cmake-format$"
"\\\\.gitignore$"
"\\\\.gitattributes$"
"\\\\.gitmodules$"
"\\\\.gitlab-ci.yml$")
endif()
if("TXZ" IN_LIST CPACK_GENERATOR)
set(CPACK_ARCHIVE_COMPONENT_INSTALL OFF)
set(CPACK_ARCHIVE_FILE_NAME "${PN}_${CPACK_TARGET_ARCH}_${CPACK_PACKAGE_VERSION}")
endif()
if("DEB" IN_LIST CPACK_GENERATOR)
set(CPACK_DEB_MONOLITHIC_INSTALL OFF)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
# По умолчанию пакет собирается для дистрибутива unstable
if(NOT ARG_DEBIAN_PACKAGE_TYPE)
set(DEBIAN_PACKAGE_TYPE "unstable")
endif()
if(NOT ARG_CPACK_DEBIAN_PACKAGE_SECTION)
set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
endif()
if(NOT ARG_CPACK_DEBIAN_PACKAGE_PRIORITY)
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
endif()
# По умолчанию пакет для Debian делится на компоненты
if(NOT ARG_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, lib, dev, static и doc
#list(APPEND CPACK_COMPONENTS_ALL main lib dev static doc)
list(REMOVE_DUPLICATES CPACK_COMPONENTS_ALL)
set(deb_arch_suffix "${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb")
# Правило формирования имени пакета и файла для компонента main
set(CPACK_DEBIAN_MAIN_PACKAGE_NAME "${PN}")
set(CPACK_DEBIAN_MAIN_FILE_NAME ${CPACK_DEBIAN_MAIN_PACKAGE_NAME}_${deb_arch_suffix})
# Правило формирования имени пакета и файла для компонента lib
set(CPACK_DEBIAN_LIB_PACKAGE_NAME "lib${PN}${PROJECT_VERSION_MAJOR}")
set(CPACK_DEBIAN_LIB_FILE_NAME ${CPACK_DEBIAN_LIB_PACKAGE_NAME}_${deb_arch_suffix})
# Правило формирования имени пакета и файла для компонента dev
set(CPACK_DEBIAN_DEV_PACKAGE_NAME "lib${PN}-dev")
set(CPACK_DEBIAN_DEV_FILE_NAME ${CPACK_DEBIAN_DEV_PACKAGE_NAME}_${deb_arch_suffix})
# Правило формирования имени пакета и файла для компонента static
set(CPACK_DEBIAN_STATIC_PACKAGE_NAME "lib${PN}${PROJECT_VERSION_MAJOR}-static-dev")
set(CPACK_DEBIAN_STATIC_FILE_NAME ${CPACK_DEBIAN_STATIC_PACKAGE_NAME}_${deb_arch_suffix})
set(CPACK_DEBIAN_STATIC_PACKAGE_DEPENDS "lib${PN}-dev")
# Правило формирования имени пакета и файла для компонента doc
set(CPACK_DEBIAN_DOC_PACKAGE_NAME "${PN}-doc")
set(CPACK_DEBIAN_DOC_FILE_NAME ${PN}-doc_${CPACK_PACKAGE_VERSION}_all.deb)
foreach(iter ${CPACK_COMPONENTS_ALL})
string(TOLOWER ${iter} _cl)
string(TOUPPER ${iter} _cu)
# Правила формирования имени пакета и файла для остальных компонентов
if((NOT ${_cu} STREQUAL MAIN) AND
(NOT ${_cu} STREQUAL LIB) AND
(NOT ${_cu} STREQUAL DEV) AND
(NOT ${_cu} STREQUAL STATIC) AND
(NOT ${_cu} STREQUAL DOC))
set(CPACK_DEBIAN_${_cu}_PACKAGE_NAME "${PN}-${_cl}")
set(CPACK_DEBIAN_${_cu}_FILE_NAME "${CPACK_DEBIAN_${_cu}_PACKAGE_NAME}_${deb_arch_suffix}")
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()
if(UNIX AND NOT TARGET deb)
add_custom_target(deb WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cpack -G DEB)
add_dependencies(deb ${NAME})
endif()
endif()
# Подключение модуля, выполняющего сборку архивов и пакетов
include(CPack)
endfunction(myx_create_packages NAME)

View File

@ -94,7 +94,7 @@ function(myx_qt5_target_setup NAME)
myx_install_relative(${PROJECT_SOURCE_DIR} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_MOC} FILES ${ARG_PUBLIC_MOC}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT dev COMPONENT DEV
) )
endif() endif()
endfunction() endfunction()

View File

@ -70,7 +70,7 @@ function(myx_target_setup NAME)
if(CMAKE_CXX_COMPILE_OPTIONS_PIE) if(CMAKE_CXX_COMPILE_OPTIONS_PIE)
target_compile_options(${NAME} PUBLIC ${CMAKE_CXX_COMPILE_OPTIONS_PIE}) target_compile_options(${NAME} PUBLIC ${CMAKE_CXX_COMPILE_OPTIONS_PIE})
endif() endif()
install(TARGETS ${NAME} COMPONENT main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS ${NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()
if(${target_type} STREQUAL "INTERFACE_LIBRARY") if(${target_type} STREQUAL "INTERFACE_LIBRARY")
@ -123,7 +123,7 @@ function(myx_target_setup NAME)
myx_install_relative(${PROJECT_SOURCE_DIR} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_HEADERS} ${ARG_INTERFACE_HEADERS} FILES ${ARG_PUBLIC_HEADERS} ${ARG_INTERFACE_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT dev COMPONENT DEV
) )
endif() endif()
endfunction() endfunction()

View File

@ -63,7 +63,7 @@ function(myx_doc_doxygen NAME)
COMMENT "Generating API documentation with Doxygen") COMMENT "Generating API documentation with Doxygen")
if(ARG_HTML) if(ARG_HTML)
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/doxygen/html/ install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/doxygen/html/
COMPONENT doc OPTIONAL COMPONENT DOC OPTIONAL
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/doxygen) DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/doxygen)
endif() endif()
if(NOT TARGET myx-doc-doxygen) if(NOT TARGET myx-doc-doxygen)

View File

@ -3,7 +3,7 @@
## Установка ## Установка
В корневом каталоге проекта создать каталог `cmake` и распаковать в него В корневом каталоге проекта создать каталог `cmake` и распаковать в него
[архив](../../../releases/download/2.0.16/myx-cmake-local-2.0.16.tar.xz ). [архив](../../../releases/download/2.0.17/myx-cmake-local-2.0.17.tar.xz ).
## Использование ## Использование

View File

@ -1 +1 @@
2.0.16 2.0.17

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.6 FATAL_ERROR) cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(myx-cmake VERSION 2.0.16 LANGUAGES) project(myx-cmake VERSION 2.0.17 LANGUAGES)
include(GNUInstallDirs) include(GNUInstallDirs)
file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
myx-cmake (2.0.16) unstable; urgency=medium myx-cmake (2.0.17) unstable; urgency=medium
* New version. * New version.

View File

@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR})
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR}) set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
endif() endif()
if(MYX_CMAKE_DIR) if(MYX_CMAKE_DIR)
find_package(MyxCMake 2.0.16 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) find_package(MyxCMake 2.0.17 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else() else()
if(MYX_CMAKE_USE_SYSTEM) if(MYX_CMAKE_USE_SYSTEM)
find_package(MyxCMake 2.0.16 REQUIRED) find_package(MyxCMake 2.0.17 REQUIRED)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else() else()
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake) include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)