This commit is contained in:
Andrei Astafev 2022-10-03 15:06:53 +03:00
parent e71ec5c925
commit 7a391f233a
9 changed files with 185 additions and 5 deletions

View File

@ -18,6 +18,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
endif() endif()
include(${MYX_CMAKE_LIB_DIR}/Includes.cmake) include(${MYX_CMAKE_LIB_DIR}/Includes.cmake)
include(${MYX_CMAKE_LIB_DIR}/CurrentDate.cmake)
include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake) include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake)
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake) include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
@ -31,6 +32,9 @@ include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/Uncrustify.cmake) include(${MYX_CMAKE_LIB_DIR}/Uncrustify.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/GitInfoHeader.cmake)
include(${MYX_CMAKE_LIB_DIR}/generators/PrivateConfigHeader.cmake)
unset(MYX_CMAKE_SOURCE_DIR) unset(MYX_CMAKE_SOURCE_DIR)
unset(MYX_CMAKE_BACKPORTS_DIR) unset(MYX_CMAKE_BACKPORTS_DIR)
unset(MYX_CMAKE_LIB_DIR) unset(MYX_CMAKE_LIB_DIR)

View File

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

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

View File

@ -1 +1 @@
1.99.64 1.99.65

19
lib/CurrentDate.cmake Normal file
View File

@ -0,0 +1,19 @@
include_guard(GLOBAL)
if(NOT MYX_TODAY)
if(WIN32)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE MYX_TODAY)
else()
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE MYX_TODAY)
endif()
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" MYX_TODAY ${MYX_TODAY})
endif()
if(NOT MYX_YEAR)
if(WIN32)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE MYX_YEAR)
else()
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE MYX_YEAR)
endif()
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3" MYX_YEAR ${MYX_YEAR})
endif()

View File

@ -50,7 +50,9 @@ function(myx_qt5_target_setup NAME)
endif() endif()
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS) if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
set(Qt5Widgets_UIC_EXECUTABLE "/usr/lib/qt5/bin/uic")
qt5_wrap_ui(ui_h ${ARG_UI}) qt5_wrap_ui(ui_h ${ARG_UI})
myx_message_warning(fffff ffff ${ui_h})
endif() endif()
if("LinguistTools" IN_LIST ARG_COMPONENTS) if("LinguistTools" IN_LIST ARG_COMPONENTS)

View File

@ -46,6 +46,10 @@ function(myx_target_setup NAME)
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}") set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PCH}")
endif() endif()
if(NOT IS_DIRECTORY "${PROJECT_BINARY_DIR}/include")
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/include")
endif()
target_include_directories(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>) $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>)

View File

@ -0,0 +1,106 @@
#[=======================================================================[.rst:
myx_generate_git_info_header
----------------------------------
Вспомогательная функция для автоматической генерации заголовочного
файла, содержащего информацию о текущем состоянии репозитория git::
myx_generate_git_info_header(TARGET BASE_FILENAME
[ PREFIX prefix ] )
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
и `BASE_FILENAME` - имя генерируемого заголовочного файла. Дополнительный аргумент
`PREFIX` добавляет префикс к генерируемым именам переменных.
#]=======================================================================]
include_guard(GLOBAL)
function(myx_generate_git_info_header target base_filename)
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_program(GIT_EXECUTABLE git)
if(GIT_EXECUTABLE)
execute_process(COMMAND git 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 diff --quiet --exit-code || echo +\" OUTPUT_VARIABLE GIT_DIFF)
execute_process(COMMAND git describe --exact-match --tags OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(COMMAND git 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(${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}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
# cmake-format: on
file(WRITE ${filename} "")
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
target_sources(${target} PRIVATE ${filename})
endfunction()

View File

@ -0,0 +1,45 @@
#[=======================================================================[.rst:
myx_generate_private_config_header
----------------------------------
Вспомогательная функция для автоматической генерации заголовочного
файла, содержащего информацию о проекте::
myx_generate_private_config_header(TARGET BASE_FILENAME)
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
и `BASE_FILENAME` - имя генерируемого заголовочного файла.
#]=======================================================================]
include_guard(GLOBAL)
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})
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
target_sources(${target} PRIVATE ${filename})
endfunction()