This commit is contained in:
Andrei Astafev 2022-10-06 15:23:27 +03:00
parent ed1a09f3af
commit e2f01d5884
23 changed files with 336 additions and 171 deletions

View File

@ -10,10 +10,10 @@ project(myx-example-qt5-gui VERSION 0.3.0 LANGUAGES C CXX)
# Рекомендуемый способ подключения MyxCMake
include(cmake/myx_setup.cmake)
#
# Поиск пакетов
myx_find_packages(Qt5 Core Gui Widgets LinguistTools)
# Цель для компиляции
# Цель для создания исполняемого файла
add_executable(${PROJECT_NAME})
# Настройка свойств цели
@ -23,6 +23,7 @@ myx_target_setup(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}/test_window.cpp
)
# Настройка Qt для цели
myx_qt5_target_setup(${PROJECT_NAME}
COMPONENTS Core Gui Widgets LinguistTools
LANGS ru_RU en_US
@ -32,11 +33,12 @@ myx_qt5_target_setup(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}/test_window.ui
)
# Форматирование исходных текстов
myx_uncrustify(${PROJECT_NAME})
# Автоматически генерируемый файл с информацией о репозитории
myx_generate_git_info_header(${PROJECT_NAME} "git_info_p.hpp")
# Автоматически генерируемый приватный заголовочный файл
myx_generate_private_config_header(${PROJECT_NAME} "config_p.hpp")
# Форматирование исходных текстов с помощью uncrustify
myx_uncrustify(${PROJECT_NAME})

View File

@ -6,19 +6,28 @@ list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/find")
get_filename_component(MYX_CMAKE_SOURCE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
#set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports" CACHE PATH "")
#set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib" CACHE PATH "")
set(MYX_CMAKE_BACKPORTS_DIR "${MYX_CMAKE_SOURCE_DIR}/backports")
set(MYX_CMAKE_LIB_DIR "${MYX_CMAKE_SOURCE_DIR}/lib")
include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake)
include(${MYX_CMAKE_BACKPORTS_DIR}/IncludeGuard.cmake)
include(${MYX_CMAKE_BACKPORTS_DIR}/TopLevelProject.cmake)
if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
include(${MYX_CMAKE_BACKPORTS_DIR}/FetchContent.cmake)
else()
include(FetchContent)
endif()
include(${MYX_CMAKE_LIB_DIR}/Includes.cmake)
include(GNUInstallDirs)
include(CMakeDependentOption)
include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake)
include(${MYX_CMAKE_LIB_DIR}/PopulateCMakeBinaryDir.cmake)
include(${MYX_CMAKE_LIB_DIR}/CurrentDate.cmake)
include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
@ -27,14 +36,16 @@ include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/Uncrustify.cmake)
include(${MYX_CMAKE_LIB_DIR}/uncrustify/Uncrustify.cmake)
include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/GitInfoHeader.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/PrivateConfigHeader.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/GitInfoHeader.cmake)
unset(MYX_CMAKE_SOURCE_DIR)
unset(MYX_CMAKE_BACKPORTS_DIR)

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "1.99.77")
set(MYX_CMAKE_PACKAGE_VERSION "1.99.99")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

View File

@ -1,6 +1,6 @@
include_guard(GLOBAL)
if(CMAKE_VERSION VERSION_LESS 3.21)
if(${CMAKE_VERSION} VERSION_LESS 3.21)
get_property(nt DIRECTORY PROPERTY PARENT_DIRECTORY)
if(NOT nt)
set(PROJECT_IS_TOP_LEVEL true)

View File

@ -0,0 +1,22 @@
#[=======================================================================[.rst:
myx_add_executable
------------------
Вспомогательная функция для создания исполняемого файла::
myx_add_executable(NAME)
Используется для совместимости с версиями CMake раньше 3.11,
в которых было необходимо указать хотя бы один файл с исходными текстами.
#]=======================================================================]
include_guard(GLOBAL)
function(myx_add_executable NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
add_executable(${NAME} ${ARGN} "")
else()
add_executable(${NAME} ${ARGN})
endif()
endfunction()

View File

@ -19,20 +19,21 @@ myx_add_library
include_guard(GLOBAL)
# Переменная `CMAKE_CURRENT_FUNCTION_LIST_DIR` позволяет определить
# каталог файла.
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
endif()
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 NAME 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)

View File

@ -1,5 +0,0 @@
include_guard(GLOBAL)
include(FetchContent)
include(GNUInstallDirs)
include(CMakeDependentOption)

View File

@ -0,0 +1,15 @@
include_guard(GLOBAL)
# Создание в каталоге ${CMAKE_BINARY_DIR} стандартных каталогов bin,include,lib,
# а также символических ссылок на каталоги в ${CMAKE_SOURCE_DIR}/files
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
create_symlink("${CMAKE_SOURCE_DIR}/files/etc" "${CMAKE_BINARY_DIR}/etc")
create_symlink("${CMAKE_SOURCE_DIR}/files/log" "${CMAKE_BINARY_DIR}/log")
create_symlink("${CMAKE_SOURCE_DIR}/files/share" "${CMAKE_BINARY_DIR}/share")
create_symlink("${CMAKE_SOURCE_DIR}/files/var" "${CMAKE_BINARY_DIR}/var")

View File

@ -36,7 +36,7 @@ function(myx_target_setup NAME)
endif()
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})
else()
target_compile_options(${NAME} PRIVATE -include ${ARG_PCH})
@ -44,10 +44,6 @@ function(myx_target_setup NAME)
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}")
endif()
if(NOT IS_DIRECTORY "${PROJECT_BINARY_DIR}/include")
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/include")
endif()
if(NOT target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)
@ -77,7 +73,9 @@ function(myx_target_setup NAME)
target_sources(${NAME} PUBLIC $<BUILD_INTERFACE:${ARG_INTERFACE_HEADERS}>)
target_sources(${NAME} PUBLIC ${ARG_PUBLIC_HEADERS})
target_sources(${NAME} PRIVATE ${ARG_CPP} ${ARG_PCH} ${ARG_PRIVATE_HEADERS})
target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES})
if(NOT target_type STREQUAL "OBJECT_LIBRARY")
target_link_libraries(${NAME} PRIVATE ${ARG_LINK_LIBRARIES})
endif()
target_compile_definitions(${NAME} PRIVATE ${ARG_COMPILE_DEFINITIONS})
# Установка публичных заголовочных файлов

View File

@ -0,0 +1,31 @@
PROJECT_NAME = @DOXYGEN_PROJECT_TITLE@
OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIRECTORY@
OUTPUT_LANGUAGE = @ARG_LANGUAGE@
STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@
STRIP_FROM_INC_PATH = @PROJECT_SOURCE_DIR@
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_METHODS = YES
INPUT = "@PROJECT_SOURCE_DIR@/doc/doxygen" "@PROJECT_SOURCE_DIR@/include" "@PROJECT_SOURCE_DIR@/src"
RECURSIVE = YES
CLANG_ASSISTED_PARSING = YES
CLANG_DATABASE_PATH = @CMAKE_BINARY_DIR@
GENERATE_HTML = @ARG_HTML@
GENERATE_TREEVIEW = YES
GENERATE_LATEX = @ARG_LATEX@
LATEX_CMD_NAME = xelatex
COMPACT_LATEX = YES
GENERATE_XML = @ARG_XML@
UML_LOOK = YES
TEMPLATE_RELATIONS = YES
CALL_GRAPH = YES
CALLER_GRAPH = YES
INTERACTIVE_SVG = YES

View File

@ -0,0 +1,73 @@
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_doc_doxygen NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT})
endif()
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_FOUND ON CACHE STRING "Doxygen documentation generator enabled" FORCE)
set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}" CACHE STRING "Path to Doxygen executable")
else()
set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
endif()
set(target "myx-doc-doxygen-${NAME}")
if(NOT DOXYGEN_FOUND)
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
return()
endif()
if(TARGET ${target})
myx_message_warning("Target ${target} already defined")
return()
endif()
set(options)
set(oneValueArgs HTML LATEX XML LANGUAGE DOXYFILE_TEMPLATE)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_HTML)
set(ARG_HTML NO)
endif()
if(NOT ARG_LATEX)
set(ARG_LATEX NO)
endif()
if(NOT ARG_XML)
set(ARG_XML YES)
endif()
if(NOT ARG_LANGUAGE)
set(ARG_LANGUAGE "Russian")
endif()
if(NOT ARG_DOXYFILE_TEMPLATE OR NOT EXISTS "${ARG_DOXYFILE_TEMPLATE}")
set(ARG_DOXYFILE_TEMPLATE "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Doxyfile.in")
endif()
if(NOT DOXYGEN_PROJECT_NAME)
set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
endif()
set(work_dir ${PROJECT_BINARY_DIR}/doc/doxygen)
configure_file(${ARG_DOXYFILE_TEMPLATE} ${work_dir}/Doxyfile @ONLY)
add_custom_target(${target}
VERBATIM
WORKING_DIRECTORY ${work_dir}
COMMAND ${DOXYGEN_EXECUTABLE} ${work_dir}/Doxyfile
COMMENT "Generating API documentation with Doxygen")
if(ARG_HTML)
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/doxygen/html/
COMPONENT doc OPTIONAL
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/doxygen)
endif()
if(NOT TARGET myx-doc-doxygen)
add_custom_target(myx-doc-doxygen)
endif()
add_dependencies(myx-doc-doxygen ${target})
endfunction()

View File

@ -0,0 +1,32 @@
cmake_policy(PUSH)
cmake_policy(SET CMP0053 NEW) # IN_LIST operator
set(ARG_PREFIX "${PREFIX}")
set(GIT_REV "N/A")
set(GIT_DIFF "")
set(GIT_TAG "N/A")
set(GIT_BRANCH "N/A")
find_package(Git)
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET)
# Check whether we got any revision (which isn't always the case,
# e.g. when someone downloaded a zip file from Github instead of a checkout)
if(NOT "${GIT_REV}" STREQUAL "")
execute_process(COMMAND bash -c "${GIT_EXECUTABLE} diff --quiet --exit-code || echo +" OUTPUT_VARIABLE GIT_DIFF)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
string(STRIP "${GIT_TAG}" GIT_TAG)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
endif()
endif()
configure_file("GitInfo.hpp.in" "${GIT_INFO_FILE}")
cmake_policy(POP)

View File

@ -0,0 +1,26 @@
// -*- C++ -*-
#pragma once
#if defined (@PREFIX@GIT_REV)
#error "Duplicate definition of macros @PREFIX@GIT_REV"
#else
#define @PREFIX@GIT_REV "@GIT_REV@"
#endif
#if defined (@PREFIX@GIT_DIFF)
#error "Duplicate definition of macros @PREFIX@GIT_DIFF"
#else
#define @PREFIX@GIT_DIFF "@GIT_DIFF@"
#endif
#if defined (@PREFIX@GIT_BRANCH)
#error "Duplicate definition of macros @PREFIX@GIT_BRANCH"
#else
#define @PREFIX@GIT_BRANCH "@GIT_BRANCH@"
#endif
#if defined (@PREFIX@GIT_TAG)
#error "Duplicate definition of macros @PREFIX@GIT_TAG"
#else
#define @PREFIX@GIT_TAG "@GIT_TAG@"
#endif

View File

@ -16,88 +16,35 @@ myx_generate_git_info_header
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_generate_git_info_header target base_filename)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif()
set(options)
set(oneValueArgs PREFIX)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(ARG_PREFIX)
string(APPEND ARG_PREFIX "_")
endif()
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
set(git_info_hpp_in
"#pragma once
#if defined (@ARG_PREFIX@GIT_REV)
#error \"Duplicate definition of macros @ARG_PREFIX@GIT_REV\"
#else
#define @ARG_PREFIX@GIT_REV \"@GIT_REV@\"
#endif
#if defined (@ARG_PREFIX@GIT_DIFF)
#error \"Duplicate definition of macros @ARG_PREFIX@GIT_DIFF\"
#else
#define @ARG_PREFIX@GIT_DIFF \"@GIT_DIFF@\"
#endif
#if defined (@ARG_PREFIX@GIT_BRANCH)
#error \"Duplicate definition of macros @ARG_PREFIX@GIT_BRANCH\"
#else
#define @ARG_PREFIX@GIT_BRANCH \"@GIT_BRANCH@\"
#endif
#if defined (@ARG_PREFIX@GIT_TAG)
#error \"Duplicate definition of macros @ARG_PREFIX@GIT_TAG\"
#else
#define @ARG_PREFIX@GIT_TAG \"@GIT_TAG@\"
#endif
")
set(git_info_hpp_in_path ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/myx_git_info_p.hpp.in)
file(WRITE ${git_info_hpp_in_path} ${git_info_hpp_in})
set(git_info_cmake_in
"set(ARG_PREFIX ${ARG_PREFIX})
set(GIT_REV \"N/A\")
set(GIT_DIFF \"\")
set(GIT_TAG \"N/A\")
set(GIT_BRANCH \"N/A\")
find_package(Git)
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET)
# Check whether we got any revision (which isn't always the case,
# e.g. when someone downloaded a zip file from Github instead of a checkout)
if(NOT \"\${GIT_REV}\" STREQUAL \"\")
execute_process(COMMAND bash -c \"${GIT_EXECUTABLE} diff --quiet --exit-code || echo +\" OUTPUT_VARIABLE GIT_DIFF)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP \"\${GIT_REV}\" GIT_REV)
string(SUBSTRING \"\${GIT_REV}\" 1 7 GIT_REV)
string(STRIP \"\${GIT_DIFF}\" GIT_DIFF)
string(STRIP \"\${GIT_TAG}\" GIT_TAG)
string(STRIP \"\${GIT_BRANCH}\" GIT_BRANCH)
set(PREFIX "")
if(ARG_PREFIX)
string(APPEND ARG_PREFIX "_")
string(REPLACE "-" "_" PREFIX ${ARG_PREFIX})
endif()
endif()
configure_file(${git_info_hpp_in_path} \"\${GIT_INFO_FILE}\")
")
set(git_info_cmake_in_path "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target}-git-info.cmake.in")
file(WRITE ${git_info_cmake_in_path} ${git_info_cmake_in})
# cmake-format: off
if(NOT TARGET ${target}-git-info-header)
add_custom_target(${target}-git-info-header ALL
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -P ${git_info_cmake_in_path}
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -DPREFIX=${PREFIX}
-P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake
BYPRODUCTS ${filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
endif()
# cmake-format: on

View File

@ -0,0 +1,12 @@
// -*- C++ -*-
#pragma once
#define PROJECT_VERSION_STR "@PROJECT_VERSION@"
#define PROJECT_VERSION_INT @PROJECT_VERSION_INT@
#cmakedefine PROJECT_NAME "@PROJECT_NAME@"
#cmakedefine AUTHOR_NAME "@AUTHOR_NAME@"
#cmakedefine AUTHOR_EMAIL "@AUTHOR_EMAIL@"
#cmakedefine DESCRIPTION "@PROJECT_DESCRIPTION@"
#cmakedefine BUILD_TYPE "@CMAKE_BUILD_TYPE@"
#cmakedefine BUILD_DATE "@MYX_TODAY@"

View File

@ -14,31 +14,21 @@ myx_generate_private_config_header
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_generate_private_config_header target base_filename)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif()
set(BUILD_DATE ${MYX_TODAY})
myx_project_version_int()
get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
set(private_config_hpp_in
"#pragma once
#define PROJECT_VERSION_STR \"@PROJECT_VERSION@\"
#define PROJECT_VERSION_INT @PROJECT_VERSION_INT@
#cmakedefine PROJECT_NAME \"@PROJECT_NAME@\"
#cmakedefine AUTHOR_NAME \"@AUTHOR_NAME@\"
#cmakedefine AUTHOR_EMAIL \"@AUTHOR_EMAIL@\"
#cmakedefine DESCRIPTION \"@PROJECT_DESCRIPTION@\"
#cmakedefine BUILD_TYPE \"@CMAKE_BUILD_TYPE@\"
#cmakedefine BUILD_DATE \"@MYX_TODAY@\"
")
set(private_config_hpp_in_path "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target}_config_p.hpp.in")
file(WRITE ${private_config_hpp_in_path} ${private_config_hpp_in})
configure_file(${private_config_hpp_in_path} ${filename})
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${filename})
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
target_sources(${target} PRIVATE ${filename})

View File

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

View File

@ -1,47 +1,19 @@
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
if(UNCRUSTIFY_EXE)
if(NOT EXISTS ${PROJECT_BINARY_DIR}/uncrustify-classheader.txt)
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-classheader.txt CONTENT
"/**
* @class $(fclass)
* @brief TODO
* @details TODO
*/")
endif()
if(NOT EXISTS ${PROJECT_BINARY_DIR}/uncrustify-filefooter.txt)
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-filefooter.txt CONTENT
"// EOF $(filename)")
endif()
if(NOT EXISTS ${PROJECT_BINARY_DIR}/uncrustify-fileheader.txt)
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-fileheader.txt CONTENT
"/**
* @file $(filename)
* @brief TODO
* @details TODO
*/")
endif()
if(NOT EXISTS ${PROJECT_BINARY_DIR}/uncrustify-funcheader.txt)
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-funcheader.txt CONTENT
"/**
* @fn $(fclass)::$(function)
* $(javaparam)
* @details TODO
*/")
endif()
endif()
function(myx_uncrustify target)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
endif()
set(options)
set(oneValueArgs CONFIG)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_CONFIG)
@ -52,15 +24,17 @@ function(myx_uncrustify target)
endif()
if(NOT EXISTS ${ARG_CONFIG})
myx_message_notify("MyxCMake: uncrustify config is not found")
myx_message_notice("MyxCMake: uncrustify config is not found")
return()
endif()
if(NOT UNCRUSTIFY_EXE)
myx_message_notify("MyxCMake: uncrustify executable is not found")
myx_message_notice("MyxCMake: uncrustify executable is not found")
return()
endif()
if(NOT TARGET myx-uncrustify)
add_custom_target(myx-uncrustify)
endif()
@ -71,12 +45,14 @@ function(myx_uncrustify target)
add_custom_target(myx-uncrustify-append-comments)
endif()
get_target_property(__sources ${target} SOURCES)
list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$")
list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$")
list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$")
list(FILTER __sources EXCLUDE REGEX ".*\\.qm$")
# Динамически сгенерированные файлы исключаются
get_target_property(s ${target} SOURCES)
foreach(iter ${s})
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
if(pos EQUAL -1)
list(APPEND src ${iter})
endif()
endforeach()
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc
-c ${ARG_CONFIG}
@ -85,21 +61,21 @@ function(myx_uncrustify target)
# cmake-format: off
add_custom_target(${target}-uncrustify-check
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${__sources})
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${src})
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
add_custom_target(${target}-uncrustify
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${__sources})
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${src})
add_custom_target(${target}-uncrustify-append-comments
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS}
--set cmt_insert_class_header=${PROJECT_BINARY_DIR}/uncrustify-classheader.txt
--set cmt_insert_file_footer=${PROJECT_BINARY_DIR}/uncrustify-filefooter.txt
--set cmt_insert_file_header=${PROJECT_BINARY_DIR}/uncrustify-fileheader.txt
--set cmt_insert_func_header=${PROJECT_BINARY_DIR}/uncrustify-funcheader.txt
--set cmt_insert_before_ctor_dtor=true --mtime ${__sources})
--set cmt_insert_class_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/classheader.txt
--set cmt_insert_file_footer=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/filefooter.txt
--set cmt_insert_file_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fileheader.txt
--set cmt_insert_func_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/funcheader.txt
--set cmt_insert_before_ctor_dtor=true --mtime ${src})
# cmake-format: on
add_dependencies(myx-uncrustify ${target}-uncrustify)

View File

@ -0,0 +1,5 @@
/**
* @class $(fclass)
* @brief TODO
* @details TODO
*/

View File

@ -0,0 +1 @@
// EOF $(filename)

View File

@ -0,0 +1,6 @@
// -*- C++ -*-
/**
* @file $(filename)
* @brief TODO
* @details TODO
*/

View File

@ -0,0 +1,5 @@
/**
* @fn $(fclass)::$(function)
* $(javaparam)
* @details TODO
*/

View File

@ -10,17 +10,21 @@
Если определена переменная `MYX_CMAKE_USE_SYSTEM`, то выполняется
поиск версии в каталогах перечисленных в переменной `CMAKE_MODULES_DIR`.
Кроме того выполняется попытка поиска (MyxxCMake)[../../../../myxx] --
расширения для библиотеки, позволяющиего в режиме разработки программного
проекта использовать дополнительные инструменты для его сопровождения.
#]=======================================================================]
if(MYX_CMAKE_DIR)
set(ENV{MYX_CMAKE_DIR} ${MYX_CMAKE_DIR})
endif()
if(DEFINED ENV{MYX_CMAKE_DIR})
find_package(MyxCMake 1.99.77 CONFIG PATHS $ENV{MYX_CMAKE_DIR} NO_DEFAULT_PATH REQUIRED)
find_package(MyxCMake 1.99.99 REQUIRED CONFIG PATHS $ENV{MYX_CMAKE_DIR} NO_DEFAULT_PATH)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else()
if(MYX_CMAKE_USE_SYSTEM)
find_package(MyxCMake 1.99.77 REQUIRED)
find_package(MyxCMake 1.99.99 REQUIRED)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else()
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
@ -28,3 +32,5 @@ else()
endif()
endif()
find_package(MyxxCMake CONFIG PATHS "$ENV{XDG_DATA_DIR}/cmake" QUIET)