Compare commits

..

No commits in common. "1c504e232878eb0b6c4250c64db75cdf0634dbdb" and "9fe572822c5bc9cba3eaaaf4a575448f9676e017" have entirely different histories.

13 changed files with 92 additions and 113 deletions

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "2.0.30") set(MYX_CMAKE_PACKAGE_VERSION "2.0.26")
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,18 +1,15 @@
#[=======================================================================[.rst: #[=======================================================================[.rst:
myx_add_interface_library myx_add_library
------------------------- ---------------
Вспомогательная функция для создания интерфейсной библиотеки:: Вспомогательная функция для создания библиотеки::
myx_add_interface_library(TARGET_NAME myx_add_library(TARGET_NAME TARGET_TYPE
[ 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_NAME` - имя библиотеки и `TARGET_TYPE` - тип цели.
Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов. Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов.
Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых
переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных. переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных.
@ -34,13 +31,9 @@ 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 HEADERS LINK_LIBRARIES PACKAGES) set(multiValueArgs)
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)
@ -48,31 +41,7 @@ function(myx_add_interface_library TARGET_NAME)
endif() endif()
# Вызов стандартной функции `add_library()` # Вызов стандартной функции `add_library()`
if(${CMAKE_VERSION} VERSION_LESS "3.19.0") add_library(${TARGET_NAME} INTERFACE ${ARG_UNPARSED_ARGUMENTS})
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()
# Библиотека, состоящая только из заголовочных файлов не требует сборки. # Библиотека, состоящая только из заголовочных файлов не требует сборки.
# Стандартные пути к заголовочным файлам # Стандартные пути к заголовочным файлам
@ -106,14 +75,16 @@ 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"
@ -131,21 +102,23 @@ 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"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT DEV
COMPONENT DEV) DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# Установка библиотеки из заголовочных файлов # Установка библиотеки из заголовочных файлов
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 DEV) COMPONENT LIB
)
# Установка публичных заголовочных файлов # Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL AND ARG_HEADERS) if(PROJECT_IS_TOP_LEVEL)
myx_install_relative(${PROJECT_SOURCE_DIR} myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_HEADERS} FILES ${ARG_UNPARSED_ARGUMENTS}
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_object_library myx_add_library
---------------------- ---------------
Вспомогательная функция для создания объектной библиотеки:: Вспомогательная функция для создания объектной библиотеки::

View File

@ -129,8 +129,7 @@ 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)
# TODO list(REMOVE_DUPLICATES CPACK_COMPONENTS_ALL)
#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,11 +87,7 @@ 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)
if(target_type STREQUAL "INTERFACE_LIBRARY") target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
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,14 +12,12 @@ 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})
@ -45,12 +43,14 @@ 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()
target_include_directories(${PROJECT_NAME} PRIVATE if(NOT __target_type STREQUAL "INTERFACE_LIBRARY")
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
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_BINARY_DIR}/include>)
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src")
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
endif()
endif() endif()
if(__target_type STREQUAL "EXECUTABLE") if(__target_type STREQUAL "EXECUTABLE")
@ -74,47 +74,62 @@ 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()
target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS}) if(NOT ${__target_type} STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS}) target_sources(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
target_sources(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>) target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS}) target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS})
target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
endif()
# CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY` if(${__target_type} STREQUAL "INTERFACE_LIBRARY")
# информацию о заголовочных файлах. Это обход. foreach(__lib ${ARG_LINK_LIBRARIES})
if(${CMAKE_VERSION} VERSION_GREATER "3.11.99") if(TARGET ${__lib})
target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES}) install(
TARGETS ${__lib}
EXPORT ${TARGET_NAME}Targets
COMPONENT LIB
)
endif()
endforeach()
target_link_libraries(${TARGET_NAME} INTERFACE ${ARG_LINK_LIBRARIES})
else() else()
if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND # CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY`
(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()
foreach(__link_library ${ARG_LINK_LIBRARIES}) if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND
if(TARGET ${__link_library}) (NOT ${__target_type} STREQUAL "EXECUTABLE"))
get_target_property(__lib_type ${__link_library} TYPE) target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
if(__lib_type) else()
get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES) foreach(__link_library ${ARG_LINK_LIBRARIES})
if(__include_dirs) if(TARGET ${__link_library})
target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs}) get_target_property(__lib_type ${__link_library} TYPE)
endif() if(__lib_type)
if(${__target_type} STREQUAL "EXECUTABLE") get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES)
if(${__lib_type} STREQUAL "OBJECT_LIBRARY") if(__include_dirs)
if(TARGET ${__link_library}_static) target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs})
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_static)
else()
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_shared)
endif() endif()
else() if(${__target_type} STREQUAL "EXECUTABLE")
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}) 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()
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library})
endif()
endif() endif()
endif() endif()
endif() endif()
endif() endforeach()
endforeach() endif()
endif() endif()
endif() endif()
# Установка публичных заголовочных файлов # Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL AND ARG_PUBLIC_HEADERS) if(PROJECT_IS_TOP_LEVEL)
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(UNIX AND (NOT EXISTS ${linkname})) if(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 create_symlink ${original} ${linkname}) execute_process(COMMAND ${CMAKE_COMMAND} -E myx_create_symlink ${original} ${linkname})
else() else()
file(CREATE_LINK ${original} ${linkname} SYMBOLIC) file(CREATE_LINK ${original} ${linkname} SYMBOLIC)
endif() endif()

View File

@ -46,17 +46,13 @@ function(myx_uncrustify TARGET_NAME)
endif() endif()
# Динамически сгенерированные файлы исключаются # Динамически сгенерированные файлы исключаются
get_target_property(__target_type ${TARGET_NAME} TYPE) get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES)
if(${__target_type} STREQUAL "INTERFACE_LIBRARY") if(__s1)
get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES) list(APPEND __all_sources ${__s1})
if(__s1) endif()
list(APPEND __all_sources ${__s1}) get_target_property(__s2 ${TARGET_NAME} SOURCES)
endif() if(__s2)
else() list(APPEND __all_sources ${__s2})
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.31/myx-cmake-local-2.0.31.tar.xz ). [архив](../../../releases/download/2.0.26/myx-cmake-local-2.0.26.tar.xz ).
## Использование ## Использование

View File

@ -1 +1 @@
2.0.31 2.0.26

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