This commit is contained in:
Andrei Astafev 2022-10-04 22:53:44 +03:00
parent e467ebd1b4
commit 62199ab0bf
9 changed files with 98 additions and 91 deletions

View File

@ -36,8 +36,8 @@ include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/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.83")
set(MYX_CMAKE_PACKAGE_VERSION "1.99.84")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

View File

@ -36,10 +36,10 @@ if(MYX_CMAKE_DIR)
set(ENV{MYX_CMAKE_DIR} ${MYX_CMAKE_DIR})
endif()
if(DEFINED ENV{MYX_CMAKE_DIR})
find_package(MyxCMake 1.99.83 REQUIRED)
find_package(MyxCMake 1.99.84 REQUIRED)
else()
if(MYX_CMAKE_USE_SYSTEM)
find_package(MyxCMake 1.99.83 REQUIRED)
find_package(MyxCMake 1.99.84 REQUIRED)
else()
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
endif()

View File

@ -1 +1 @@
1.99.83
1.99.84

View File

@ -0,0 +1,37 @@
cmake_policy(PUSH)
cmake_policy(SET CMP0053 NEW) # IN_LIST operator
# Переменная `CMAKE_CURRENT_FUNCTION_LIST_DIR` позволяет определить каталог файла.
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
endif()
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,25 @@
#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,6 +16,12 @@ myx_generate_git_info_header
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()
function(myx_generate_git_info_header target base_filename)
set(options)
set(oneValueArgs PREFIX)
@ -23,81 +29,21 @@ function(myx_generate_git_info_header target base_filename)
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,11 @@
#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,19 @@ myx_generate_private_config_header
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()
function(myx_generate_private_config_header target base_filename)
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})