From 08b5271e5a3ce1286be6d92d0c1f8daf62c5191d Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 6 Oct 2022 15:23:16 +0300 Subject: [PATCH] update --- CMakeLists.txt | 2 +- cmake/myx/MyxCMakeConfig.cmake | 23 +++-- cmake/myx/MyxCMakeConfigVersion.cmake | 2 +- cmake/myx/backports/TopLevelProject.cmake | 2 +- cmake/myx/lib/AddExecutable.cmake | 22 +++++ cmake/myx/lib/AddLibrary.cmake | 15 ++-- cmake/myx/lib/Includes.cmake | 5 -- cmake/myx/lib/PopulateCMakeBinaryDir.cmake | 15 ++++ cmake/myx/lib/TargetSetup.cmake | 10 +-- cmake/myx/lib/doc/Doxyfile.in | 31 +++++++ cmake/myx/lib/doc/Doxygen.cmake | 73 ++++++++++++++++ cmake/myx/lib/generators/GitInfo.cmake | 32 +++++++ cmake/myx/lib/generators/GitInfo.hpp.in | 26 ++++++ cmake/myx/lib/generators/GitInfoHeader.cmake | 83 ++++--------------- cmake/myx/lib/generators/PrivateConfig.hpp.in | 12 +++ .../lib/generators/PrivateConfigHeader.cmake | 28 ++----- cmake/myx/lib/macro/CreateSymlink.cmake | 11 +++ .../myx/lib/{ => uncrustify}/Uncrustify.cmake | 78 ++++++----------- cmake/myx/lib/uncrustify/classheader.txt | 5 ++ cmake/myx/lib/uncrustify/filefooter.txt | 1 + cmake/myx/lib/uncrustify/fileheader.txt | 6 ++ cmake/myx/lib/uncrustify/funcheader.txt | 5 ++ cmake/myx_setup.cmake | 10 ++- 23 files changed, 330 insertions(+), 167 deletions(-) create mode 100644 cmake/myx/lib/AddExecutable.cmake delete mode 100644 cmake/myx/lib/Includes.cmake create mode 100644 cmake/myx/lib/PopulateCMakeBinaryDir.cmake create mode 100644 cmake/myx/lib/doc/Doxyfile.in create mode 100644 cmake/myx/lib/doc/Doxygen.cmake create mode 100644 cmake/myx/lib/generators/GitInfo.cmake create mode 100644 cmake/myx/lib/generators/GitInfo.hpp.in create mode 100644 cmake/myx/lib/generators/PrivateConfig.hpp.in create mode 100644 cmake/myx/lib/macro/CreateSymlink.cmake rename cmake/myx/lib/{ => uncrustify}/Uncrustify.cmake (51%) create mode 100644 cmake/myx/lib/uncrustify/classheader.txt create mode 100644 cmake/myx/lib/uncrustify/filefooter.txt create mode 100644 cmake/myx/lib/uncrustify/fileheader.txt create mode 100644 cmake/myx/lib/uncrustify/funcheader.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f061047..6fe0cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,5 +21,5 @@ myx_target_setup(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/src/${PROJECT_NAME}/init.cpp ) -# Форматирование кода с помощью uncrustify +# Форматирование исходных текстов с помощью uncrustify myx_uncrustify(${PROJECT_NAME}) diff --git a/cmake/myx/MyxCMakeConfig.cmake b/cmake/myx/MyxCMakeConfig.cmake index b3378fe..27b091f 100644 --- a/cmake/myx/MyxCMakeConfig.cmake +++ b/cmake/myx/MyxCMakeConfig.cmake @@ -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) diff --git a/cmake/myx/MyxCMakeConfigVersion.cmake b/cmake/myx/MyxCMakeConfigVersion.cmake index f355bf4..cd17f81 100644 --- a/cmake/myx/MyxCMakeConfigVersion.cmake +++ b/cmake/myx/MyxCMakeConfigVersion.cmake @@ -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() diff --git a/cmake/myx/backports/TopLevelProject.cmake b/cmake/myx/backports/TopLevelProject.cmake index b1b89ee..86994cc 100644 --- a/cmake/myx/backports/TopLevelProject.cmake +++ b/cmake/myx/backports/TopLevelProject.cmake @@ -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) diff --git a/cmake/myx/lib/AddExecutable.cmake b/cmake/myx/lib/AddExecutable.cmake new file mode 100644 index 0000000..0894dce --- /dev/null +++ b/cmake/myx/lib/AddExecutable.cmake @@ -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() diff --git a/cmake/myx/lib/AddLibrary.cmake b/cmake/myx/lib/AddLibrary.cmake index df0c197..da573a6 100644 --- a/cmake/myx/lib/AddLibrary.cmake +++ b/cmake/myx/lib/AddLibrary.cmake @@ -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) diff --git a/cmake/myx/lib/Includes.cmake b/cmake/myx/lib/Includes.cmake deleted file mode 100644 index 788516e..0000000 --- a/cmake/myx/lib/Includes.cmake +++ /dev/null @@ -1,5 +0,0 @@ -include_guard(GLOBAL) - -include(FetchContent) -include(GNUInstallDirs) -include(CMakeDependentOption) diff --git a/cmake/myx/lib/PopulateCMakeBinaryDir.cmake b/cmake/myx/lib/PopulateCMakeBinaryDir.cmake new file mode 100644 index 0000000..8078fca --- /dev/null +++ b/cmake/myx/lib/PopulateCMakeBinaryDir.cmake @@ -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") diff --git a/cmake/myx/lib/TargetSetup.cmake b/cmake/myx/lib/TargetSetup.cmake index 323f397..cb2236f 100644 --- a/cmake/myx/lib/TargetSetup.cmake +++ b/cmake/myx/lib/TargetSetup.cmake @@ -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 $) @@ -77,7 +73,9 @@ function(myx_target_setup NAME) target_sources(${NAME} PUBLIC $) 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}) # Установка публичных заголовочных файлов diff --git a/cmake/myx/lib/doc/Doxyfile.in b/cmake/myx/lib/doc/Doxyfile.in new file mode 100644 index 0000000..c8923f8 --- /dev/null +++ b/cmake/myx/lib/doc/Doxyfile.in @@ -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 diff --git a/cmake/myx/lib/doc/Doxygen.cmake b/cmake/myx/lib/doc/Doxygen.cmake new file mode 100644 index 0000000..5d97ac0 --- /dev/null +++ b/cmake/myx/lib/doc/Doxygen.cmake @@ -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() diff --git a/cmake/myx/lib/generators/GitInfo.cmake b/cmake/myx/lib/generators/GitInfo.cmake new file mode 100644 index 0000000..5b9f2a7 --- /dev/null +++ b/cmake/myx/lib/generators/GitInfo.cmake @@ -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) diff --git a/cmake/myx/lib/generators/GitInfo.hpp.in b/cmake/myx/lib/generators/GitInfo.hpp.in new file mode 100644 index 0000000..2e8825e --- /dev/null +++ b/cmake/myx/lib/generators/GitInfo.hpp.in @@ -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 diff --git a/cmake/myx/lib/generators/GitInfoHeader.cmake b/cmake/myx/lib/generators/GitInfoHeader.cmake index 3155319..d3545a2 100644 --- a/cmake/myx/lib/generators/GitInfoHeader.cmake +++ b/cmake/myx/lib/generators/GitInfoHeader.cmake @@ -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 diff --git a/cmake/myx/lib/generators/PrivateConfig.hpp.in b/cmake/myx/lib/generators/PrivateConfig.hpp.in new file mode 100644 index 0000000..0d24d25 --- /dev/null +++ b/cmake/myx/lib/generators/PrivateConfig.hpp.in @@ -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@" diff --git a/cmake/myx/lib/generators/PrivateConfigHeader.cmake b/cmake/myx/lib/generators/PrivateConfigHeader.cmake index 2d1331b..e048ca4 100644 --- a/cmake/myx/lib/generators/PrivateConfigHeader.cmake +++ b/cmake/myx/lib/generators/PrivateConfigHeader.cmake @@ -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}) diff --git a/cmake/myx/lib/macro/CreateSymlink.cmake b/cmake/myx/lib/macro/CreateSymlink.cmake new file mode 100644 index 0000000..fe04de6 --- /dev/null +++ b/cmake/myx/lib/macro/CreateSymlink.cmake @@ -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) diff --git a/cmake/myx/lib/Uncrustify.cmake b/cmake/myx/lib/uncrustify/Uncrustify.cmake similarity index 51% rename from cmake/myx/lib/Uncrustify.cmake rename to cmake/myx/lib/uncrustify/Uncrustify.cmake index 620e38f..489dbf8 100644 --- a/cmake/myx/lib/Uncrustify.cmake +++ b/cmake/myx/lib/uncrustify/Uncrustify.cmake @@ -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) diff --git a/cmake/myx/lib/uncrustify/classheader.txt b/cmake/myx/lib/uncrustify/classheader.txt new file mode 100644 index 0000000..c82b16e --- /dev/null +++ b/cmake/myx/lib/uncrustify/classheader.txt @@ -0,0 +1,5 @@ +/** + * @class $(fclass) + * @brief TODO + * @details TODO + */ diff --git a/cmake/myx/lib/uncrustify/filefooter.txt b/cmake/myx/lib/uncrustify/filefooter.txt new file mode 100644 index 0000000..56a3f8b --- /dev/null +++ b/cmake/myx/lib/uncrustify/filefooter.txt @@ -0,0 +1 @@ +// EOF $(filename) diff --git a/cmake/myx/lib/uncrustify/fileheader.txt b/cmake/myx/lib/uncrustify/fileheader.txt new file mode 100644 index 0000000..c5b9665 --- /dev/null +++ b/cmake/myx/lib/uncrustify/fileheader.txt @@ -0,0 +1,6 @@ +// -*- C++ -*- +/** + * @file $(filename) + * @brief TODO + * @details TODO + */ diff --git a/cmake/myx/lib/uncrustify/funcheader.txt b/cmake/myx/lib/uncrustify/funcheader.txt new file mode 100644 index 0000000..3fb62e7 --- /dev/null +++ b/cmake/myx/lib/uncrustify/funcheader.txt @@ -0,0 +1,5 @@ +/** + * @fn $(fclass)::$(function) + * $(javaparam) + * @details TODO + */ diff --git a/cmake/myx_setup.cmake b/cmake/myx_setup.cmake index bed27cc..ab11dbd 100644 --- a/cmake/myx_setup.cmake +++ b/cmake/myx_setup.cmake @@ -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) +