Обновление MyxCMake

This commit is contained in:
Andrei Astafev 2023-07-30 11:37:15 +03:00
parent 50a39faa70
commit 1d5707399f
25 changed files with 485 additions and 629 deletions

View File

@ -1,7 +1,15 @@
cmake_policy(PUSH) cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW) # IN_LIST operator cmake_policy(SET CMP0057 NEW) # IN_LIST operator
# Каталог для модулей, выполняющих поиск библиотек # CMake выполняет проверку системного окружения с помощью модулей,
# расположенных в следующих каталогах:
# /usr/share/cmake-${CMAKE_VERSION}/Modules
# /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake
# /usr/lib/cmake
# Если для используемой программы или библиотеки нет стандартного
# модуля для поиска, то можно использовать собственный.
# С помощью переменной `CMAKE_MODULE_PATH` указывается перечень
# дополнительных каталогов, в которых производится поиск модулей.
set(MYX_CMAKE_FIND_DIR "${PROJECT_SOURCE_DIR}/cmake/find") set(MYX_CMAKE_FIND_DIR "${PROJECT_SOURCE_DIR}/cmake/find")
if(IS_DIRECTORY "${MYX_CMAKE_FIND_DIR}") if(IS_DIRECTORY "${MYX_CMAKE_FIND_DIR}")
if(NOT ${MYX_CMAKE_FIND_DIR} IN_LIST CMAKE_MODULE_PATH) if(NOT ${MYX_CMAKE_FIND_DIR} IN_LIST CMAKE_MODULE_PATH)
@ -14,6 +22,7 @@ get_filename_component(MYX_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTO
set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports") set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports")
set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib") set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib")
# Модули для обеспечения обратной совместимости со старыми версиями CMake
include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake)
include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake) include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake)
if(${CMAKE_VERSION} VERSION_LESS "3.11.0") if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
@ -22,14 +31,17 @@ else()
include(FetchContent) include(FetchContent)
endif() endif()
# Загрузка стандартных модулей
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakeDependentOption) include(CMakeDependentOption)
include(${MYX_CMAKE_LIB_DIR}/macro/SkipExternalTarget.cmake) # Полезные макросы
include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/CheckEnableCxxCompilerFlag.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/CheckEnableCxxCompilerFlag.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/GTest.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/QTest.cmake)
include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake) include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake)
include(${MYX_CMAKE_LIB_DIR}/PopulateCMakeBinaryDir.cmake) include(${MYX_CMAKE_LIB_DIR}/PopulateCMakeBinaryDir.cmake)
@ -38,13 +50,16 @@ include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake) include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake) include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddExternalTarget.cmake)
include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake) include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake)
include(${MYX_CMAKE_LIB_DIR}/LSBInfo.cmake) set(MYX_CMAKE_TOOLCHAINS_DIR "${MYX_CMAKE_LIB_DIR}/toolchains")
include(${MYX_CMAKE_LIB_DIR}/Toolchain.cmake) include(${MYX_CMAKE_LIB_DIR}/Toolchains.cmake)
include(${MYX_CMAKE_LIB_DIR}/CompilerFlags.cmake) unset(MYX_CMAKE_TOOLCHAINS_DIR)
include(${MYX_CMAKE_LIB_DIR}/AddExecutable.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}/TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake) include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)

View File

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

@ -3,7 +3,7 @@
# Макрос реализован для обратной совместимости # Макрос реализован для обратной совместимости
if(${CMAKE_VERSION} VERSION_LESS "3.10.0") if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
macro(include_guard) macro(include_guard)
if (CMAKE_FILE_${CMAKE_CURRENT_LIST_FILE}_ALREADY_INCLUDED) if(CMAKE_FILE_${CMAKE_CURRENT_LIST_FILE}_ALREADY_INCLUDED)
return() return()
endif() endif()
set(CMAKE_FILE_${CMAKE_CURRENT_LIST_FILE}_ALREADY_INCLUDED TRUE) set(CMAKE_FILE_${CMAKE_CURRENT_LIST_FILE}_ALREADY_INCLUDED TRUE)

View File

@ -1,10 +1,11 @@
include_guard(GLOBAL) include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS 3.21) if(${CMAKE_VERSION} VERSION_LESS 3.21)
get_property(nt DIRECTORY PROPERTY PARENT_DIRECTORY) get_property(__parent_directory DIRECTORY PROPERTY PARENT_DIRECTORY)
if(NOT nt) if(NOT __parent_directory)
set(PROJECT_IS_TOP_LEVEL true) set(PROJECT_IS_TOP_LEVEL TRUE)
else()
set(PROJECT_IS_TOP_LEVEL FALSE)
endif() endif()
unset(nt) unset(__parent_directory)
endif() endif()

View File

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

View File

@ -1,13 +1,13 @@
#[=======================================================================[.rst: #[=======================================================================[.rst:
Обёртки для функции `message()`, которые в терминале UNIX Обёртки для функции `message()`, которые в терминале UNIX
подсвечиают сообщения в зависимости от важности. подсвечивают сообщения в зависимости от важности.
#]=======================================================================] #]=======================================================================]
include_guard(GLOBAL) include_guard(GLOBAL)
if(DEFINED ENV{TERM} AND UNIX) if(DEFINED ENV{COLORTERM} AND UNIX)
string(ASCII 27 Esc) string(ASCII 27 Esc)
set(MyxColorReset "${Esc}[m") set(MyxColorReset "${Esc}[m")
set(MyxColorBold "${Esc}[1m") set(MyxColorBold "${Esc}[1m")

View File

@ -1,28 +0,0 @@
include_guard(GLOBAL)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# cmake-format: off
if((MYX_CMAKE_LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE") AND
(MYX_CMAKE_LSB_CODENAME STREQUAL "smolensk") AND
(MYX_CMAKE_LSB_RELEASE_VERSION STREQUAL "1.5"))
# cmake-format: on
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS ON)
check_enable_cxx_compiler_flag(-Wno-shadow)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS ON)
check_enable_cxx_compiler_flag(-Wno-invalid-offsetof)
list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/e2k-linux-gnu")
endif()
if(CMAKE_COLOR_MAKEFILE)
check_enable_cxx_compiler_flag(-fdiagnostics-color=auto)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_COLOR_MAKEFILE)
check_enable_cxx_compiler_flag(-fcolor-diagnostics)
endif()
endif()

View File

@ -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(options)
set(oneValueArgs DEBIAN_PACKAGE_TYPE CPACK_DEBIAN_PACKAGE_SECTION CPACK_DEBIAN_PACKAGE_PRIORITY set(oneValueArgs DEBIAN_PACKAGE_TYPE CPACK_DEBIAN_PACKAGE_SECTION CPACK_DEBIAN_PACKAGE_PRIORITY
CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CPACK_PACKAGE_CONTACT) CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CPACK_PACKAGE_CONTACT CPACK_PACKAGING_INSTALL_PREFIX)
set(multiValueArgs CPACK_SOURCE_GENERATOR CPACK_GENERATOR CPACK_SOURCE_IGNORE_FILES set(multiValueArgs CPACK_SOURCE_GENERATOR CPACK_GENERATOR CPACK_SOURCE_IGNORE_FILES)
CPACK_PACKAGING_INSTALL_PREFIX)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 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) if(NOT ${PROJECT_NAME}_CONTACT)
set(CPACK_PACKAGE_CONTACT "unknown maintainer <nonexistent@mailbox") if(${PROJECT_NAME}_AUTHOR_NAME AND ${PROJECT_NAME}_AUTHOR_EMAIL)
myx_message_warning("\${PROJECT_NAME}_CONTACT variable is required for packaging but unset") 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() else()
set(CPACK_PACKAGE_CONTACT ${${PROJECT_NAME}_CONTACT}) set(CPACK_PACKAGE_CONTACT ${${PROJECT_NAME}_CONTACT})
endif() 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) string(TOLOWER ${PROJECT_NAME} PN)
set(CPACK_PACKAGE_NAME ${PN}) set(CPACK_PACKAGE_NAME ${PN})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) 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) if(NOT ARG_CPACK_SOURCE_GENERATOR)
set(CPACK_SOURCE_GENERATOR "TXZ") set(CPACK_SOURCE_GENERATOR "TXZ")
@ -116,7 +129,8 @@ function(myx_create_packages 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
@ -171,10 +185,10 @@ function(myx_create_packages NAME)
if(UNIX AND NOT TARGET deb) if(UNIX AND NOT TARGET deb)
add_custom_target(deb WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cpack -G 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()
endif() endif()
# Подключение модуля, выполняющего сборку архивов и пакетов # Подключение модуля, выполняющего сборку архивов и пакетов
include(CPack) include(CPack)
endfunction(myx_create_packages NAME) endfunction(myx_create_packages TARGET_NAME)

View File

@ -24,7 +24,7 @@ include_guard(GLOBAL)
# Обязательно в глобальной области # Обязательно в глобальной области
find_package(Git) find_package(Git)
function(FetchContent_Add NAME) function(FetchContent_Add TARGET_NAME)
set(options "") set(options "")
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH) set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
set(multiValueArgs "") set(multiValueArgs "")
@ -45,12 +45,12 @@ function(FetchContent_Add NAME)
endif() endif()
FetchContent_Declare( FetchContent_Declare(
${NAME} ${TARGET_NAME}
${ARG_UNPARSED_ARGUMENTS} ${ARG_UNPARSED_ARGUMENTS}
GIT_REPOSITORY ${ARG_GIT_REPOSITORY} GIT_REPOSITORY ${ARG_GIT_REPOSITORY}
GIT_SHALLOW 1 GIT_SHALLOW 1
) )
set(FETCHCONTENT_QUIET off) set(FETCHCONTENT_QUIET off)
FetchContent_MakeAvailable(${NAME}) FetchContent_MakeAvailable(${TARGET_NAME})
endfunction() endfunction()

View File

@ -1,34 +0,0 @@
include_guard(GLOBAL)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(MYX_CMAKE_LSB_DISTRIBUTOR_ID "unknown")
set(MYX_CMAKE_LSB_CODENAME "unknown")
set(MYX_CMAKE_LSB_RELEASE_VERSION "unknown")
if(CMAKE_CROSSCOMPILING)
return()
endif()
if(EXISTS /etc/mcst_version)
set(MYX_CMAKE_LSB_DISTRIBUTOR_ID "ElbrusD")
set(MYX_CMAKE_LSB_CODENAME "Jessie")
execute_process(COMMAND cat /etc/mcst_version
OUTPUT_VARIABLE MYX_CMAKE_LSB_RELEASE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
find_program(LSB_RELEASE_EXECUTABLE lsb_release)
# cmake-format: off
if(LSB_RELEASE_EXECUTABLE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si
OUTPUT_VARIABLE MYX_CMAKE_LSB_DISTRIBUTOR_ID
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sc
OUTPUT_VARIABLE MYX_CMAKE_LSB_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sr
OUTPUT_VARIABLE MYX_CMAKE_LSB_RELEASE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# cmake-format: on
endif()
endif()

View File

@ -4,5 +4,5 @@
include_guard(GLOBAL) include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.8.0" AND CMAKE_GENERATOR MATCHES Ninja) if(${CMAKE_VERSION} VERSION_LESS "3.8.0" AND CMAKE_GENERATOR MATCHES Ninja)
myx_message_error("Myx: Old CMake versions should use Makefile generator") myx_message_send_error("Myx: Old CMake versions should use Makefile generator")
endif() endif()

View File

@ -1,45 +1,53 @@
include_guard(GLOBAL) include_guard(GLOBAL)
function(myx_qt5_target_setup NAME) function(myx_qt5_target_setup TARGET_NAME)
set(options) set(options)
set(oneValueArgs) set(oneValueArgs)
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS) set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 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}) foreach(iter ${ARG_COMPONENTS})
if(target_type STREQUAL "INTERFACE_LIBRARY") 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() else()
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS}) target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
endif()
if(NOT iter STREQUAL "LinguistTools")
if(__target_type STREQUAL "EXECUTABLE")
target_link_libraries(${TARGET_NAME} PRIVATE "Qt5::${iter}")
endif()
if(__target_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(${TARGET_NAME} PUBLIC "Qt5::${iter}")
endif()
if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (__target_type STREQUAL "OBJECT_LIBRARY"))
target_link_libraries(${TARGET_NAME} PUBLIC "Qt5::${iter}")
endif()
endif() endif()
if(target_type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools")
target_link_libraries(${NAME} PRIVATE "Qt5::${iter}")
endif()
endforeach() endforeach()
foreach(iter ${ARG_PRIVATE}) foreach(iter ${ARG_PRIVATE})
if(target_type STREQUAL "INTERFACE_LIBRARY") 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() else()
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS}) target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
endif() endif()
endforeach() endforeach()
if(target_type STREQUAL "EXECUTABLE") 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() endif()
if(ARG_PUBLIC_MOC) if(ARG_PUBLIC_MOC)
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}") set_property(TARGET ${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 TR_FILES ${ARG_PUBLIC_MOC})
endif() endif()
if(ARG_PRIVATE_MOC) if(ARG_PRIVATE_MOC)
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}") set_property(TARGET ${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 TR_FILES ${ARG_PRIVATE_MOC})
endif() endif()
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC) if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
@ -52,42 +60,46 @@ function(myx_qt5_target_setup NAME)
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS) if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
qt5_wrap_ui(ui_h ${ARG_UI}) 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 # TODO
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR}) target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
endif() endif()
# Перечень файлов, подлежащих переводу # Перечень файлов, подлежащих переводу
if(target_type STREQUAL "INTERFACE_LIBRARY") if(__target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(tr ${NAME} INTERFACE_TR_FILES) get_target_property(tr ${TARGET_NAME} INTERFACE_TR_FILES)
else() else()
get_target_property(tr ${NAME} TR_FILES) get_target_property(tr ${TARGET_NAME} TR_FILES)
endif() endif()
# Формирование файла ресурсов с переводами # Формирование файла ресурсов с переводами
if("LinguistTools" IN_LIST ARG_COMPONENTS AND tr) 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 # Для каждого языка, указанное в параметре LANGS
foreach(iter ${ARG_LANGS}) foreach(iter ${ARG_LANGS})
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n # Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
# и его компиляция в каталог ${PROJECT_BINARY_DIR} # и его компиляция в каталог ${PROJECT_BINARY_DIR}
qt5_create_translation(qm ${tr} 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}) OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
# Добавление записи для скомпилированного файла переводов в ресурсный файл # Добавление записи для скомпилированного файла переводов в ресурсный файл
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc
"<file alias=\"${NAME}_${iter}\">${NAME}_${iter}.qm</file>\n") "<file alias=\"${TARGET_NAME}_${iter}\">${TARGET_NAME}_${iter}.qm</file>\n")
# Добавление скомпилированного файла переводов к списку зависимостей для цели # Добавление скомпилированного файла переводов к списку зависимостей для цели
target_sources(${NAME} PRIVATE ${qm}) target_sources(${TARGET_NAME} PRIVATE ${qm})
endforeach() 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) qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
target_sources(${NAME} PRIVATE ${qrc_l10n}) target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n})
endif() endif()
unset(tr) unset(tr)
target_sources(${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

@ -1,59 +1,59 @@
include_guard(GLOBAL) include_guard(GLOBAL)
function(myx_target_setup NAME) function(myx_target_setup TARGET_NAME)
set(options) set(options)
set(oneValueArgs PCH) set(oneValueArgs PCH)
set(multiValueArgs COMPILE_DEFINITIONS PACKAGES LINK_LIBRARIES 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}) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT TARGET ${NAME}) if(NOT TARGET ${TARGET_NAME})
myx_message_fatal_error("Target ${NAME} does not exists.") myx_message_fatal_error("Target ${TARGET_NAME} does not exists.")
endif() 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}) foreach(iter ${ARG_PACKAGES})
target_include_directories(${NAME} PRIVATE ${${iter}_INCLUDE_DIRS}) target_include_directories(${TARGET_NAME} PRIVATE ${${iter}_INCLUDE_DIRS})
target_compile_definitions(${NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS}) target_compile_definitions(${TARGET_NAME} PRIVATE ${${iter}_COMPILE_DEFINITIONS})
endforeach() endforeach()
target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
if(ARG_CPP) if(ARG_CPP)
set_property(TARGET ${NAME} APPEND PROPERTY CPP_FILES ${ARG_CPP}) set_property(TARGET ${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 TR_FILES ${ARG_CPP})
endif() endif()
if(ARG_PUBLIC_HEADERS) if(ARG_PUBLIC_HEADERS)
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_HEADERS}") set_property(TARGET ${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 TR_FILES ${ARG_PUBLIC_HEADERS})
endif() endif()
if(ARG_PRIVATE_HEADERS) if(ARG_PRIVATE_HEADERS)
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_HEADERS}") set_property(TARGET ${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 TR_FILES ${ARG_PRIVATE_HEADERS})
endif() endif()
if(ARG_PCH) if(ARG_PCH)
if((${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16) AND (PROJECT_IS_TOP_LEVEL OR MYX_USE_LOCAL_DIRECTORIES)) 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() else()
target_compile_options(${NAME} PRIVATE -include ${ARG_PCH}) target_compile_options(${TARGET_NAME} PRIVATE -include ${ARG_PCH})
endif() 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() 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 target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>) $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
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")
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/include") if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>) $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
@ -63,65 +63,62 @@ function(myx_target_setup NAME)
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}>) $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}>)
endif() endif()
set_target_properties(${NAME} PROPERTIES set_target_properties(${TARGET_NAME} PROPERTIES
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
) )
if(CMAKE_CXX_COMPILE_OPTIONS_PIE) 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() endif()
install(TARGETS ${NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS ${TARGET_NAME} COMPONENT MAIN RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()
if(${target_type} STREQUAL "INTERFACE_LIBRARY") target_sources(${TARGET_NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
target_sources(${NAME} INTERFACE $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>) target_sources(${TARGET_NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS})
else() target_sources(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
target_sources(${NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>) target_compile_definitions(${TARGET_NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
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()
# CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY` # CMake до версии 3.12 не умеет извлекать из целей типа `OBJECT_LIBRARY`
# информацию о заголовочных файлах. Это обход. # информацию о заголовочных файлах. Это обход.
if(${CMAKE_VERSION} VERSION_GREATER "3.11.99") 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() else()
if((NOT ${target_type} STREQUAL "OBJECT_LIBRARY") AND if((NOT ${__target_type} STREQUAL "OBJECT_LIBRARY") AND
(NOT ${target_type} STREQUAL "EXECUTABLE")) (NOT ${__target_type} STREQUAL "EXECUTABLE"))
target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES}) target_link_libraries(${TARGET_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
elseif(${target_type} STREQUAL "INTERFACE")
target_link_libraries(${NAME} INTERFACE ${ARG_LINK_LIBRARIES})
else() else()
foreach(link_library ${ARG_LINK_LIBRARIES}) foreach(__link_library ${ARG_LINK_LIBRARIES})
if(TARGET ${link_library}) if(TARGET ${__link_library})
get_target_property(lib_type ${link_library} TYPE) get_target_property(__lib_type ${__link_library} TYPE)
if(lib_type) if(__lib_type)
get_target_property(include_dir ${link_library} INTERFACE_INCLUDE_DIRECTORIES) get_target_property(__include_dirs ${__link_library} INTERFACE_INCLUDE_DIRECTORIES)
if(include_dir) if(__include_dirs)
target_include_directories(${NAME} PUBLIC ${include_dir}) target_include_directories(${TARGET_NAME} PUBLIC ${__include_dirs})
endif() endif()
if(${target_type} STREQUAL "EXECUTABLE") if(${__target_type} STREQUAL "EXECUTABLE")
if(${lib_type} STREQUAL "OBJECT_LIBRARY") if(${__lib_type} STREQUAL "OBJECT_LIBRARY")
if(TARGET ${link_library}_static) if(TARGET ${__link_library}_static)
target_link_libraries(${NAME} PRIVATE ${link_library}_static) target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_static)
else() else()
target_link_libraries(${NAME} PRIVATE ${link_library}_shared) target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library}_shared)
endif() endif()
else() else()
target_link_libraries(${NAME} PRIVATE ${link_library}) target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library})
endif() endif()
endif() endif()
endif() endif()
else()
target_link_libraries(${TARGET_NAME} PRIVATE ${__link_library})
endif() endif()
endforeach() 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} ${ARG_INTERFACE_HEADERS} FILES ${ARG_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT DEV COMPONENT DEV
) )

View File

@ -1,35 +0,0 @@
include_guard(GLOBAL)
# Предпочтительные пути к утилитам для компоновки
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# cmake-format: off
# Astra Linux Smolensk 1.5
if((MYX_CMAKE_LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE") AND
(MYX_CMAKE_LSB_CODENAME STREQUAL "smolensk") AND
(MYX_CMAKE_LSB_RELEASE_VERSION STREQUAL "1.5"))
find_program(CMAKE_GCC_AR NAMES "/usr/bin/x86_64-linux-gnu-gcc-ar-4.7")
find_program(CMAKE_GCC_NM NAMES "/usr/bin/x86_64-linux-gnu-gcc-nm-4.7")
find_program(CMAKE_GCC_RANLIB NAMES "/usr/bin/x86_64-linux-gnu-gcc-ranlib-4.7")
# Elbrus E2K
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
find_program(CMAKE_GCC_AR NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/ar")
find_program(CMAKE_GCC_NM NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/nm")
find_program(CMAKE_GCC_RANLIB NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/ranlib")
# Другие версии Linux
else()
find_program(CMAKE_GCC_AR NAMES "gcc-ar" "ar")
find_program(CMAKE_GCC_NM NAMES "gcc-nm" "nm")
find_program(CMAKE_GCC_RANLIB NAMES "gcc-ranlib" "ranlib")
endif()
# cmake-format: on
if(CMAKE_GCC_AR)
set(CMAKE_AR ${CMAKE_GCC_AR} CACHE STRING "" FORCE)
endif()
if(CMAKE_GCC_NM)
set(CMAKE_NM ${CMAKE_GCC_NM} CACHE STRING "" FORCE)
endif()
if(CMAKE_GCC_RANLIB)
set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE STRING "" FORCE)
endif()
endif()

View File

@ -6,7 +6,7 @@
include_guard(GLOBAL) include_guard(GLOBAL)
if(NOT TARGET uninstall) if((NOT TARGET uninstall) AND (NOT DEFINED ENV{SAPR_PREFIX}))
configure_file(${CMAKE_CURRENT_LIST_DIR}/uninstall.cmake.in configure_file(${CMAKE_CURRENT_LIST_DIR}/uninstall.cmake.in
${CMAKE_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY) ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake)

View File

@ -1,14 +1,16 @@
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}") set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif() endif()
function(myx_doc_doxygen NAME) function(myx_doc_doxygen TARGET_NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT}) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT})
endif() endif()
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
return()
endif()
find_package(Doxygen) find_package(Doxygen)
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
set(DOXYGEN_FOUND ON CACHE STRING "Doxygen documentation generator enabled" FORCE) 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) set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
endif() endif()
set(target "myx-doc-doxygen-${NAME}") set(target myx-doc-doxygen-${TARGET_NAME})
if(NOT DOXYGEN_FOUND) if(TARGET ${target})
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build") myx_message_warning("Target ${target} already defined")
return() return()
endif() endif()
if(TARGET ${target}) if(NOT DOXYGEN_FOUND)
myx_message_warning("Target ${target} already defined") add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
return() return()
endif() endif()

View File

@ -5,12 +5,13 @@ myx_generate_git_info_header
Вспомогательная функция для автоматической генерации заголовочного Вспомогательная функция для автоматической генерации заголовочного
файла, содержащего информацию о текущем состоянии репозитория git:: файла, содержащего информацию о текущем состоянии репозитория git::
myx_generate_git_info_header(TARGET BASE_FILENAME myx_generate_git_info_header(TARGET_NAME BASE_FILENAME
[ PREFIX prefix ] ) [ PREFIX prefix ] )
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл, Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
и `BASE_FILENAME` - имя генерируемого заголовочного файла. Дополнительный аргумент заголовочный файл, и `BASE_FILENAME` - имя генерируемого заголовочного
`PREFIX` добавляет префикс к генерируемым именам переменных. файла. Дополнительный аргумент `PREFIX` добавляет префикс к генерируемым
именам переменных.
#]=======================================================================] #]=======================================================================]
@ -20,7 +21,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}") set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif() 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") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT}) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif() endif()
@ -30,24 +31,26 @@ function(myx_generate_git_info_header target base_filename)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 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) if(ARG_PREFIX)
string(APPEND ARG_PREFIX "_") string(APPEND ARG_PREFIX "_")
string(REPLACE "-" "_" PREFIX ${ARG_PREFIX}) string(REPLACE "-" "_" __prefix ${ARG_PREFIX})
endif() endif()
# cmake-format: off # cmake-format: off
if(NOT TARGET ${target}-git-info-header) if(NOT TARGET ${TARGET_NAME}-git-info-header)
add_custom_target(${target}-git-info-header ALL add_custom_target(${TARGET_NAME}-git-info-header ALL
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -DPREFIX=${PREFIX} ${CMAKE_COMMAND} -DGIT_INFO_FILE=${__filename} -DPREFIX=${__prefix}
-P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake -P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake
BYPRODUCTS ${filename} BYPRODUCTS ${__filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
endif() endif()
# cmake-format: on # cmake-format: on
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename}) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
target_sources(${target} PRIVATE ${filename}) target_sources(${TARGET_NAME} PRIVATE ${__filename})
add_dependencies(${TARGET_NAME} ${TARGET_NAME}-git-info-header)
endfunction() endfunction()

View File

@ -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` - имя цели, с которой связан заголовочный файл, Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
и `BASE_FILENAME` - имя генерируемого заголовочного файла. заголовочный файл, и `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}") set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif() 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") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT}) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif() endif()
@ -27,9 +27,9 @@ function(myx_generate_private_config_header target base_filename)
myx_project_version_int() myx_project_version_int()
get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT) get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}") set(__filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${filename}) configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${__filename})
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename}) set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
target_sources(${target} PRIVATE ${filename}) target_sources(${TARGET_NAME} PRIVATE ${__filename})
endfunction() endfunction()

View File

@ -1,33 +1,34 @@
include_guard(GLOBAL) include_guard(GLOBAL)
# based on https://github.com/bluescarni/yacma # Добавление флага к списку используемых после проверки
# возможности его использования текущим компилятором
# Основано на https://github.com/bluescarni/yacma
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
macro(check_enable_cxx_compiler_flag flag) macro(check_enable_cxx_compiler_flag FLAG)
set(options) set(options)
set(oneValueArgs TARGET) set(oneValueArgs TARGET)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(CMAKE_REQUIRED_QUIET TRUE) set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("${flag}" check_cxx_flag) check_cxx_compiler_flag("${FLAG}" check_cxx_flag)
unset(CMAKE_REQUIRED_QUIET) unset(CMAKE_REQUIRED_QUIET)
if(check_cxx_flag) if(check_cxx_flag)
myx_message_notice("'${flag}': flag is supported.") myx_message_notice("'${FLAG}': flag is supported.")
if(ARG_TARGET) if(ARG_TARGET)
target_compile_options(${ARG_TARGET} PUBLIC ${flag}) target_compile_options(${ARG_TARGET} PUBLIC ${FLAG})
else() else()
add_compile_options(${flag}) add_compile_options(${FLAG})
endif() endif()
else() else()
myx_message_status("'${flag}': flag is NOT supported.") myx_message_status("'${FLAG}': flag is NOT supported.")
endif() endif()
unset(check_cxx_flag CACHE) unset(check_cxx_flag CACHE)
foreach(iter IN LISTS oneValueArgs multiValueArgs) foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${iter}) unset(ARG_${__iter})
endforeach() endforeach()
unset(ARG_UNPARSED_ARGUMENTS) unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs) unset(multiValueArgs)

View File

@ -1,11 +1,13 @@
include_guard(GLOBAL) include_guard(GLOBAL)
macro(myx_create_symlink original linkname) # Создание символических ссылок
if(NOT EXISTS ${linkname}) macro(myx_create_symlink ORIGINAL_FILENAME 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_FILENAME} ${LINKNAME})
else() else()
file(CREATE_LINK ${original} ${linkname} SYMBOLIC) file(CREATE_LINK ${ORIGINAL_FILENAME} ${LINKNAME} SYMBOLIC)
endif() endif()
endif() endif()
endmacro(myx_create_symlink original linkname) endmacro(myx_create_symlink ORIGINAL_FILENAME LINKNAME)

View File

@ -3,7 +3,7 @@ include_guard(GLOBAL)
macro(myx_find_required_packages) macro(myx_find_required_packages)
set(options) set(options)
set(oneValueArgs) set(oneValueArgs)
set(multiValueArgs PACKAGES Boost Qt5 Qt5Private) set(multiValueArgs PACKAGES Boost Qt5 Qt5Private Qt6 Qt6Private)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
foreach(iter ${ARG_PACKAGES}) foreach(iter ${ARG_PACKAGES})
@ -24,8 +24,18 @@ macro(myx_find_required_packages)
endforeach() endforeach()
endif() endif()
foreach(iter IN LISTS oneValueArgs multiValueArgs) if(ARG_Qt6)
unset(ARG_${iter}) find_package(Qt6 COMPONENTS ${ARG_Qt6} REQUIRED)
endif()
if(ARG_Qt6Private)
foreach(iter ${ARG_Qt6Private})
find_package("Qt6${iter}" COMPONENTS Private REQUIRED)
endforeach()
endif()
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach() endforeach()
unset(ARG_UNPARSED_ARGUMENTS) unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs) unset(multiValueArgs)

View File

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

View File

@ -1,17 +1,17 @@
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}") set(MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif() endif()
find_program(UNCRUSTIFY_EXE NAMES uncrustify) find_program(UNCRUSTIFY_EXE NAMES uncrustify)
function(myx_uncrustify NAME) function(myx_uncrustify TARGET_NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0") if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT}) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
endif() endif()
myx_skip_external_target(${NAME}) if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
return()
endif()
set(options) set(options)
set(oneValueArgs CONFIG) set(oneValueArgs CONFIG)
@ -19,10 +19,7 @@ function(myx_uncrustify NAME)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_CONFIG) if(NOT ARG_CONFIG)
set(ARG_CONFIG "${PROJECT_SOURCE_DIR}/.uncrustify.cfg") set(ARG_CONFIG "${PROJECT_SOURCE_DIR}/uncrustify.cfg")
if(NOT EXISTS ${ARG_CONFIG})
set(ARG_CONFIG "${CMAKE_SOURCE_DIR}/.uncrustify.cfg")
endif()
endif() endif()
if(NOT EXISTS ${ARG_CONFIG}) if(NOT EXISTS ${ARG_CONFIG})
@ -46,44 +43,54 @@ function(myx_uncrustify NAME)
endif() endif()
# Динамически сгенерированные файлы исключаются # Динамически сгенерированные файлы исключаются
get_target_property(target_type ${NAME} TYPE) get_target_property(__target_type ${TARGET_NAME} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY") if((${__target_type} STREQUAL "INTERFACE_LIBRARY") AND (${CMAKE_VERSION} VERSION_LESS "3.17.0"))
get_target_property(s ${NAME} INTERFACE_SOURCES) get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES)
if(__s1)
list(APPEND __all_sources ${__s1})
endif()
else() else()
get_target_property(s ${NAME} SOURCES) get_target_property(__s2 ${TARGET_NAME} SOURCES)
if(__s2)
list(APPEND __all_sources ${__s2})
endif()
endif() endif()
foreach(iter ${s})
foreach(iter ${__all_sources})
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos) string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
if(pos EQUAL -1) if(pos EQUAL -1)
list(APPEND src ${iter}) list(APPEND __sources ${iter})
endif() endif()
endforeach() endforeach()
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg
target_sources(${TARGET_NAME} PRIVATE ${ARG_CONFIG})
set(__fixed_config ${PROJECT_BINARY_DIR}/uncrustify-${TARGET_NAME}.cfg)
add_custom_command(OUTPUT ${__fixed_config}
DEPENDS ${ARG_CONFIG}
COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc
-c ${ARG_CONFIG} -c ${ARG_CONFIG} -o ${__fixed_config})
-o ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg) list(APPEND __options -c ${__fixed_config})
list(APPEND UNCRUSTIFY_OPTS -c ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg)
# cmake-format: off # cmake-format: off
add_custom_target(${NAME}-uncrustify-check add_custom_target(${TARGET_NAME}-uncrustify-check
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${src}) COMMAND ${UNCRUSTIFY_EXE} ${__options} --check ${__sources})
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup) list(APPEND __options --replace --no-backup)
add_custom_target(${NAME}-uncrustify add_custom_target(${TARGET_NAME}-uncrustify
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${src}) COMMAND ${UNCRUSTIFY_EXE} ${__options} --mtime ${__sources})
add_custom_target(${NAME}-uncrustify-append-comments add_custom_target(${TARGET_NAME}-uncrustify-append-comments
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} COMMAND ${UNCRUSTIFY_EXE} ${__options}
--set cmt_insert_class_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/classheader.txt --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_footer=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/filefooter.txt
--set cmt_insert_file_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fileheader.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_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 # cmake-format: on
add_dependencies(myx-uncrustify ${NAME}-uncrustify) add_dependencies(myx-uncrustify ${TARGET_NAME}-uncrustify)
add_dependencies(myx-uncrustify-check ${NAME}-uncrustify-check) add_dependencies(myx-uncrustify-check ${TARGET_NAME}-uncrustify-check)
add_dependencies(myx-uncrustify-append-comments ${NAME}-uncrustify-append-comments) add_dependencies(myx-uncrustify-append-comments ${TARGET_NAME}-uncrustify-append-comments)
endfunction() endfunction()

View File

@ -4,7 +4,7 @@
По умолчанию предполагается использование версии MyxCMake, По умолчанию предполагается использование версии MyxCMake,
файлы которой находятся в каталоге `cmake/myx` текущего проекта. файлы которой находятся в каталоге `cmake/myx` текущего проекта.
Для удобства разботки библиотеки MyxCMake можно указать путь Для удобства разработки библиотеки MyxCMake можно указать путь
к её репозиторию с помощью переменной проекта CMake `MYX_CMAKE_DIR` к её репозиторию с помощью переменной проекта CMake `MYX_CMAKE_DIR`
или переменной окружения `MYX_CMAKE_DIR`. или переменной окружения `MYX_CMAKE_DIR`.
@ -12,7 +12,7 @@
поиск версии в каталогах перечисленных в переменной `CMAKE_MODULES_DIR`. поиск версии в каталогах перечисленных в переменной `CMAKE_MODULES_DIR`.
Кроме того выполняется попытка поиска (MyxxCMake)[../../../../myxx] -- Кроме того выполняется попытка поиска (MyxxCMake)[../../../../myxx] --
расширения для библиотеки, позволяющиего в режиме разработки программного расширения для библиотеки, позволяющего в режиме разработки программного
проекта использовать дополнительные инструменты для его сопровождения. проекта использовать дополнительные инструменты для его сопровождения.
#]=======================================================================] #]=======================================================================]
@ -20,15 +20,15 @@ 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.19 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) find_package(MyxCMake 2.3.8 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.19 REQUIRED) find_package(MyxCMake 2.3.8 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)
myx_message_notice("=== MyxCMake directory: ${PROJECT_SOURCE_DIR}/cmake/myx ===") myx_message_notice("== MyxCMake directory: ${PROJECT_SOURCE_DIR}/cmake/myx ==")
endif() endif()
endif() endif()

View File

@ -1,4 +1,4 @@
# Uncrustify-0.75.0_f # Uncrustify-0.77.1_f
# #
# General options # General options
@ -195,6 +195,11 @@ sp_before_ptr_star = remove # ignore/add/remove/force/not_defined
# variable name. If set to ignore, sp_before_ptr_star is used instead. # variable name. If set to ignore, sp_before_ptr_star is used instead.
sp_before_unnamed_ptr_star = remove # ignore/add/remove/force/not_defined sp_before_unnamed_ptr_star = remove # ignore/add/remove/force/not_defined
# Add or remove space between a qualifier and a pointer star '*' that isn't
# followed by a variable name, as in '(char const *)'. If set to ignore,
# sp_before_ptr_star is used instead.
sp_qualifier_unnamed_ptr_star = ignore # ignore/add/remove/force/not_defined
# Add or remove space between pointer stars '*', as in 'int ***a;'. # Add or remove space between pointer stars '*', as in 'int ***a;'.
sp_between_ptr_star = remove # ignore/add/remove/force/not_defined sp_between_ptr_star = remove # ignore/add/remove/force/not_defined
@ -232,13 +237,24 @@ sp_ptr_star_func_type = remove # ignore/add/remove/force/not_defined
sp_ptr_star_paren = ignore # ignore/add/remove/force/not_defined sp_ptr_star_paren = ignore # ignore/add/remove/force/not_defined
# Add or remove space before a pointer star '*', if followed by a function # Add or remove space before a pointer star '*', if followed by a function
# prototype or function definition. # prototype or function definition. If set to ignore, sp_before_ptr_star is
# used instead.
sp_before_ptr_star_func = remove # ignore/add/remove/force/not_defined sp_before_ptr_star_func = remove # ignore/add/remove/force/not_defined
# Add or remove space between a qualifier and a pointer star '*' followed by
# the name of the function in a function prototype or definition, as in
# 'char const *foo()`. If set to ignore, sp_before_ptr_star is used instead.
sp_qualifier_ptr_star_func = ignore # ignore/add/remove/force/not_defined
# Add or remove space before a pointer star '*' in the trailing return of a # Add or remove space before a pointer star '*' in the trailing return of a
# function prototype or function definition. # function prototype or function definition.
sp_before_ptr_star_trailing = ignore # ignore/add/remove/force/not_defined sp_before_ptr_star_trailing = ignore # ignore/add/remove/force/not_defined
# Add or remove space between a qualifier and a pointer star '*' in the
# trailing return of a function prototype or function definition, as in
# 'auto foo() -> char const *'.
sp_qualifier_ptr_star_trailing = ignore # ignore/add/remove/force/not_defined
# Add or remove space before a reference sign '&'. # Add or remove space before a reference sign '&'.
sp_before_byref = remove # ignore/add/remove/force/not_defined sp_before_byref = remove # ignore/add/remove/force/not_defined
@ -392,11 +408,11 @@ sp_before_semi_for = remove # ignore/add/remove/force/not_defined
# Add or remove space before a semicolon of an empty left part of a for # Add or remove space before a semicolon of an empty left part of a for
# statement, as in 'for ( <here> ; ; )'. # statement, as in 'for ( <here> ; ; )'.
sp_before_semi_for_empty = remove # ignore/add/remove/force/not_defined sp_before_semi_for_empty = force # ignore/add/remove/force/not_defined
# Add or remove space between the semicolons of an empty middle part of a for # Add or remove space between the semicolons of an empty middle part of a for
# statement, as in 'for ( ; <here> ; )'. # statement, as in 'for ( ; <here> ; )'.
sp_between_semi_for_empty = remove # ignore/add/remove/force/not_defined sp_between_semi_for_empty = force # ignore/add/remove/force/not_defined
# Add or remove space after ';', except when followed by a comment. # Add or remove space after ';', except when followed by a comment.
# #
@ -410,7 +426,7 @@ sp_after_semi_for = force # ignore/add/remove/force/not_defined
# Add or remove space after the final semicolon of an empty part of a for # Add or remove space after the final semicolon of an empty part of a for
# statement, as in 'for ( ; ; <here> )'. # statement, as in 'for ( ; ; <here> )'.
sp_after_semi_for_empty = remove # ignore/add/remove/force/not_defined sp_after_semi_for_empty = force # ignore/add/remove/force/not_defined
# Add or remove space before '[' (except '[]'). # Add or remove space before '[' (except '[]').
sp_before_square = ignore # ignore/add/remove/force/not_defined sp_before_square = ignore # ignore/add/remove/force/not_defined
@ -447,15 +463,15 @@ sp_after_comma = force # ignore/add/remove/force/not_defined
# Default: remove # Default: remove
sp_before_comma = remove # ignore/add/remove/force/not_defined sp_before_comma = remove # ignore/add/remove/force/not_defined
# (C#) Add or remove space between ',' and ']' in multidimensional array type # (C#, Vala) Add or remove space between ',' and ']' in multidimensional array type
# like 'int[,,]'. # like 'int[,,]'.
sp_after_mdatype_commas = ignore # ignore/add/remove/force/not_defined sp_after_mdatype_commas = ignore # ignore/add/remove/force/not_defined
# (C#) Add or remove space between '[' and ',' in multidimensional array type # (C#, Vala) Add or remove space between '[' and ',' in multidimensional array type
# like 'int[,,]'. # like 'int[,,]'.
sp_before_mdatype_commas = ignore # ignore/add/remove/force/not_defined sp_before_mdatype_commas = ignore # ignore/add/remove/force/not_defined
# (C#) Add or remove space between ',' in multidimensional array type # (C#, Vala) Add or remove space between ',' in multidimensional array type
# like 'int[,,]'. # like 'int[,,]'.
sp_between_mdatype_commas = ignore # ignore/add/remove/force/not_defined sp_between_mdatype_commas = ignore # ignore/add/remove/force/not_defined
@ -628,6 +644,16 @@ sp_inside_fparens = remove # ignore/add/remove/force/not_defined
# Add or remove space inside function '(' and ')'. # Add or remove space inside function '(' and ')'.
sp_inside_fparen = force # ignore/add/remove/force/not_defined sp_inside_fparen = force # ignore/add/remove/force/not_defined
# Add or remove space inside user functor '(' and ')'.
sp_func_call_user_inside_rparen = ignore # ignore/add/remove/force/not_defined
# Add or remove space inside empty functor '()'.
# Overrides sp_after_angle unless use_sp_after_angle_always is set to true.
sp_inside_rparens = ignore # ignore/add/remove/force/not_defined
# Add or remove space inside functor '(' and ')'.
sp_inside_rparen = ignore # ignore/add/remove/force/not_defined
# Add or remove space inside the first parentheses in a function type, as in # Add or remove space inside the first parentheses in a function type, as in
# 'void (*x)(...)'. # 'void (*x)(...)'.
sp_inside_tparen = ignore # ignore/add/remove/force/not_defined sp_inside_tparen = ignore # ignore/add/remove/force/not_defined
@ -744,10 +770,10 @@ sp_macro = ignore # ignore/add/remove/force/not_defined
sp_macro_func = ignore # ignore/add/remove/force/not_defined sp_macro_func = ignore # ignore/add/remove/force/not_defined
# Add or remove space between 'else' and '{' if on the same line. # Add or remove space between 'else' and '{' if on the same line.
sp_else_brace = ignore # ignore/add/remove/force/not_defined sp_else_brace = force # ignore/add/remove/force/not_defined
# Add or remove space between '}' and 'else' if on the same line. # Add or remove space between '}' and 'else' if on the same line.
sp_brace_else = ignore # ignore/add/remove/force/not_defined sp_brace_else = force # ignore/add/remove/force/not_defined
# Add or remove space between '}' and the name of a typedef on the same line. # Add or remove space between '}' and the name of a typedef on the same line.
sp_brace_typedef = ignore # ignore/add/remove/force/not_defined sp_brace_typedef = ignore # ignore/add/remove/force/not_defined
@ -782,7 +808,7 @@ sp_getset_brace = ignore # ignore/add/remove/force/not_defined
# Add or remove space between a variable and '{' for C++ uniform # Add or remove space between a variable and '{' for C++ uniform
# initialization. # initialization.
sp_word_brace_init_lst = force # ignore/add/remove/force/not_defined sp_word_brace_init_lst = add # ignore/add/remove/force/not_defined
# Add or remove space between a variable and '{' for a namespace. # Add or remove space between a variable and '{' for a namespace.
# #
@ -965,7 +991,15 @@ sp_before_for_colon = remove # ignore/add/remove/force/not_defined
sp_extern_paren = ignore # ignore/add/remove/force/not_defined sp_extern_paren = ignore # ignore/add/remove/force/not_defined
# Add or remove space after the opening of a C++ comment, as in '// <here> A'. # Add or remove space after the opening of a C++ comment, as in '// <here> A'.
sp_cmt_cpp_start = ignore # ignore/add/remove/force/not_defined sp_cmt_cpp_start = add # ignore/add/remove/force/not_defined
# remove space after the '//' and the pvs command '-V1234',
# only works with sp_cmt_cpp_start set to add or force.
sp_cmt_cpp_pvs = true # true/false
# remove space after the '//' and the command 'lint',
# only works with sp_cmt_cpp_start set to add or force.
sp_cmt_cpp_lint = true # true/false
# Add or remove space in a C++ region marker comment, as in '// <here> BEGIN'. # Add or remove space in a C++ region marker comment, as in '// <here> BEGIN'.
# A region marker is defined as a comment which is not preceded by other text # A region marker is defined as a comment which is not preceded by other text
@ -995,7 +1029,7 @@ sp_between_new_paren = ignore # ignore/add/remove/force/not_defined
# Add or remove space between ')' and type in 'new(foo) BAR'. # Add or remove space between ')' and type in 'new(foo) BAR'.
sp_after_newop_paren = ignore # ignore/add/remove/force/not_defined sp_after_newop_paren = ignore # ignore/add/remove/force/not_defined
# Add or remove space inside parenthesis of the new operator # Add or remove space inside parentheses of the new operator
# as in 'new(foo) BAR'. # as in 'new(foo) BAR'.
sp_inside_newop_paren = ignore # ignore/add/remove/force/not_defined sp_inside_newop_paren = ignore # ignore/add/remove/force/not_defined
@ -1537,7 +1571,7 @@ indent_using_block = true # true/false
# How to indent the continuation of ternary operator. # How to indent the continuation of ternary operator.
# #
# 0: Off (default) # 0: Off (default)
# 1: When the `if_false` is a continuation, indent it under `if_false` # 1: When the `if_false` is a continuation, indent it under the `if_true` branch
# 2: When the `:` is a continuation, indent it under `?` # 2: When the `:` is a continuation, indent it under `?`
indent_ternary_operator = 2 # unsigned number indent_ternary_operator = 2 # unsigned number
@ -1565,9 +1599,14 @@ donot_indent_func_def_close_paren = false # true/false
# Newline adding and removing options # Newline adding and removing options
# #
# Whether to collapse empty blocks between '{' and '}'. # Whether to collapse empty blocks between '{' and '}' except for functions.
# If true, overrides nl_inside_empty_func # Use nl_collapse_empty_body_functions to specify how empty function braces
nl_collapse_empty_body = false # true/false # should be formatted.
nl_collapse_empty_body = true # true/false
# Whether to collapse empty blocks between '{' and '}' for functions only.
# If true, overrides nl_inside_empty_func.
nl_collapse_empty_body_functions = true # true/false
# Don't split one-line braced assignments, as in 'foo_t f = { 1, 2 };'. # Don't split one-line braced assignments, as in 'foo_t f = { 1, 2 };'.
nl_assign_leave_one_liners = true # true/false nl_assign_leave_one_liners = true # true/false
@ -1656,7 +1695,7 @@ nl_after_square_assign = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between a function call's ')' and '{', as in # Add or remove newline between a function call's ')' and '{', as in
# 'list_for_each(item, &list) { }'. # 'list_for_each(item, &list) { }'.
nl_fcall_brace = add # ignore/add/remove/force/not_defined nl_fcall_brace = force # ignore/add/remove/force/not_defined
# Add or remove newline between 'enum' and '{'. # Add or remove newline between 'enum' and '{'.
nl_enum_brace = force # ignore/add/remove/force/not_defined nl_enum_brace = force # ignore/add/remove/force/not_defined
@ -1680,17 +1719,17 @@ nl_struct_brace = force # ignore/add/remove/force/not_defined
nl_union_brace = force # ignore/add/remove/force/not_defined nl_union_brace = force # ignore/add/remove/force/not_defined
# Add or remove newline between 'if' and '{'. # Add or remove newline between 'if' and '{'.
nl_if_brace = force # ignore/add/remove/force/not_defined nl_if_brace = remove # ignore/add/remove/force/not_defined
# Add or remove newline between '}' and 'else'. # Add or remove newline between '}' and 'else'.
nl_brace_else = force # ignore/add/remove/force/not_defined nl_brace_else = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between 'else if' and '{'. If set to ignore, # Add or remove newline between 'else if' and '{'. If set to ignore,
# nl_if_brace is used instead. # nl_if_brace is used instead.
nl_elseif_brace = force # ignore/add/remove/force/not_defined nl_elseif_brace = force # ignore/add/remove/force/not_defined
# Add or remove newline between 'else' and '{'. # Add or remove newline between 'else' and '{'.
nl_else_brace = force # ignore/add/remove/force/not_defined nl_else_brace = remove # ignore/add/remove/force/not_defined
# Add or remove newline between 'else' and 'if'. # Add or remove newline between 'else' and 'if'.
nl_else_if = force # ignore/add/remove/force/not_defined nl_else_if = force # ignore/add/remove/force/not_defined
@ -1714,7 +1753,7 @@ nl_try_brace = ignore # ignore/add/remove/force/not_defined
nl_getset_brace = ignore # ignore/add/remove/force/not_defined nl_getset_brace = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between 'for' and '{'. # Add or remove newline between 'for' and '{'.
nl_for_brace = add # ignore/add/remove/force/not_defined nl_for_brace = remove # ignore/add/remove/force/not_defined
# Add or remove newline before the '{' of a 'catch' statement, as in # Add or remove newline before the '{' of a 'catch' statement, as in
# 'catch (decl) <here> {'. # 'catch (decl) <here> {'.
@ -1738,7 +1777,7 @@ nl_brace_square = ignore # ignore/add/remove/force/not_defined
nl_brace_fparen = ignore # ignore/add/remove/force/not_defined nl_brace_fparen = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between 'while' and '{'. # Add or remove newline between 'while' and '{'.
nl_while_brace = add # ignore/add/remove/force/not_defined nl_while_brace = remove # ignore/add/remove/force/not_defined
# (D) Add or remove newline between 'scope (x)' and '{'. # (D) Add or remove newline between 'scope (x)' and '{'.
nl_scope_brace = ignore # ignore/add/remove/force/not_defined nl_scope_brace = ignore # ignore/add/remove/force/not_defined
@ -1763,7 +1802,7 @@ nl_do_brace = ignore # ignore/add/remove/force/not_defined
nl_brace_while = ignore # ignore/add/remove/force/not_defined nl_brace_while = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between 'switch' and '{'. # Add or remove newline between 'switch' and '{'.
nl_switch_brace = add # ignore/add/remove/force/not_defined nl_switch_brace = remove # ignore/add/remove/force/not_defined
# Add or remove newline between 'synchronized' and '{'. # Add or remove newline between 'synchronized' and '{'.
nl_synchronized_brace = ignore # ignore/add/remove/force/not_defined nl_synchronized_brace = ignore # ignore/add/remove/force/not_defined
@ -1862,7 +1901,7 @@ nl_template_var = ignore # ignore/add/remove/force/not_defined
nl_template_using = ignore # ignore/add/remove/force/not_defined nl_template_using = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between 'class' and '{'. # Add or remove newline between 'class' and '{'.
nl_class_brace = add # ignore/add/remove/force/not_defined nl_class_brace = force # ignore/add/remove/force/not_defined
# Add or remove newline before or after (depending on pos_class_comma, # Add or remove newline before or after (depending on pos_class_comma,
# may not be IGNORE) each',' in the base class list. # may not be IGNORE) each',' in the base class list.
@ -2021,6 +2060,12 @@ nl_template_end = false # true/false
# See nl_oc_msg_leave_one_liner. # See nl_oc_msg_leave_one_liner.
nl_oc_msg_args = false # true/false nl_oc_msg_args = false # true/false
# (OC) Minimum number of Objective-C message parameters before applying nl_oc_msg_args.
nl_oc_msg_args_min_params = 0 # unsigned number
# (OC) Max code width of Objective-C message before applying nl_oc_msg_args.
nl_oc_msg_args_max_code_width = 0 # unsigned number
# Add or remove newline between function signature and '{'. # Add or remove newline between function signature and '{'.
nl_fdef_brace = add # ignore/add/remove/force/not_defined nl_fdef_brace = add # ignore/add/remove/force/not_defined
@ -2034,6 +2079,9 @@ nl_cpp_ldef_brace = remove # ignore/add/remove/force/not_defined
# Add or remove newline between 'return' and the return expression. # Add or remove newline between 'return' and the return expression.
nl_return_expr = ignore # ignore/add/remove/force/not_defined nl_return_expr = ignore # ignore/add/remove/force/not_defined
# Add or remove newline between 'throw' and the throw expression.
nl_throw_expr = ignore # ignore/add/remove/force/not_defined
# Whether to add a newline after semicolons, except in 'for' statements. # Whether to add a newline after semicolons, except in 'for' statements.
nl_after_semicolon = false # true/false nl_after_semicolon = false # true/false
@ -2227,7 +2275,7 @@ nl_max_blank_in_func = 2 # unsigned number
# The number of newlines inside an empty function body. # The number of newlines inside an empty function body.
# This option overrides eat_blanks_after_open_brace and # This option overrides eat_blanks_after_open_brace and
# eat_blanks_before_close_brace, but is ignored when # eat_blanks_before_close_brace, but is ignored when
# nl_collapse_empty_body=true # nl_collapse_empty_body_functions=true
nl_inside_empty_func = 0 # unsigned number nl_inside_empty_func = 0 # unsigned number
# The number of newlines before a function prototype. # The number of newlines before a function prototype.
@ -2279,12 +2327,6 @@ nl_after_func_body_class = 2 # unsigned number
# Overrides nl_after_func_body and nl_after_func_body_class. # Overrides nl_after_func_body and nl_after_func_body_class.
nl_after_func_body_one_liner = 0 # unsigned number nl_after_func_body_one_liner = 0 # unsigned number
# The number of blank lines after a block of variable definitions at the top
# of a function body.
#
# 0: No change (default).
nl_func_var_def_blk = 1 # unsigned number
# The number of newlines before a block of typedefs. If nl_after_access_spec # The number of newlines before a block of typedefs. If nl_after_access_spec
# is non-zero, that option takes precedence. # is non-zero, that option takes precedence.
# #
@ -2294,22 +2336,34 @@ nl_typedef_blk_start = 0 # unsigned number
# The number of newlines after a block of typedefs. # The number of newlines after a block of typedefs.
# #
# 0: No change (default). # 0: No change (default).
nl_typedef_blk_end = 1 # unsigned number nl_typedef_blk_end = 0 # unsigned number
# The maximum number of consecutive newlines within a block of typedefs. # The maximum number of consecutive newlines within a block of typedefs.
# #
# 0: No change (default). # 0: No change (default).
nl_typedef_blk_in = 0 # unsigned number nl_typedef_blk_in = 0 # unsigned number
# The number of empty newlines before a block of variable definitions # The minimum number of blank lines after a block of variable definitions
# not at the top of a function body. If nl_after_access_spec is non-zero, # at the top of a function body. If any preprocessor directives appear
# that option takes precedence. # between the opening brace of the function and the variable block, then
# it is considered as not at the top of the function.Newlines are added
# before trailing preprocessor directives, if any exist.
# #
# 0: No change (default). # 0: No change (default).
nl_var_def_blk_start = 1 # unsigned number nl_var_def_blk_end_func_top = 0 # unsigned number
# The number of empty newlines after a block of variable definitions # The minimum number of empty newlines before a block of variable definitions
# not at the top of a function body. # not at the top of a function body. If nl_after_access_spec is non-zero,
# that option takes precedence. Newlines are not added at the top of the
# file or just after an opening brace. Newlines are added above any
# preprocessor directives before the block.
#
# 0: No change (default).
nl_var_def_blk_start = 0 # unsigned number
# The minimum number of empty newlines after a block of variable definitions
# not at the top of a function body. Newlines are not added if the block
# is at the bottom of the file or just before a preprocessor directive.
# #
# 0: No change (default). # 0: No change (default).
nl_var_def_blk_end = 0 # unsigned number nl_var_def_blk_end = 0 # unsigned number
@ -2625,11 +2679,6 @@ align_var_def_inline = false # true/false
# 0: Don't align (default). # 0: Don't align (default).
align_assign_span = 1 # unsigned number align_assign_span = 1 # unsigned number
# The span for aligning on '{' in braced init list.
#
# 0: Don't align (default).
align_braced_init_list_span = 0 # unsigned number
# The span for aligning on '=' in function prototype modifier. # The span for aligning on '=' in function prototype modifier.
# #
# 0: Don't align (default). # 0: Don't align (default).
@ -2646,6 +2695,11 @@ align_assign_thresh = 0 # number
# Depends on 'align_assign_span' and 'align_assign_thresh' settings. # Depends on 'align_assign_span' and 'align_assign_thresh' settings.
align_assign_on_multi_var_defs = true # true/false align_assign_on_multi_var_defs = true # true/false
# The span for aligning on '{' in braced init list.
#
# 0: Don't align (default).
align_braced_init_list_span = 0 # unsigned number
# The threshold for aligning on '{' in braced init list. # The threshold for aligning on '{' in braced init list.
# Use a negative number for absolute thresholds. # Use a negative number for absolute thresholds.
# #
@ -2813,9 +2867,16 @@ align_single_line_brace_gap = 0 # unsigned number
# 0: Don't align (default). # 0: Don't align (default).
align_oc_msg_spec_span = 0 # unsigned number align_oc_msg_spec_span = 0 # unsigned number
# Whether to align macros wrapped with a backslash and a newline. This will # Whether and how to align backslashes that split a macro onto multiple lines.
# not work right if the macro contains a multi-line comment. # This will not work right if the macro contains a multi-line comment.
align_nl_cont = false # true/false #
# 0: Do nothing (default)
# 1: Align the backslashes in the column at the end of the longest line
# 2: Align with the backslash that is farthest to the left, or, if that
# backslash is farther left than the end of the longest line, at the end of
# the longest line
# 3: Align with the backslash that is farthest to the right
align_nl_cont = 0 # unsigned number
# Whether to align macro functions and variables together. # Whether to align macro functions and variables together.
align_pp_define_together = false # true/false align_pp_define_together = false # true/false
@ -3099,9 +3160,12 @@ mod_full_brace_nl = 0 # unsigned number
# mod_full_brace_function # mod_full_brace_function
mod_full_brace_nl_block_rem_mlcond = false # true/false mod_full_brace_nl_block_rem_mlcond = false # true/false
# Add or remove unnecessary parenthesis on 'return' statement. # Add or remove unnecessary parentheses on 'return' statement.
mod_paren_on_return = add # ignore/add/remove/force/not_defined mod_paren_on_return = add # ignore/add/remove/force/not_defined
# Add or remove unnecessary parentheses on 'throw' statement.
mod_paren_on_throw = ignore # ignore/add/remove/force/not_defined
# (Pawn) Whether to change optional semicolons to real semicolons. # (Pawn) Whether to change optional semicolons to real semicolons.
mod_pawn_semicolon = false # true/false mod_pawn_semicolon = false # true/false
@ -3123,6 +3187,12 @@ mod_remove_extra_semicolon = true # true/false
# Whether to remove duplicate include. # Whether to remove duplicate include.
mod_remove_duplicate_include = true # true/false mod_remove_duplicate_include = true # true/false
# the following options (mod_XX_closebrace_comment) use different comment,
# depending of the setting of the next option.
# false: Use the c comment (default)
# true : Use the cpp comment
mod_add_force_c_closebrace_comment = false # true/false
# If a function body exceeds the specified number of newlines and doesn't have # If a function body exceeds the specified number of newlines and doesn't have
# a comment after the close brace, a comment will be added. # a comment after the close brace, a comment will be added.
mod_add_long_function_closebrace_comment = 20 # unsigned number mod_add_long_function_closebrace_comment = 20 # unsigned number
@ -3199,6 +3269,49 @@ mod_remove_empty_return = false # true/false
# Add or remove the comma after the last value of an enumeration. # Add or remove the comma after the last value of an enumeration.
mod_enum_last_comma = ignore # ignore/add/remove/force/not_defined mod_enum_last_comma = ignore # ignore/add/remove/force/not_defined
# Syntax to use for infinite loops.
#
# 0: Leave syntax alone (default)
# 1: Rewrite as `for(;;)`
# 2: Rewrite as `while(true)`
# 3: Rewrite as `do`...`while(true);`
# 4: Rewrite as `while(1)`
# 5: Rewrite as `do`...`while(1);`
#
# Infinite loops that do not already match one of these syntaxes are ignored.
# Other options that affect loop formatting will be applied after transforming
# the syntax.
mod_infinite_loop = 0 # unsigned number
# Add or remove the 'int' keyword in 'int short'.
mod_int_short = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'short int'.
mod_short_int = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'int long'.
mod_int_long = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'long int'.
mod_long_int = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'int signed'.
mod_int_signed = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'signed int'.
mod_signed_int = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'int unsigned'.
mod_int_unsigned = ignore # ignore/add/remove/force/not_defined
# Add or remove the 'int' keyword in 'unsigned int'.
mod_unsigned_int = ignore # ignore/add/remove/force/not_defined
# If there is a situation where mod_int_* and mod_*_int would result in
# multiple int keywords, whether to keep the rightmost int (the default) or the
# leftmost int.
mod_int_prefer_int_on_left = false # true/false
# (OC) Whether to organize the properties. If true, properties will be # (OC) Whether to organize the properties. If true, properties will be
# rearranged according to the mod_sort_oc_property_*_weight factors. # rearranged according to the mod_sort_oc_property_*_weight factors.
mod_sort_oc_properties = false # true/false mod_sort_oc_properties = false # true/false
@ -3230,6 +3343,16 @@ mod_sort_oc_property_nullability_weight = 0 # number
# Preprocessor options # Preprocessor options
# #
# How to use tabs when indenting preprocessor code.
#
# -1: Use 'indent_with_tabs' setting (default)
# 0: Spaces only
# 1: Indent with tabs to brace level, align with spaces
# 2: Indent and align with tabs, using spaces when not on a tabstop
#
# Default: -1
pp_indent_with_tabs = -1 # number
# Add or remove indentation of preprocessor directives inside #if blocks # Add or remove indentation of preprocessor directives inside #if blocks
# at brace level 0 (file-level). # at brace level 0 (file-level).
pp_indent = ignore # ignore/add/remove/force/not_defined pp_indent = ignore # ignore/add/remove/force/not_defined
@ -3250,10 +3373,11 @@ pp_indent_at_level0 = false # true/false
# Default: 1 # Default: 1
pp_indent_count = 4 # unsigned number pp_indent_count = 4 # unsigned number
# Add or remove space after # based on pp_level of #if blocks. # Add or remove space after # based on pp level of #if blocks.
pp_space = remove # ignore/add/remove/force/not_defined pp_space = remove # compat
pp_space_after = remove # ignore/add/remove/force/not_defined
# Sets the number of spaces per level added with pp_space. # Sets the number of spaces per level added with pp_space_after.
pp_space_count = 0 # unsigned number pp_space_count = 0 # unsigned number
# The indent for '#region' and '#endregion' in C# and '#pragma region' in # The indent for '#region' and '#endregion' in C# and '#pragma region' in
@ -3286,22 +3410,34 @@ pp_include_at_level = false # true/false
# Whether to ignore the '#define' body while formatting. # Whether to ignore the '#define' body while formatting.
pp_ignore_define_body = false # true/false pp_ignore_define_body = false # true/false
# An offset value that controls the indentation of the body of a multiline #define.
# 'body' refers to all the lines of a multiline #define except the first line.
# Requires 'pp_ignore_define_body = false'.
#
# <0: Absolute column: the body indentation starts off at the specified column
# (ex. -3 ==> the body is indented starting from column 3)
# >=0: Relative to the column of the '#' of '#define'
# (ex. 3 ==> the body is indented starting 3 columns at the right of '#')
#
# Default: 8
pp_multiline_define_body_indent = 8 # number
# Whether to indent case statements between #if, #else, and #endif. # Whether to indent case statements between #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the case statements # Only applies to the indent of the preprocessor that the case statements
# directly inside of. # directly inside of.
# #
# Default: true # Default: true
pp_indent_case = true # true/false pp_indent_case = true # true/false
# Whether to indent whole function definitions between #if, #else, and #endif. # Whether to indent whole function definitions between #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the function definition # Only applies to the indent of the preprocessor that the function definition
# is directly inside of. # is directly inside of.
# #
# Default: true # Default: true
pp_indent_func_def = true # true/false pp_indent_func_def = true # true/false
# Whether to indent extern C blocks between #if, #else, and #endif. # Whether to indent extern C blocks between #if, #else, and #endif.
# Only applies to the indent of the preprocesser that the extern block is # Only applies to the indent of the preprocessor that the extern block is
# directly inside of. # directly inside of.
# #
# Default: true # Default: true
@ -3309,7 +3445,7 @@ pp_indent_extern = true # true/false
# How to indent braces directly inside #if, #else, and #endif. # How to indent braces directly inside #if, #else, and #endif.
# Requires pp_if_indent_code=true and only applies to the indent of the # Requires pp_if_indent_code=true and only applies to the indent of the
# preprocesser that the braces are directly inside of. # preprocessor that the braces are directly inside of.
# 0: No extra indent # 0: No extra indent
# 1: Indent by one level # 1: Indent by one level
# -1: Preserve original indentation # -1: Preserve original indentation
@ -3382,10 +3518,10 @@ use_indent_continue_only_once = false # true/false
# The indentation can be: # The indentation can be:
# - after the assignment, at the '[' character # - after the assignment, at the '[' character
# - at the begin of the lambda body # - at the beginning of the lambda body
# #
# true: indentation will be after the assignment # true: indentation will be at the beginning of the lambda body
# false: indentation will be at the begin of the lambda body (default) # false: indentation will be after the assignment (default)
indent_cpp_lambda_only_once = true # true/false indent_cpp_lambda_only_once = true # true/false
# Whether sp_after_angle takes precedence over sp_inside_fparen. This was the # Whether sp_after_angle takes precedence over sp_inside_fparen. This was the
@ -3437,6 +3573,18 @@ debug_timeout = 0 # number
# 0: do not truncate. # 0: do not truncate.
debug_truncate = 0 # unsigned number debug_truncate = 0 # unsigned number
# sort (or not) the tracking info.
#
# Default: true
debug_sort_the_tracks = true # true/false
# decode (or not) the flags as a new line.
# only if the -p option is set.
debug_decode_the_flags = false # true/false
# insert the number of the line at the beginning of each line
set_numbering_for_html_output = false # true/false
# Meaning of the settings: # Meaning of the settings:
# Ignore - do not do any changes # Ignore - do not do any changes
# Add - makes sure there is 1 or more space/brace/newline/etc # Add - makes sure there is 1 or more space/brace/newline/etc
@ -3489,5 +3637,5 @@ debug_truncate = 0 # unsigned number
# `macro-close END_MESSAGE_MAP` # `macro-close END_MESSAGE_MAP`
# #
# #
# option(s) with 'not default' value: 214 # option(s) with 'not default' value: 217
# #