HVAC_M7_MONO/MODULES/CmakeConfig_RandomBuildIdGe.../generate_version.cmake

71 lines
2.1 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# generate_version.cmake
# Запуск: cmake -DOUT=<path/Version.h>
# -DVERSION_FILE=<path/.version>
# -P generate_version.cmake
if(NOT DEFINED OUT)
message(FATAL_ERROR "OUT is not defined")
endif()
if(NOT DEFINED VERSION_FILE)
message(FATAL_ERROR "VERSION_FILE is not defined")
endif()
# --- Дата без ведущих нулей (26, 9, 29) ---
string(TIMESTAMP CURRENT_YEAR "%y") # 26
string(TIMESTAMP CURRENT_MONTH "%m") # 09
string(TIMESTAMP CURRENT_DAY "%d") # 29
string(REGEX REPLACE "^0" "" CURRENT_MONTH "${CURRENT_MONTH}") # 9
string(REGEX REPLACE "^0" "" CURRENT_DAY "${CURRENT_DAY}") # 29
# --- Ключ дня для .version (с ведущими нулями — совместимость) ---
string(TIMESTAMP DATE_KEY "%y%m%d")
# --- Читаем .version ---
set(saved_key "")
set(saved_rev 0)
if(EXISTS "${VERSION_FILE}")
file(READ "${VERSION_FILE}" content)
string(REGEX MATCH "DATE_KEY=([0-9]+)" _ "${content}")
if(CMAKE_MATCH_1)
set(saved_key "${CMAKE_MATCH_1}")
endif()
string(REGEX MATCH "REV=([0-9]+)" _ "${content}")
if(CMAKE_MATCH_1)
set(saved_rev "${CMAKE_MATCH_1}")
endif()
endif()
# --- Считаем ревизию ---
if("${saved_key}" STREQUAL "${DATE_KEY}")
math(EXPR new_rev "${saved_rev} + 1")
else()
set(new_rev 1)
endif()
file(WRITE "${VERSION_FILE}" "DATE_KEY=${DATE_KEY}\nREV=${new_rev}\n")
# --- Пишем заголовок ---
file(WRITE "${OUT}"
"#pragma once
#define INTERNAL_SW_YEAR ${CURRENT_YEAR}
#define INTERNAL_SW_MONTH ${CURRENT_MONTH}
#define INTERNAL_SW_DAY ${CURRENT_DAY}
#define INTERNAL_SW_REV ${new_rev}
#define INTERNAL_MDB_YEAR ${CURRENT_YEAR}
#define INTERNAL_MDB_MONTH ${CURRENT_MONTH}
#define INTERNAL_MDB_DAY ${CURRENT_DAY}
#define INTERNAL_MDB_REV ${new_rev}
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
#define INTERNAL_SW_VERSION_STR \\
STR(INTERNAL_SW_YEAR) \".\" STR(INTERNAL_SW_MONTH) \".\" \\
STR(INTERNAL_SW_DAY) \"-\" STR(INTERNAL_SW_REV)
")
message(STATUS "Version: ${CURRENT_YEAR}.${CURRENT_MONTH}.${CURRENT_DAY}-${new_rev}")