myx update
This commit is contained in:
parent
a1a22464df
commit
d7ef97a277
@ -25,7 +25,6 @@ endif()
|
||||
include(GNUInstallDirs)
|
||||
include(CMakeDependentOption)
|
||||
|
||||
include(${MYX_CMAKE_LIB_DIR}/macro/SkipExternalTarget.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake)
|
||||
@ -44,7 +43,8 @@ include(${MYX_CMAKE_LIB_DIR}/LSBInfo.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/Toolchain.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/CompilerFlags.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddInterfaceLibrary.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddObjectLibrary.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
set(MYX_CMAKE_PACKAGE_VERSION "2.0.19")
|
||||
set(MYX_CMAKE_PACKAGE_VERSION "2.0.31")
|
||||
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
|
150
cmake/myx/lib/AddInterfaceLibrary.cmake
Normal file
150
cmake/myx/lib/AddInterfaceLibrary.cmake
Normal file
@ -0,0 +1,150 @@
|
||||
#[=======================================================================[.rst:
|
||||
myx_add_interface_library
|
||||
-------------------------
|
||||
|
||||
Вспомогательная функция для создания интерфейсной библиотеки::
|
||||
|
||||
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 ] |
|
||||
[ HEADERS headers ])
|
||||
|
||||
Обязательные параметры: `TARGET_NAME` - имя библиотеки.
|
||||
Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов.
|
||||
Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых
|
||||
переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных.
|
||||
Все остальные параметры передаются в стандартную функцию `add_library()`
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GenerateExportHeader)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
function(myx_add_interface_library TARGET_NAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
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 HEADERS LINK_LIBRARIES PACKAGES)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT ARG_OUTPUT_NAME)
|
||||
set(ARG_OUTPUT_NAME ${TARGET_NAME})
|
||||
endif()
|
||||
|
||||
# Вызов стандартной функции `add_library()`
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.19.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()
|
||||
|
||||
# Библиотека, состоящая только из заголовочных файлов не требует сборки.
|
||||
# Стандартные пути к заголовочным файлам
|
||||
target_include_directories(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то созданная цель исключается из цели `all`.
|
||||
# При этом сама цель `${TARGET_NAME}` может участвовать в сборке,
|
||||
# если окажется в перечне зависимостей.
|
||||
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES EXCLUDE_FROM_ALL True)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Правила для установки библиотек и относящихся к ним файлов.
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то эти правила не обрабатываются.
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/library-config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||
)
|
||||
|
||||
install(EXPORT ${TARGET_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
|
||||
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)
|
||||
|
||||
# Формирование файла для pkg-config
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"exec_prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n"
|
||||
"\n"
|
||||
"Name: ${TARGET_NAME}\n"
|
||||
"Description: ${TARGET_NAME} library\n"
|
||||
"Version: ${PROJECT_VERSION}\n"
|
||||
"\n"
|
||||
"Requires:\n"
|
||||
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
||||
|
||||
# Установка файла для pkg-config
|
||||
install(
|
||||
FILES "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
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 DEV)
|
||||
|
||||
# Установка публичных заголовочных файлов
|
||||
if(PROJECT_IS_TOP_LEVEL AND ARG_HEADERS)
|
||||
myx_install_relative(${PROJECT_SOURCE_DIR}
|
||||
FILES ${ARG_HEADERS}
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
||||
COMPONENT DEV)
|
||||
endif()
|
||||
endfunction()
|
@ -1,226 +0,0 @@
|
||||
#[=======================================================================[.rst:
|
||||
myx_add_library
|
||||
---------------
|
||||
|
||||
Вспомогательная функция для создания библиотеки::
|
||||
|
||||
myx_add_library(TARGET_NAME TARGET_TYPE
|
||||
[ OUTPUT_NAME output_name ] |
|
||||
[ EXPORT_FILE_NAME file_name ] |
|
||||
[ EXPORT_BASE_NAME base_name ])
|
||||
|
||||
Обязательные параметры: `TARGET_NAME` - имя библиотеки и `TARGET_TYPE` - тип цели.
|
||||
Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов.
|
||||
Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых
|
||||
переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных.
|
||||
Все остальные параметры передаются в стандартную функцию `add_library()`
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GenerateExportHeader)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
function(myx_add_library TARGET_NAME TARGET_TYPE)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DIR_BACKPORT})
|
||||
endif()
|
||||
|
||||
set(options)
|
||||
set(oneValueArgs OUTPUT_NAME EXPORT_FILE_NAME EXPORT_BASE_NAME)
|
||||
set(multiValueArgs)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT ARG_OUTPUT_NAME)
|
||||
set(ARG_OUTPUT_NAME ${TARGET_NAME})
|
||||
endif()
|
||||
|
||||
# Вызов стандартной функции `add_library()`
|
||||
add_library(${TARGET_NAME} ${TARGET_TYPE} ${ARG_UNPARSED_ARGUMENTS})
|
||||
|
||||
if(TARGET_TYPE STREQUAL "INTERFACE")
|
||||
# Библиотека, состоящая только из заголовочных файлов не требует сборки.
|
||||
# Стандартные пути к заголовочным файлам
|
||||
target_include_directories(${TARGET_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
else()
|
||||
string(TOUPPER ${TARGET_NAME} __project_name_upper)
|
||||
# Опция для разрешения сборки динамической библиотеки
|
||||
cmake_dependent_option(${__project_name_upper}_BUILD_SHARED
|
||||
"Build shared library for ${TARGET_NAME}" ON "BUILD_SHARED_LIBS" OFF)
|
||||
# Опция для разрешения сборки статической библиотеки
|
||||
cmake_dependent_option(${__project_name_upper}_BUILD_STATIC
|
||||
"Build static library for ${TARGET_NAME}" ON "NOT BUILD_SHARED_LIBS" OFF)
|
||||
|
||||
# Стандартные пути к заголовочным файлам
|
||||
target_include_directories(${TARGET_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
# Сборка позиционно-независимых объектных файлов нужна
|
||||
# для создания динамической библиотеки
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(NOT EXPORT_BASE_NAME)
|
||||
set(ARG_EXPORT_BASE_NAME ${__project_name_upper})
|
||||
endif()
|
||||
|
||||
if(NOT ARG_EXPORT_FILE_NAME)
|
||||
set(ARG_EXPORT_FILE_NAME
|
||||
"${PROJECT_SOURCE_DIR}/include/${TARGET_NAME}/${TARGET_NAME}_export.hpp")
|
||||
endif()
|
||||
|
||||
generate_export_header(${TARGET_NAME}
|
||||
BASE_NAME ${ARG_EXPORT_BASE_NAME}
|
||||
EXPORT_MACRO_NAME "EXPORT_${ARG_EXPORT_BASE_NAME}"
|
||||
DEPRECATED_MACRO_NAME "DEPRECATED_${ARG_EXPORT_BASE_NAME}"
|
||||
NO_DEPRECATED_MACRO_NAME "NO_DEPRECATED_${ARG_EXPORT_BASE_NAME}"
|
||||
NO_EXPORT_MACRO_NAME "NO_EXPORT_${ARG_EXPORT_BASE_NAME}"
|
||||
STATIC_DEFINE "STATIC_DEFINE_${ARG_EXPORT_BASE_NAME}"
|
||||
EXPORT_FILE_NAME ${ARG_EXPORT_FILE_NAME}
|
||||
DEFINE_NO_DEPRECATED
|
||||
)
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY
|
||||
INTERFACE_HEADER_FILES "${ARG_EXPORT_FILE_NAME}")
|
||||
|
||||
# Цель для создания динамической библиотеки из объектных файлов
|
||||
if(${__project_name_upper}_BUILD_SHARED)
|
||||
# Для создания динамической библиотеки используются объектные файлы цели ${TARGET_NAME}
|
||||
add_library(${TARGET_NAME}_shared SHARED $<TARGET_OBJECTS:${TARGET_NAME}>)
|
||||
# Установка дополнительных свойств для цели ${TARGET_NAME}_shared
|
||||
# VERSION: версия библиотеки
|
||||
# SOVERSION: мажорная версия библиотеки
|
||||
# LIBRARY_OUTPUT_DIRECTORY: каталог для записи результатов сборки
|
||||
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
|
||||
set_target_properties(${TARGET_NAME}_shared PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||
endif()
|
||||
|
||||
# Цель для создания статической библиотеки из объектных файлов
|
||||
if(${__project_name_upper}_BUILD_STATIC)
|
||||
# Для создания статической библиотеки используются
|
||||
# объектные файлы цели ${TARGET_NAME}
|
||||
add_library(${TARGET_NAME}_static STATIC $<TARGET_OBJECTS:${TARGET_NAME}>)
|
||||
# Установка дополнительных свойств для цели ${TARGET_NAME}_static
|
||||
# ARCHIVE_OUTPUT_DIRECTORY: каталог для записи результатов сборки
|
||||
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
|
||||
set_target_properties(${TARGET_NAME}_static PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то созданная цель исключается из цели `all`.
|
||||
# При этом сама цель `${TARGET_NAME}` может участвовать в сборке,
|
||||
# если окажется в перечне зависимостей.
|
||||
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES EXCLUDE_FROM_ALL True)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Правила для установки библиотек и относящихся к ним файлов.
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то эти правила не обрабатываются.
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/library-config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||
)
|
||||
|
||||
install(EXPORT ${TARGET_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
|
||||
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
|
||||
)
|
||||
|
||||
# Формирование файла для pkg-config
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"exec_prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
||||
|
||||
if(NOT TARGET_TYPE STREQUAL "INTERFACE")
|
||||
file(APPEND "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
"libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n")
|
||||
endif()
|
||||
|
||||
file(APPEND "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
"\n"
|
||||
"Name: ${TARGET_NAME}\n"
|
||||
"Description: ${TARGET_NAME} library\n"
|
||||
"Version: ${PROJECT_VERSION}\n"
|
||||
"\n"
|
||||
"Requires:\n"
|
||||
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
||||
|
||||
if(NOT TARGET_TYPE STREQUAL "INTERFACE")
|
||||
file(APPEND "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
"Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${TARGET_NAME}\n")
|
||||
endif()
|
||||
|
||||
# Установка файла для pkg-config
|
||||
install(
|
||||
FILES "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
COMPONENT DEV
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
|
||||
if(TARGET_TYPE STREQUAL "OBJECT")
|
||||
# Установка динамической библиотеки
|
||||
if(TARGET ${TARGET_NAME}_shared)
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}_shared
|
||||
EXPORT ${TARGET_NAME}Targets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
COMPONENT LIB
|
||||
)
|
||||
endif()
|
||||
|
||||
if(TARGET ${TARGET_NAME}_static)
|
||||
# Установка статической библиотеки
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}_static
|
||||
EXPORT ${TARGET_NAME}Targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
COMPONENT STATIC
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(TARGET_TYPE STREQUAL "INTERFACE")
|
||||
# Установка библиотеки из заголовочных файлов
|
||||
target_include_directories(${TARGET_NAME} SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}
|
||||
EXPORT ${TARGET_NAME}Targets
|
||||
COMPONENT LIB
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
195
cmake/myx/lib/AddObjectLibrary.cmake
Normal file
195
cmake/myx/lib/AddObjectLibrary.cmake
Normal file
@ -0,0 +1,195 @@
|
||||
#[=======================================================================[.rst:
|
||||
myx_add_object_library
|
||||
----------------------
|
||||
|
||||
Вспомогательная функция для создания объектной библиотеки::
|
||||
|
||||
myx_add_object_library(TARGET_NAME
|
||||
[ OUTPUT_NAME output_name ] |
|
||||
[ EXPORT_FILE_NAME file_name ] |
|
||||
[ EXPORT_BASE_NAME base_name ])
|
||||
|
||||
Обязательные параметры: `TARGET_NAME` - имя библиотеки.
|
||||
Параметр `OUTPUT_NAME` определяет базовое имя выходных файлов.
|
||||
Параметр `EXPORT_FILE_NAME` задаёт имя заголовочного файла экспортируемых
|
||||
переменных, а `EXPORT_BASE_NAME` - базовый суффикс для формирования имён переменных.
|
||||
Все остальные параметры передаются в стандартную функцию `add_library()`
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GenerateExportHeader)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
function(myx_add_object_library TARGET_NAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DIR_BACKPORT})
|
||||
endif()
|
||||
|
||||
set(options)
|
||||
set(oneValueArgs OUTPUT_NAME EXPORT_FILE_NAME EXPORT_BASE_NAME)
|
||||
set(multiValueArgs)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT ARG_OUTPUT_NAME)
|
||||
set(ARG_OUTPUT_NAME ${TARGET_NAME})
|
||||
endif()
|
||||
|
||||
# Вызов стандартной функции `add_library()`
|
||||
add_library(${TARGET_NAME} OBJECT ${ARG_UNPARSED_ARGUMENTS})
|
||||
|
||||
string(TOUPPER ${TARGET_NAME} __project_name_upper)
|
||||
# Опция для разрешения сборки динамической библиотеки
|
||||
cmake_dependent_option(${__project_name_upper}_BUILD_SHARED
|
||||
"Build shared library for ${TARGET_NAME}" ON "BUILD_SHARED_LIBS" OFF)
|
||||
# Опция для разрешения сборки статической библиотеки
|
||||
cmake_dependent_option(${__project_name_upper}_BUILD_STATIC
|
||||
"Build static library for ${TARGET_NAME}" ON "NOT BUILD_SHARED_LIBS" OFF)
|
||||
|
||||
# Стандартные пути к заголовочным файлам
|
||||
target_include_directories(${TARGET_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
# Сборка позиционно-независимых объектных файлов нужна
|
||||
# для создания динамической библиотеки
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(NOT EXPORT_BASE_NAME)
|
||||
set(ARG_EXPORT_BASE_NAME ${__project_name_upper})
|
||||
endif()
|
||||
|
||||
if(NOT ARG_EXPORT_FILE_NAME)
|
||||
set(ARG_EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/${TARGET_NAME}/${TARGET_NAME}_export.hpp")
|
||||
endif()
|
||||
|
||||
generate_export_header(${TARGET_NAME}
|
||||
BASE_NAME ${ARG_EXPORT_BASE_NAME}
|
||||
EXPORT_MACRO_NAME "EXPORT_${ARG_EXPORT_BASE_NAME}"
|
||||
DEPRECATED_MACRO_NAME "DEPRECATED_${ARG_EXPORT_BASE_NAME}"
|
||||
NO_DEPRECATED_MACRO_NAME "NO_DEPRECATED_${ARG_EXPORT_BASE_NAME}"
|
||||
NO_EXPORT_MACRO_NAME "NO_EXPORT_${ARG_EXPORT_BASE_NAME}"
|
||||
STATIC_DEFINE "STATIC_DEFINE_${ARG_EXPORT_BASE_NAME}"
|
||||
EXPORT_FILE_NAME ${ARG_EXPORT_FILE_NAME}
|
||||
DEFINE_NO_DEPRECATED
|
||||
)
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY INTERFACE_HEADER_FILES "${ARG_EXPORT_FILE_NAME}")
|
||||
|
||||
# Цель для создания динамической библиотеки из объектных файлов
|
||||
if(${__project_name_upper}_BUILD_SHARED)
|
||||
# Для создания динамической библиотеки используются объектные файлы цели ${TARGET_NAME}
|
||||
add_library(${TARGET_NAME}_shared SHARED $<TARGET_OBJECTS:${TARGET_NAME}>)
|
||||
# Установка дополнительных свойств для цели ${TARGET_NAME}_shared
|
||||
# VERSION: версия библиотеки
|
||||
# SOVERSION: мажорная версия библиотеки
|
||||
# LIBRARY_OUTPUT_DIRECTORY: каталог для записи результатов сборки
|
||||
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
|
||||
set_target_properties(${TARGET_NAME}_shared PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||
endif()
|
||||
|
||||
# Цель для создания статической библиотеки из объектных файлов
|
||||
if(${__project_name_upper}_BUILD_STATIC)
|
||||
# Для создания статической библиотеки используются
|
||||
# объектные файлы цели ${TARGET_NAME}
|
||||
add_library(${TARGET_NAME}_static STATIC $<TARGET_OBJECTS:${TARGET_NAME}>)
|
||||
# Установка дополнительных свойств для цели ${TARGET_NAME}_static
|
||||
# ARCHIVE_OUTPUT_DIRECTORY: каталог для записи результатов сборки
|
||||
# OUTPUT_NAME: базовое имя выходного файла (без учёта расширения)
|
||||
set_target_properties(${TARGET_NAME}_static PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
OUTPUT_NAME ${ARG_OUTPUT_NAME})
|
||||
endif()
|
||||
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то созданная цель исключается из цели `all`.
|
||||
# При этом сама цель `${TARGET_NAME}` может участвовать в сборке,
|
||||
# если окажется в перечне зависимостей.
|
||||
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES EXCLUDE_FROM_ALL True)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Правила для установки библиотек и относящихся к ним файлов.
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то эти правила не обрабатываются.
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/library-config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||
)
|
||||
|
||||
install(EXPORT ${TARGET_NAME}Targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET_NAME}
|
||||
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
|
||||
)
|
||||
|
||||
# Формирование файла для pkg-config
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"exec_prefix=${CMAKE_INSTALL_PREFIX}\n"
|
||||
"includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n"
|
||||
"libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n"
|
||||
"\n"
|
||||
"Name: ${TARGET_NAME}\n"
|
||||
"Description: ${TARGET_NAME} library\n"
|
||||
"Version: ${PROJECT_VERSION}\n"
|
||||
"\n"
|
||||
"Requires:\n"
|
||||
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n"
|
||||
"Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${TARGET_NAME}\n")
|
||||
|
||||
# Установка файла для pkg-config
|
||||
install(
|
||||
FILES "${PROJECT_BINARY_DIR}/${TARGET_NAME}.pc"
|
||||
COMPONENT DEV
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
|
||||
# Установка динамической библиотеки
|
||||
if(TARGET ${TARGET_NAME}_shared)
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}_shared
|
||||
EXPORT ${TARGET_NAME}Targets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
COMPONENT LIB
|
||||
)
|
||||
endif()
|
||||
|
||||
# Установка статической библиотеки
|
||||
if(TARGET ${TARGET_NAME}_static)
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}_static
|
||||
EXPORT ${TARGET_NAME}Targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
COMPONENT STATIC
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
@ -1,32 +1,45 @@
|
||||
include_guard(GLOBAL)
|
||||
function(myx_create_packages TARGET_NAME)
|
||||
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
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_INSTALL_DEFAULT_COMPONENT_NAME CPACK_PACKAGE_CONTACT CPACK_PACKAGING_INSTALL_PREFIX)
|
||||
set(multiValueArgs CPACK_SOURCE_GENERATOR CPACK_GENERATOR CPACK_SOURCE_IGNORE_FILES)
|
||||
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 <nonexistent@mailbox")
|
||||
myx_message_warning("\${PROJECT_NAME}_CONTACT variable is required for packaging but unset")
|
||||
if(${PROJECT_NAME}_AUTHOR_NAME AND ${PROJECT_NAME}_AUTHOR_EMAIL)
|
||||
set(CPACK_PACKAGE_CONTACT "${${PROJECT_NAME}_AUTHOR_NAME} <${${PROJECT_NAME}_AUTHOR_EMAIL}>")
|
||||
else()
|
||||
set(CPACK_PACKAGE_CONTACT "unknown maintainer <nonexistent@mailbox>")
|
||||
myx_message_warning("\${PROJECT_NAME}_CONTACT variable is required for packaging but unset")
|
||||
endif()
|
||||
else()
|
||||
set(CPACK_PACKAGE_CONTACT ${${PROJECT_NAME}_CONTACT})
|
||||
endif()
|
||||
|
||||
if(NOT ${PROJECT_NAME}_VENDOR)
|
||||
if(${PROJECT_NAME}_AUTHOR_NAME)
|
||||
set(CPACK_PACKAGE_VENDOR "${${PROJECT_NAME}_AUTHOR_NAME}")
|
||||
else()
|
||||
set(CPACK_PACKAGE_VENDOR "unknown vendor")
|
||||
myx_message_warning("\${PROJECT_NAME}_VENDOR variable is required for packaging but unset")
|
||||
endif()
|
||||
else()
|
||||
set(CPACK_PACKAGE_VENDOR ${${PROJECT_NAME}_VENDOR})
|
||||
endif()
|
||||
|
||||
string(TOLOWER ${PROJECT_NAME} PN)
|
||||
set(CPACK_PACKAGE_NAME ${PN})
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
|
||||
if(NOT CPACK_PACKAGING_INSTALL_PREFIX)
|
||||
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
|
||||
endif()
|
||||
|
||||
# Параметры для архива исходных текстов
|
||||
if(NOT ARG_CPACK_SOURCE_GENERATOR)
|
||||
set(CPACK_SOURCE_GENERATOR "TXZ")
|
||||
@ -116,7 +129,8 @@ function(myx_create_packages 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
|
||||
@ -171,10 +185,10 @@ function(myx_create_packages NAME)
|
||||
|
||||
if(UNIX AND NOT TARGET deb)
|
||||
add_custom_target(deb WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cpack -G DEB)
|
||||
add_dependencies(deb ${NAME})
|
||||
add_dependencies(deb ${TARGET_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Подключение модуля, выполняющего сборку архивов и пакетов
|
||||
include(CPack)
|
||||
endfunction(myx_create_packages NAME)
|
||||
endfunction(myx_create_packages TARGET_NAME)
|
||||
|
@ -24,7 +24,7 @@ include_guard(GLOBAL)
|
||||
# Обязательно в глобальной области
|
||||
find_package(Git)
|
||||
|
||||
function(FetchContent_Add NAME)
|
||||
function(FetchContent_Add TARGET_NAME)
|
||||
set(options "")
|
||||
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
|
||||
set(multiValueArgs "")
|
||||
@ -45,12 +45,12 @@ function(FetchContent_Add NAME)
|
||||
endif()
|
||||
|
||||
FetchContent_Declare(
|
||||
${NAME}
|
||||
${TARGET_NAME}
|
||||
${ARG_UNPARSED_ARGUMENTS}
|
||||
GIT_REPOSITORY ${ARG_GIT_REPOSITORY}
|
||||
GIT_SHALLOW 1
|
||||
)
|
||||
|
||||
set(FETCHCONTENT_QUIET off)
|
||||
FetchContent_MakeAvailable(${NAME})
|
||||
FetchContent_MakeAvailable(${TARGET_NAME})
|
||||
endfunction()
|
||||
|
@ -1,45 +1,45 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
function(myx_qt5_target_setup NAME)
|
||||
function(myx_qt5_target_setup TARGET_NAME)
|
||||
set(options)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
|
||||
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
get_target_property(target_type ${NAME} TYPE)
|
||||
get_target_property(target_type ${TARGET_NAME} TYPE)
|
||||
|
||||
foreach(iter ${ARG_COMPONENTS})
|
||||
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
||||
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
|
||||
target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
|
||||
else()
|
||||
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
|
||||
endif()
|
||||
if(target_type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools")
|
||||
target_link_libraries(${NAME} PRIVATE "Qt5::${iter}")
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE "Qt5::${iter}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(iter ${ARG_PRIVATE})
|
||||
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
||||
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||
target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||
else()
|
||||
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(target_type STREQUAL "EXECUTABLE")
|
||||
target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
|
||||
target_compile_options(${TARGET_NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
|
||||
endif()
|
||||
|
||||
if(ARG_PUBLIC_MOC)
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
|
||||
endif()
|
||||
|
||||
if(ARG_PRIVATE_MOC)
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
|
||||
endif()
|
||||
|
||||
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
|
||||
@ -52,42 +52,42 @@ function(myx_qt5_target_setup NAME)
|
||||
|
||||
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
|
||||
qt5_wrap_ui(ui_h ${ARG_UI})
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
|
||||
# TODO
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
# Перечень файлов, подлежащих переводу
|
||||
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
||||
get_target_property(tr ${NAME} INTERFACE_TR_FILES)
|
||||
get_target_property(tr ${TARGET_NAME} INTERFACE_TR_FILES)
|
||||
else()
|
||||
get_target_property(tr ${NAME} TR_FILES)
|
||||
get_target_property(tr ${TARGET_NAME} TR_FILES)
|
||||
endif()
|
||||
# Формирование файла ресурсов с переводами
|
||||
if("LinguistTools" IN_LIST ARG_COMPONENTS AND tr)
|
||||
# Заглавие файла ресурсов
|
||||
file(WRITE ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
|
||||
file(WRITE ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
|
||||
# Для каждого языка, указанное в параметре LANGS
|
||||
foreach(iter ${ARG_LANGS})
|
||||
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
|
||||
# и его компиляция в каталог ${PROJECT_BINARY_DIR}
|
||||
qt5_create_translation(qm ${tr}
|
||||
"${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts"
|
||||
"${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts"
|
||||
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
|
||||
# Добавление записи для скомпилированного файла переводов в ресурсный файл
|
||||
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc
|
||||
"<file alias=\"${NAME}_${iter}\">${NAME}_${iter}.qm</file>\n")
|
||||
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc
|
||||
"<file alias=\"${TARGET_NAME}_${iter}\">${TARGET_NAME}_${iter}.qm</file>\n")
|
||||
# Добавление скомпилированного файла переводов к списку зависимостей для цели
|
||||
target_sources(${NAME} PRIVATE ${qm})
|
||||
target_sources(${TARGET_NAME} PRIVATE ${qm})
|
||||
endforeach()
|
||||
# Окончение файла ресурсов
|
||||
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "</qresource></RCC>\n")
|
||||
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "</qresource></RCC>\n")
|
||||
# Комплияция файла ресурсов с переводами
|
||||
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc)
|
||||
target_sources(${NAME} PRIVATE ${qrc_l10n})
|
||||
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
|
||||
target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n})
|
||||
endif()
|
||||
unset(tr)
|
||||
target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
||||
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
||||
|
||||
# Установка публичных заголовочных файлов
|
||||
if(PROJECT_IS_TOP_LEVEL)
|
||||
|
@ -1,59 +1,59 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
function(myx_target_setup NAME)
|
||||
function(myx_target_setup TARGET_NAME)
|
||||
set(options)
|
||||
set(oneValueArgs PCH)
|
||||
set(multiValueArgs COMPILE_DEFINITIONS PACKAGES LINK_LIBRARIES
|
||||
CPP INTERFACE_HEADERS PUBLIC_HEADERS PRIVATE_HEADERS)
|
||||
CPP PUBLIC_HEADERS PRIVATE_HEADERS)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT TARGET ${NAME})
|
||||
myx_message_fatal_error("Target ${NAME} does not exists.")
|
||||
if(NOT TARGET ${TARGET_NAME})
|
||||
myx_message_fatal_error("Target ${TARGET_NAME} does not exists.")
|
||||
endif()
|
||||
|
||||
get_target_property(target_type ${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})
|
||||
target_include_directories(${NAME} PRIVATE ${${iter}_INCLUDE_DIRS})
|
||||
target_compile_definitions(${NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS})
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${${iter}_INCLUDE_DIRS})
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS})
|
||||
endforeach()
|
||||
target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
|
||||
|
||||
if(ARG_CPP)
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY CPP_FILES ${ARG_CPP})
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_CPP})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY CPP_FILES ${ARG_CPP})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_CPP})
|
||||
endif()
|
||||
|
||||
if(ARG_PUBLIC_HEADERS)
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_HEADERS}")
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_HEADERS})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_HEADERS}")
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_HEADERS})
|
||||
endif()
|
||||
|
||||
if(ARG_PRIVATE_HEADERS)
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_HEADERS}")
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_HEADERS})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_HEADERS}")
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_HEADERS})
|
||||
endif()
|
||||
|
||||
if(ARG_PCH)
|
||||
if((${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) AND (PROJECT_IS_TOP_LEVEL OR MYX_USE_LOCAL_DIRECTORIES))
|
||||
target_precompile_headers(${NAME} PRIVATE ${ARG_PCH})
|
||||
target_precompile_headers(${TARGET_NAME} PRIVATE ${ARG_PCH})
|
||||
else()
|
||||
target_compile_options(${NAME} PRIVATE -include ${ARG_PCH})
|
||||
target_compile_options(${TARGET_NAME} PRIVATE -include ${ARG_PCH})
|
||||
endif()
|
||||
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}")
|
||||
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>)
|
||||
|
||||
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
$<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()
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
|
||||
endif()
|
||||
|
||||
if(target_type STREQUAL "EXECUTABLE")
|
||||
if(__target_type STREQUAL "EXECUTABLE")
|
||||
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/include")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
@ -63,53 +63,48 @@ function(myx_target_setup NAME)
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}>)
|
||||
endif()
|
||||
|
||||
set_target_properties(${NAME} PROPERTIES
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
if(CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
||||
target_compile_options(${NAME} PUBLIC ${CMAKE_CXX_COMPILE_OPTIONS_PIE})
|
||||
target_compile_options(${TARGET_NAME} PUBLIC ${CMAKE_CXX_COMPILE_OPTIONS_PIE})
|
||||
endif()
|
||||
install(TARGETS ${NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
install(TARGETS ${TARGET_NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
|
||||
target_sources(${NAME} INTERFACE $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
|
||||
else()
|
||||
target_sources(${NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
|
||||
target_sources(${NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
|
||||
target_sources(${NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS})
|
||||
target_compile_definitions(${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 $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
|
||||
|
||||
# CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY`
|
||||
# информацию о заголовочных файлах. Это обход.
|
||||
if(${CMAKE_VERSION} VERSION_GREATER "3.11.99")
|
||||
target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES})
|
||||
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(${NAME} PRIVATE ${ARG_LINK_LIBRARIES})
|
||||
elseif(${target_type} STREQUAL "INTERFACE")
|
||||
target_link_libraries(${NAME} INTERFACE ${ARG_LINK_LIBRARIES})
|
||||
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_dir ${link_library} INTERFACE_INCLUDE_DIRECTORIES)
|
||||
if(include_dir)
|
||||
target_include_directories(${NAME} PUBLIC ${include_dir})
|
||||
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(${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(${NAME} PRIVATE ${link_library}_shared)
|
||||
endif()
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_shared)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(${NAME} PRIVATE ${link_library})
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -119,9 +114,9 @@ function(myx_target_setup NAME)
|
||||
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} ${ARG_INTERFACE_HEADERS}
|
||||
FILES ${ARG_PUBLIC_HEADERS}
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
||||
COMPONENT DEV
|
||||
)
|
||||
|
@ -1,14 +1,16 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
function(myx_doc_doxygen NAME)
|
||||
function(myx_doc_doxygen TARGET_NAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT})
|
||||
endif()
|
||||
|
||||
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_package(Doxygen)
|
||||
if(DOXYGEN_FOUND)
|
||||
set(DOXYGEN_FOUND ON CACHE STRING "Doxygen documentation generator enabled" FORCE)
|
||||
@ -17,14 +19,14 @@ function(myx_doc_doxygen NAME)
|
||||
set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
|
||||
endif()
|
||||
|
||||
set(target "myx-doc-doxygen-${NAME}")
|
||||
if(NOT DOXYGEN_FOUND)
|
||||
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
|
||||
set(target myx-doc-doxygen-${TARGET_NAME})
|
||||
if(TARGET ${target})
|
||||
myx_message_warning("Target ${target} already defined")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(TARGET ${target})
|
||||
myx_message_warning("Target ${target} already defined")
|
||||
if(NOT DOXYGEN_FOUND)
|
||||
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
@ -5,12 +5,13 @@ myx_generate_git_info_header
|
||||
Вспомогательная функция для автоматической генерации заголовочного
|
||||
файла, содержащего информацию о текущем состоянии репозитория git::
|
||||
|
||||
myx_generate_git_info_header(TARGET BASE_FILENAME
|
||||
myx_generate_git_info_header(TARGET_NAME BASE_FILENAME
|
||||
[ PREFIX prefix ] )
|
||||
|
||||
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
|
||||
и `BASE_FILENAME` - имя генерируемого заголовочного файла. Дополнительный аргумент
|
||||
`PREFIX` добавляет префикс к генерируемым именам переменных.
|
||||
Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
|
||||
заголовочный файл, и `BASE_FILENAME` - имя генерируемого заголовочного
|
||||
файла. Дополнительный аргумент `PREFIX` добавляет префикс к генерируемым
|
||||
именам переменных.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
@ -20,7 +21,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
function(myx_generate_git_info_header target base_filename)
|
||||
function(myx_generate_git_info_header TARGET_NAME BASE_FILENAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
|
||||
endif()
|
||||
@ -30,24 +31,25 @@ function(myx_generate_git_info_header target base_filename)
|
||||
set(multiValueArgs)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
|
||||
set(__filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
|
||||
file(APPEND ${__filename} "")
|
||||
|
||||
set(PREFIX "")
|
||||
set(__prefix "")
|
||||
if(ARG_PREFIX)
|
||||
string(APPEND ARG_PREFIX "_")
|
||||
string(REPLACE "-" "_" PREFIX ${ARG_PREFIX})
|
||||
string(REPLACE "-" "_" __prefix ${ARG_PREFIX})
|
||||
endif()
|
||||
|
||||
# cmake-format: off
|
||||
if(NOT TARGET ${target}-git-info-header)
|
||||
add_custom_target(${target}-git-info-header ALL
|
||||
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -DPREFIX=${PREFIX}
|
||||
if(NOT TARGET ${TARGET_NAME}-git-info-header)
|
||||
add_custom_target(${TARGET_NAME}-git-info-header ALL
|
||||
${CMAKE_COMMAND} -DGIT_INFO_FILE=${__filename} -DPREFIX=${__prefix}
|
||||
-P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake
|
||||
BYPRODUCTS ${filename}
|
||||
BYPRODUCTS ${__filename}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
|
||||
endif()
|
||||
# cmake-format: on
|
||||
|
||||
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
|
||||
target_sources(${target} PRIVATE ${filename})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
|
||||
target_sources(${TARGET_NAME} PRIVATE ${__filename})
|
||||
endfunction()
|
||||
|
@ -5,10 +5,10 @@ myx_generate_private_config_header
|
||||
Вспомогательная функция для автоматической генерации заголовочного
|
||||
файла, содержащего информацию о проекте::
|
||||
|
||||
myx_generate_private_config_header(TARGET BASE_FILENAME)
|
||||
myx_generate_private_config_header(TARGET_NAME BASE_FILENAME)
|
||||
|
||||
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
|
||||
и `BASE_FILENAME` - имя генерируемого заголовочного файла.
|
||||
Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
|
||||
заголовочный файл, и `BASE_FILENAME` - имя генерируемого заголовочного файла.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
@ -18,7 +18,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
function(myx_generate_private_config_header target base_filename)
|
||||
function(myx_generate_private_config_header TARGET_NAME BASE_FILENAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
|
||||
endif()
|
||||
@ -27,9 +27,9 @@ function(myx_generate_private_config_header target base_filename)
|
||||
myx_project_version_int()
|
||||
get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
|
||||
|
||||
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
|
||||
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${filename})
|
||||
set(__filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
|
||||
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${__filename})
|
||||
|
||||
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
|
||||
target_sources(${target} PRIVATE ${filename})
|
||||
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
|
||||
target_sources(${TARGET_NAME} PRIVATE ${__filename})
|
||||
endfunction()
|
||||
|
@ -1,9 +1,9 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
macro(myx_create_symlink original linkname)
|
||||
if(NOT EXISTS ${linkname})
|
||||
if(UNIX AND (NOT EXISTS ${linkname}))
|
||||
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()
|
||||
file(CREATE_LINK ${original} ${linkname} SYMBOLIC)
|
||||
endif()
|
||||
|
@ -1,33 +0,0 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
# Пропуск целей, которые создаются автоматически в `CMAKE_BINARY_DIR`
|
||||
macro(myx_skip_external_target NAME)
|
||||
get_target_property(__type ${NAME} TYPE)
|
||||
if(__type STREQUAL "INTERFACE_LIBRARY")
|
||||
get_target_property(__sources ${NAME} INTERFACE_SOURCES)
|
||||
foreach(iter ${__sources})
|
||||
string(FIND ${iter} ${CMAKE_BINARY_DIR} __pos)
|
||||
if(__pos GREATER -1)
|
||||
unset(__type)
|
||||
unset(__pos)
|
||||
unset(__sources)
|
||||
return()
|
||||
endif()
|
||||
endforeach()
|
||||
unset(__type)
|
||||
unset(__pos)
|
||||
unset(__sources)
|
||||
else()
|
||||
get_target_property(__source_dir ${NAME} SOURCE_DIR)
|
||||
string(FIND ${__source_dir} ${CMAKE_BINARY_DIR} __pos)
|
||||
if(__pos EQUAL 0)
|
||||
unset(__type)
|
||||
unset(__pos)
|
||||
unset(__source_dir)
|
||||
return()
|
||||
endif()
|
||||
unset(__pos)
|
||||
unset(__source_dir)
|
||||
endif()
|
||||
unset(__type)
|
||||
endmacro(myx_skip_external_target NAME)
|
@ -1,17 +1,17 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
|
||||
|
||||
function(myx_uncrustify NAME)
|
||||
function(myx_uncrustify TARGET_NAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
|
||||
endif()
|
||||
|
||||
myx_skip_external_target(${NAME})
|
||||
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(options)
|
||||
set(oneValueArgs CONFIG)
|
||||
@ -46,44 +46,53 @@ function(myx_uncrustify NAME)
|
||||
endif()
|
||||
|
||||
# Динамически сгенерированные файлы исключаются
|
||||
get_target_property(target_type ${NAME} TYPE)
|
||||
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
|
||||
get_target_property(s ${NAME} INTERFACE_SOURCES)
|
||||
get_target_property(__target_type ${TARGET_NAME} TYPE)
|
||||
if(${__target_type} STREQUAL "INTERFACE_LIBRARY")
|
||||
get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES)
|
||||
if(__s1)
|
||||
list(APPEND __all_sources ${__s1})
|
||||
endif()
|
||||
else()
|
||||
get_target_property(s ${NAME} SOURCES)
|
||||
get_target_property(__s2 ${TARGET_NAME} SOURCES)
|
||||
if(__s2)
|
||||
list(APPEND __all_sources ${__s2})
|
||||
endif()
|
||||
endif()
|
||||
foreach(iter ${s})
|
||||
|
||||
foreach(iter ${__all_sources})
|
||||
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
|
||||
if(pos EQUAL -1)
|
||||
list(APPEND src ${iter})
|
||||
list(APPEND __sources ${iter})
|
||||
endif()
|
||||
endforeach()
|
||||
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg
|
||||
|
||||
set(__fixed_config ${PROJECT_BINARY_DIR}/uncrustify-${TARGET_NAME}.cfg)
|
||||
|
||||
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${TARGET_NAME}.cfg
|
||||
COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc
|
||||
-c ${ARG_CONFIG}
|
||||
-o ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg)
|
||||
list(APPEND UNCRUSTIFY_OPTS -c ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg)
|
||||
-c ${ARG_CONFIG} -o ${__fixed_config})
|
||||
list(APPEND __options -c ${__fixed_config})
|
||||
# cmake-format: off
|
||||
add_custom_target(${NAME}-uncrustify-check
|
||||
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg
|
||||
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${src})
|
||||
add_custom_target(${TARGET_NAME}-uncrustify-check
|
||||
DEPENDS ${__fixed_config}
|
||||
COMMAND ${UNCRUSTIFY_EXE} ${__options} --check ${__sources})
|
||||
|
||||
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
|
||||
add_custom_target(${NAME}-uncrustify
|
||||
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg
|
||||
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${src})
|
||||
list(APPEND __options --replace --no-backup)
|
||||
add_custom_target(${TARGET_NAME}-uncrustify
|
||||
DEPENDS ${__fixed_config}
|
||||
COMMAND ${UNCRUSTIFY_EXE} ${__options} --mtime ${__sources})
|
||||
|
||||
add_custom_target(${NAME}-uncrustify-append-comments
|
||||
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg
|
||||
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS}
|
||||
add_custom_target(${TARGET_NAME}-uncrustify-append-comments
|
||||
DEPENDS ${__fixed_config}
|
||||
COMMAND ${UNCRUSTIFY_EXE} ${__options}
|
||||
--set cmt_insert_class_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/classheader.txt
|
||||
--set cmt_insert_file_footer=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/filefooter.txt
|
||||
--set cmt_insert_file_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fileheader.txt
|
||||
--set cmt_insert_func_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/funcheader.txt
|
||||
--set cmt_insert_before_ctor_dtor=true --mtime ${src})
|
||||
--set cmt_insert_before_ctor_dtor=true --mtime ${__sources})
|
||||
# cmake-format: on
|
||||
|
||||
add_dependencies(myx-uncrustify ${NAME}-uncrustify)
|
||||
add_dependencies(myx-uncrustify-check ${NAME}-uncrustify-check)
|
||||
add_dependencies(myx-uncrustify-append-comments ${NAME}-uncrustify-append-comments)
|
||||
add_dependencies(myx-uncrustify ${TARGET_NAME}-uncrustify)
|
||||
add_dependencies(myx-uncrustify-check ${TARGET_NAME}-uncrustify-check)
|
||||
add_dependencies(myx-uncrustify-append-comments ${TARGET_NAME}-uncrustify-append-comments)
|
||||
endfunction()
|
||||
|
@ -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.19 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} ===")
|
||||
else()
|
||||
if(MYX_CMAKE_USE_SYSTEM)
|
||||
find_package(MyxCMake 2.0.19 REQUIRED)
|
||||
find_package(MyxCMake 2.0.31 REQUIRED)
|
||||
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
|
||||
else()
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
|
||||
|
Loading…
Reference in New Issue
Block a user