From 9f755b3bdbeeb60b44ff2212cde7bd1061ddb69c Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 20 Oct 2022 11:50:52 +0300 Subject: [PATCH] 2.0.29 --- MyxCMake/MyxCMakeConfigVersion.cmake | 2 +- MyxCMake/lib/AddInterfaceLibrary.cmake | 66 +++++++++++++------ MyxCMake/lib/AddObjectLibrary.cmake | 4 +- MyxCMake/lib/CreatePackages.cmake | 3 +- MyxCMake/lib/TargetSetup.cmake | 89 +++++++++++--------------- README.md | 2 +- VERSION | 2 +- debian/CMakeLists.txt | 2 +- debian/changelog | 2 +- myx_setup.cmake | 4 +- 10 files changed, 94 insertions(+), 82 deletions(-) diff --git a/MyxCMake/MyxCMakeConfigVersion.cmake b/MyxCMake/MyxCMakeConfigVersion.cmake index ab208e0..74eef03 100644 --- a/MyxCMake/MyxCMakeConfigVersion.cmake +++ b/MyxCMake/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "2.0.26") +set(MYX_CMAKE_PACKAGE_VERSION "2.0.29") if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() diff --git a/MyxCMake/lib/AddInterfaceLibrary.cmake b/MyxCMake/lib/AddInterfaceLibrary.cmake index 8424706..6b80671 100644 --- a/MyxCMake/lib/AddInterfaceLibrary.cmake +++ b/MyxCMake/lib/AddInterfaceLibrary.cmake @@ -1,15 +1,18 @@ #[=======================================================================[.rst: -myx_add_library ---------------- +myx_add_interface_library +------------------------- -Вспомогательная функция для создания библиотеки:: +Вспомогательная функция для создания интерфейсной библиотеки:: - myx_add_library(TARGET_NAME TARGET_TYPE + myx_add_interface_library(TARGET_NAME + [ PACKAGES packages ] | + [ LINK_LIBRARIES link_libraries ] | [ OUTPUT_NAME output_name ] | [ EXPORT_FILE_NAME file_name ] | - [ EXPORT_BASE_NAME base_name ]) + [ EXPORT_BASE_NAME base_name ] | + [ HEADERS headers ]) -Обязательные параметры: `TARGET_NAME` - имя библиотеки и `TARGET_TYPE` - тип цели. +Обязательные параметры: `TARGET_NAME` - имя библиотеки. Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов. Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных. @@ -31,9 +34,13 @@ function(myx_add_interface_library TARGET_NAME) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DIR_BACKPORT}) endif() + if(TARGET ${TARGET_NAME}) + myx_message_fatal_error("Target ${TARGET_NAME} already exists") + endif() + set(options) set(oneValueArgs OUTPUT_NAME) - set(multiValueArgs) + set(multiValueArgs HEADERS LINK_LIBRARIES PACKAGES) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(NOT ARG_OUTPUT_NAME) @@ -41,7 +48,30 @@ function(myx_add_interface_library TARGET_NAME) endif() # Вызов стандартной функции `add_library()` - add_library(${TARGET_NAME} INTERFACE ${ARG_UNPARSED_ARGUMENTS}) + if(${CMAKE_VERSION} VERSION_LESS "3.13.0") + add_library(${TARGET_NAME} INTERFACE) + # TODO +# target_sources(${TARGET_NAME} INTERFACE ${ARG_HEADERS}) + else() + add_library(${TARGET_NAME} INTERFACE ${ARG_HEADERS}) + endif() + + foreach(__iter ${ARG_PACKAGES}) + target_include_directories(${TARGET_NAME} INTERFACE ${${__iter}_INCLUDE_DIRS}) + target_compile_definitions(${TARGET_NAME} INTERFACE ${${__iter}_COMPILE_DEFINITIONS}) + endforeach() + + if(ARG_LINK_LIBRARIES) + target_link_libraries(${TARGET_NAME} INTERFACE ${ARG_LINK_LIBRARIES}) + foreach(__lib ${ARG_LINK_LIBRARIES}) + if(TARGET ${__lib}) + install( + TARGETS ${__lib} + EXPORT ${TARGET_NAME}Targets + COMPONENT DEV) + endif() + endforeach() + endif() # Библиотека, состоящая только из заголовочных файлов не требует сборки. # Стандартные пути к заголовочным файлам @@ -75,16 +105,14 @@ function(myx_add_interface_library TARGET_NAME) install(EXPORT ${TARGET_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME} - COMPONENT DEV - ) + COMPONENT DEV) install( FILES ${PROJECT_BINARY_DIR}/${TARGET_NAME}ConfigVersion.cmake ${PROJECT_BINARY_DIR}/${TARGET_NAME}Config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME} - COMPONENT DEV - ) + COMPONENT DEV) # Формирование файла для pkg-config file(WRITE "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc" @@ -102,23 +130,21 @@ function(myx_add_interface_library TARGET_NAME) # Установка файла для pkg-config install( FILES "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc" - COMPONENT DEV - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + COMPONENT DEV) # Установка библиотеки из заголовочных файлов target_include_directories(${TARGET_NAME} SYSTEM INTERFACE $) install( TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME}Targets - COMPONENT LIB - ) + COMPONENT DEV) # Установка публичных заголовочных файлов - if(PROJECT_IS_TOP_LEVEL) + if(PROJECT_IS_TOP_LEVEL AND ARG_HEADERS) myx_install_relative(${PROJECT_SOURCE_DIR} - FILES ${ARG_UNPARSED_ARGUMENTS} + FILES ${ARG_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX} - COMPONENT DEV - ) + COMPONENT DEV) endif() endfunction() diff --git a/MyxCMake/lib/AddObjectLibrary.cmake b/MyxCMake/lib/AddObjectLibrary.cmake index 9c30954..2fc2443 100644 --- a/MyxCMake/lib/AddObjectLibrary.cmake +++ b/MyxCMake/lib/AddObjectLibrary.cmake @@ -1,6 +1,6 @@ #[=======================================================================[.rst: -myx_add_library ---------------- +myx_add_object_library +---------------------- Вспомогательная функция для создания объектной библиотеки:: diff --git a/MyxCMake/lib/CreatePackages.cmake b/MyxCMake/lib/CreatePackages.cmake index 4470f5d..23ba112 100644 --- a/MyxCMake/lib/CreatePackages.cmake +++ b/MyxCMake/lib/CreatePackages.cmake @@ -129,7 +129,8 @@ function(myx_create_packages TARGET_NAME) # В списке компонентов обязательно должны быть main, lib, dev, static и doc #list(APPEND CPACK_COMPONENTS_ALL main lib dev static doc) - list(REMOVE_DUPLICATES CPACK_COMPONENTS_ALL) + # TODO + #list(REMOVE_DUPLICATES CPACK_COMPONENTS_ALL) set(deb_arch_suffix "${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb") # Правило формирования имени пакета и файла для компонента main diff --git a/MyxCMake/lib/TargetSetup.cmake b/MyxCMake/lib/TargetSetup.cmake index bab4f22..31c6d12 100644 --- a/MyxCMake/lib/TargetSetup.cmake +++ b/MyxCMake/lib/TargetSetup.cmake @@ -12,12 +12,14 @@ function(myx_target_setup TARGET_NAME) endif() get_target_property(__target_type ${TARGET_NAME} TYPE) + if(${__target_type} STREQUAL "INTERFACE_LIBRARY") + myx_message_fatal_error("This function will not work for interface targets.") + endif() foreach(iter ${ARG_PACKAGES}) target_include_directories(${TARGET_NAME} PRIVATE ${${iter}_INCLUDE_DIRS}) target_compile_definitions(${TARGET_NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS}) endforeach() - target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS}) if(ARG_CPP) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY CPP_FILES ${ARG_CPP}) @@ -43,14 +45,12 @@ function(myx_target_setup TARGET_NAME) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}") endif() - if(NOT __target_type STREQUAL "INTERFACE_LIBRARY") - target_include_directories(${PROJECT_NAME} PRIVATE - $) + target_include_directories(${PROJECT_NAME} PRIVATE + $) - if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src") - target_include_directories(${PROJECT_NAME} PRIVATE - $) - endif() + if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src") + target_include_directories(${PROJECT_NAME} PRIVATE + $) endif() if(__target_type STREQUAL "EXECUTABLE") @@ -74,62 +74,47 @@ function(myx_target_setup TARGET_NAME) install(TARGETS ${TARGET_NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - if(NOT ${__target_type} STREQUAL "INTERFACE_LIBRARY") - target_sources(${TARGET_NAME} PUBLIC $) - target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS}) - target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS}) - target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS}) - endif() + target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS}) + target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS}) + target_sources(${TARGET_NAME} PUBLIC $) + target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS}) - if(${__target_type} STREQUAL "INTERFACE_LIBRARY") - foreach(__lib ${ARG_LINK_LIBRARIES}) - if(TARGET ${__lib}) - install( - TARGETS ${__lib} - EXPORT ${TARGET_NAME}Targets - COMPONENT LIB - ) - endif() - endforeach() - target_link_libraries(${TARGET_NAME} INTERFACE ${ARG_LINK_LIBRARIES}) + # CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY` + # информацию о заголовочных файлах. Это обход. + if(${CMAKE_VERSION} VERSION_GREATER "3.11.99") + target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES}) else() - # CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY` - # информацию о заголовочных файлах. Это обход. - if(${CMAKE_VERSION} VERSION_GREATER "3.11.99") + if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND + (NOT ${__target_type} STREQUAL "EXECUTABLE")) target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES}) else() - if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND - (NOT ${__target_type} STREQUAL "EXECUTABLE")) - target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES}) - else() - foreach(__link_library ${ARG_LINK_LIBRARIES}) - if(TARGET ${__link_library}) - get_target_property(__lib_type ${__link_library} TYPE) - if(__lib_type) - get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES) - if(__include_dirs) - target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs}) - endif() - if(${__target_type} STREQUAL "EXECUTABLE") - if(${__lib_type} STREQUAL "OBJECT_LIBRARY") - if(TARGET ${__link_library}_static) - target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_static) - else() - target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_shared) - endif() + foreach(__link_library ${ARG_LINK_LIBRARIES}) + if(TARGET ${__link_library}) + get_target_property(__lib_type ${__link_library} TYPE) + if(__lib_type) + get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES) + if(__include_dirs) + target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs}) + endif() + if(${__target_type} STREQUAL "EXECUTABLE") + if(${__lib_type} STREQUAL "OBJECT_LIBRARY") + if(TARGET ${__link_library}_static) + target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_static) else() - target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}) - endif() + target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_shared) + endif() + else() + target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}) endif() endif() endif() - endforeach() - endif() + endif() + endforeach() endif() endif() # Установка публичных заголовочных файлов - if(PROJECT_IS_TOP_LEVEL) + if(PROJECT_IS_TOP_LEVEL AND ARG_PUBLIC_HEADERS) myx_install_relative(${PROJECT_SOURCE_DIR} FILES ${ARG_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX} diff --git a/README.md b/README.md index 39199da..ee4a2a3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Установка В корневом каталоге проекта создать каталог `cmake` и распаковать в него -[архив](../../../releases/download/2.0.26/myx-cmake-local-2.0.26.tar.xz ). +[архив](../../../releases/download/2.0.29/myx-cmake-local-2.0.29.tar.xz ). ## Использование diff --git a/VERSION b/VERSION index f6ee962..3df5a46 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.26 +2.0.29 diff --git a/debian/CMakeLists.txt b/debian/CMakeLists.txt index 720f013..a07ddbe 100644 --- a/debian/CMakeLists.txt +++ b/debian/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.6 FATAL_ERROR) -project(myx-cmake VERSION 2.0.26 LANGUAGES) +project(myx-cmake VERSION 2.0.29 LANGUAGES) include(GNUInstallDirs) file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake diff --git a/debian/changelog b/debian/changelog index 0f771ff..618701b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -myx-cmake (2.0.26) unstable; urgency=medium +myx-cmake (2.0.29) unstable; urgency=medium * New version. diff --git a/myx_setup.cmake b/myx_setup.cmake index 3270fd9..056a310 100644 --- a/myx_setup.cmake +++ b/myx_setup.cmake @@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR}) set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR}) endif() if(MYX_CMAKE_DIR) - find_package(MyxCMake 2.0.26 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) + find_package(MyxCMake 2.0.29 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") else() if(MYX_CMAKE_USE_SYSTEM) - find_package(MyxCMake 2.0.26 REQUIRED) + find_package(MyxCMake 2.0.29 REQUIRED) myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)