diff --git a/MyxCMakeConfig.cmake b/MyxCMakeConfig.cmake index 4970a97..a9a0800 100644 --- a/MyxCMakeConfig.cmake +++ b/MyxCMakeConfig.cmake @@ -18,6 +18,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.11.0") endif() 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}/NinjaGeneratorWarning.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}/generators/GitInfoHeader.cmake) +include(${MYX_CMAKE_LIB_DIR}/generators/PrivateConfigHeader.cmake) + unset(MYX_CMAKE_SOURCE_DIR) unset(MYX_CMAKE_BACKPORTS_DIR) unset(MYX_CMAKE_LIB_DIR) diff --git a/MyxCMakeConfigVersion.cmake b/MyxCMakeConfigVersion.cmake index 49f1e67..8ba3de6 100644 --- a/MyxCMakeConfigVersion.cmake +++ b/MyxCMakeConfigVersion.cmake @@ -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) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() diff --git a/README.md b/README.md index a39e7de..aff5c68 100644 --- a/README.md +++ b/README.md @@ -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.64 REQUIRED) + find_package(MyxCMake 1.99.65 REQUIRED) else() if(MYX_CMAKE_USE_SYSTEM) - find_package(MyxCMake 1.99.64 REQUIRED) + find_package(MyxCMake 1.99.65 REQUIRED) else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake) endif() diff --git a/VERSION b/VERSION index c2e1b86..338050c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.99.64 +1.99.65 diff --git a/lib/CurrentDate.cmake b/lib/CurrentDate.cmake new file mode 100644 index 0000000..b48038a --- /dev/null +++ b/lib/CurrentDate.cmake @@ -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() diff --git a/lib/Qt5TargetSetup.cmake b/lib/Qt5TargetSetup.cmake index 60358fa..b43fff4 100644 --- a/lib/Qt5TargetSetup.cmake +++ b/lib/Qt5TargetSetup.cmake @@ -50,7 +50,9 @@ function(myx_qt5_target_setup NAME) endif() 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}) + myx_message_warning(fffff ffff ${ui_h}) endif() if("LinguistTools" IN_LIST ARG_COMPONENTS) diff --git a/lib/TargetSetup.cmake b/lib/TargetSetup.cmake index 8320209..79c1117 100644 --- a/lib/TargetSetup.cmake +++ b/lib/TargetSetup.cmake @@ -46,12 +46,16 @@ 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() + target_include_directories(${PROJECT_NAME} PRIVATE $) if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/src") target_include_directories(${PROJECT_NAME} PRIVATE - $) + $) endif() if(type STREQUAL EXECUTABLE) diff --git a/lib/generators/GitInfoHeader.cmake b/lib/generators/GitInfoHeader.cmake new file mode 100644 index 0000000..53f81d1 --- /dev/null +++ b/lib/generators/GitInfoHeader.cmake @@ -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() diff --git a/lib/generators/PrivateConfigHeader.cmake b/lib/generators/PrivateConfigHeader.cmake new file mode 100644 index 0000000..2d1331b --- /dev/null +++ b/lib/generators/PrivateConfigHeader.cmake @@ -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()