This commit is contained in:
Andrei Astafev 2022-10-20 11:50:52 +03:00
parent 9fe572822c
commit 9f755b3bdb
10 changed files with 94 additions and 82 deletions

View File

@ -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()

View File

@ -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_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
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()

View File

@ -1,6 +1,6 @@
#[=======================================================================[.rst:
myx_add_library
---------------
myx_add_object_library
----------------------
Вспомогательная функция для создания объектной библиотеки::

View File

@ -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

View File

@ -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,7 +45,6 @@ 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
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
@ -51,7 +52,6 @@ function(myx_target_setup TARGET_NAME)
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
endif()
endif()
if(__target_type STREQUAL "EXECUTABLE")
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/include")
@ -74,25 +74,11 @@ 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 $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
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 $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
endif()
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})
else()
# CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY`
# информацию о заголовочных файлах. Это обход.
if(${CMAKE_VERSION} VERSION_GREATER "3.11.99")
@ -126,10 +112,9 @@ function(myx_target_setup TARGET_NAME)
endforeach()
endif()
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}

View File

@ -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 ).
## Использование

View File

@ -1 +1 @@
2.0.26
2.0.29

View File

@ -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

2
debian/changelog vendored
View File

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

View File

@ -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)