Compare commits

...

3 Commits

Author SHA1 Message Date
1c504e2328 2.0.31 2022-10-20 12:48:52 +03:00
e80b8d4a02 2.0.30 2022-10-20 12:45:27 +03:00
9f755b3bdb 2.0.29 2022-10-20 11:50:52 +03:00
13 changed files with 113 additions and 92 deletions

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "2.0.26") set(MYX_CMAKE_PACKAGE_VERSION "2.0.30")
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

@ -1,15 +1,18 @@
#[=======================================================================[.rst: #[=======================================================================[.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 ] | [ OUTPUT_NAME output_name ] |
[ EXPORT_FILE_NAME file_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` определяет базовое имя выходных файлов. Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов.
Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых
переменных, а `EXPORT_BASE_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}) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DIR_BACKPORT})
endif() endif()
if(TARGET ${TARGET_NAME})
myx_message_fatal_error("Target ${TARGET_NAME} already exists")
endif()
set(options) set(options)
set(oneValueArgs OUTPUT_NAME) set(oneValueArgs OUTPUT_NAME)
set(multiValueArgs) set(multiValueArgs HEADERS LINK_LIBRARIES PACKAGES)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_OUTPUT_NAME) if(NOT ARG_OUTPUT_NAME)
@ -41,7 +48,31 @@ function(myx_add_interface_library TARGET_NAME)
endif() endif()
# Вызов стандартной функции `add_library()` # Вызов стандартной функции `add_library()`
add_library(${TARGET_NAME} INTERFACE ${ARG_UNPARSED_ARGUMENTS}) if(${CMAKE_VERSION} VERSION_LESS "3.19.0")
add_library(${TARGET_NAME} INTERFACE)
target_sources(${TARGET_NAME} INTERFACE $<BUILD_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})
if(${CMAKE_VERSION} VERSION_GREATER "3.15.0")
foreach(__lib ${ARG_LINK_LIBRARIES})
if(TARGET ${__lib})
install(
TARGETS ${__lib}
EXPORT ${TARGET_NAME}Targets
COMPONENT DEV)
endif()
endforeach()
endif()
endif()
# Библиотека, состоящая только из заголовочных файлов не требует сборки. # Библиотека, состоящая только из заголовочных файлов не требует сборки.
# Стандартные пути к заголовочным файлам # Стандартные пути к заголовочным файлам
@ -75,16 +106,14 @@ function(myx_add_interface_library TARGET_NAME)
install(EXPORT ${TARGET_NAME}Targets install(EXPORT ${TARGET_NAME}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
COMPONENT DEV COMPONENT DEV)
)
install( install(
FILES FILES
${PROJECT_BINARY_DIR}/${TARGET_NAME}ConfigVersion.cmake ${PROJECT_BINARY_DIR}/${TARGET_NAME}ConfigVersion.cmake
${PROJECT_BINARY_DIR}/${TARGET_NAME}Config.cmake ${PROJECT_BINARY_DIR}/${TARGET_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
COMPONENT DEV COMPONENT DEV)
)
# Формирование файла для pkg-config # Формирование файла для pkg-config
file(WRITE "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc" file(WRITE "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
@ -102,23 +131,21 @@ function(myx_add_interface_library TARGET_NAME)
# Установка файла для pkg-config # Установка файла для pkg-config
install( install(
FILES "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc" 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}>) target_include_directories(${TARGET_NAME} SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install( install(
TARGETS ${TARGET_NAME} TARGETS ${TARGET_NAME}
EXPORT ${TARGET_NAME}Targets 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} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_UNPARSED_ARGUMENTS} FILES ${ARG_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT DEV COMPONENT DEV)
)
endif() endif()
endfunction() endfunction()

View File

@ -1,6 +1,6 @@
#[=======================================================================[.rst: #[=======================================================================[.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 # В списке компонентов обязательно должны быть main, lib, dev, static и doc
#list(APPEND CPACK_COMPONENTS_ALL 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") set(deb_arch_suffix "${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}.deb")
# Правило формирования имени пакета и файла для компонента main # Правило формирования имени пакета и файла для компонента main

View File

@ -87,7 +87,11 @@ function(myx_qt5_target_setup TARGET_NAME)
target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n}) target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n})
endif() endif()
unset(tr) unset(tr)
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp}) if(target_type STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
else()
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
endif()
# Установка публичных заголовочных файлов # Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL) if(PROJECT_IS_TOP_LEVEL)

View File

@ -12,12 +12,14 @@ function(myx_target_setup TARGET_NAME)
endif() endif()
get_target_property(__target_type ${TARGET_NAME} TYPE) 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}) foreach(iter ${ARG_PACKAGES})
target_include_directories(${TARGET_NAME} PRIVATE ${${iter}_INCLUDE_DIRS}) target_include_directories(${TARGET_NAME} PRIVATE ${${iter}_INCLUDE_DIRS})
target_compile_definitions(${TARGET_NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS}) target_compile_definitions(${TARGET_NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS})
endforeach() endforeach()
target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
if(ARG_CPP) if(ARG_CPP)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY CPP_FILES ${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}") set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}")
endif() endif()
if(NOT __target_type STREQUAL "INTERFACE_LIBRARY") target_include_directories(${PROJECT_NAME} PRIVATE
target_include_directories(${PROJECT_NAME} PRIVATE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src") if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src")
target_include_directories(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
endif()
endif() endif()
if(__target_type STREQUAL "EXECUTABLE") 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}) install(TARGETS ${TARGET_NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()
if(NOT ${__target_type} STREQUAL "INTERFACE_LIBRARY") target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
target_sources(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>) target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS})
target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS}) target_sources(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS}) target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
endif()
if(${__target_type} STREQUAL "INTERFACE_LIBRARY") # CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY`
foreach(__lib ${ARG_LINK_LIBRARIES}) # информацию о заголовочных файлах. Это обход.
if(TARGET ${__lib}) if(${CMAKE_VERSION} VERSION_GREATER "3.11.99")
install( target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
TARGETS ${__lib}
EXPORT ${TARGET_NAME}Targets
COMPONENT LIB
)
endif()
endforeach()
target_link_libraries(${TARGET_NAME} INTERFACE ${ARG_LINK_LIBRARIES})
else() else()
# CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY` if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND
# информацию о заголовочных файлах. Это обход. (NOT ${__target_type} STREQUAL "EXECUTABLE"))
if(${CMAKE_VERSION} VERSION_GREATER "3.11.99")
target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES}) target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
else() else()
if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND foreach(__link_library ${ARG_LINK_LIBRARIES})
(NOT ${__target_type} STREQUAL "EXECUTABLE")) if(TARGET ${__link_library})
target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES}) get_target_property(__lib_type ${__link_library} TYPE)
else() if(__lib_type)
foreach(__link_library ${ARG_LINK_LIBRARIES}) get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES)
if(TARGET ${__link_library}) if(__include_dirs)
get_target_property(__lib_type ${__link_library} TYPE) target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs})
if(__lib_type) endif()
get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES) if(${__target_type} STREQUAL "EXECUTABLE")
if(__include_dirs) if(${__lib_type} STREQUAL "OBJECT_LIBRARY")
target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs}) if(TARGET ${__link_library}_static)
endif() target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_static)
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()
else() else()
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}) target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_shared)
endif() endif()
else()
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library})
endif() endif()
endif() endif()
endif() endif()
endforeach() endif()
endif() endforeach()
endif() endif()
endif() endif()
# Установка публичных заголовочных файлов # Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL) if(PROJECT_IS_TOP_LEVEL AND ARG_PUBLIC_HEADERS)
myx_install_relative(${PROJECT_SOURCE_DIR} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_HEADERS} FILES ${ARG_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}

View File

@ -1,9 +1,9 @@
include_guard(GLOBAL) include_guard(GLOBAL)
macro(myx_create_symlink original linkname) macro(myx_create_symlink original linkname)
if(NOT EXISTS ${linkname}) if(UNIX AND (NOT EXISTS ${linkname}))
if(${CMAKE_VERSION} VERSION_LESS "3.14.0") if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
execute_process(COMMAND ${CMAKE_COMMAND} -E myx_create_symlink ${original} ${linkname}) execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${original} ${linkname})
else() else()
file(CREATE_LINK ${original} ${linkname} SYMBOLIC) file(CREATE_LINK ${original} ${linkname} SYMBOLIC)
endif() endif()

View File

@ -46,13 +46,17 @@ function(myx_uncrustify TARGET_NAME)
endif() endif()
# Динамически сгенерированные файлы исключаются # Динамически сгенерированные файлы исключаются
get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES) get_target_property(__target_type ${TARGET_NAME} TYPE)
if(__s1) if(${__target_type} STREQUAL "INTERFACE_LIBRARY")
list(APPEND __all_sources ${__s1}) get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES)
endif() if(__s1)
get_target_property(__s2 ${TARGET_NAME} SOURCES) list(APPEND __all_sources ${__s1})
if(__s2) endif()
list(APPEND __all_sources ${__s2}) else()
get_target_property(__s2 ${TARGET_NAME} SOURCES)
if(__s2)
list(APPEND __all_sources ${__s2})
endif()
endif() endif()
foreach(iter ${__all_sources}) foreach(iter ${__all_sources})

View File

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

View File

@ -1 +1 @@
2.0.26 2.0.31

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.26 LANGUAGES) project(myx-cmake VERSION 2.0.31 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.26) unstable; urgency=medium myx-cmake (2.0.31) 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.26 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) find_package(MyxCMake 2.0.31 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.26 REQUIRED) find_package(MyxCMake 2.0.31 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)