chore: define MAA_VERSION automatically in CMake

This commit is contained in:
Horror Proton
2022-10-19 00:48:43 +08:00
parent ccfadc4221
commit 3ffd653d2d

View File

@@ -90,3 +90,43 @@ if (BUILD_XCFRAMEWORK)
DEPENDS MeoAssistant MeoAssistant.xcframework
)
endif (BUILD_XCFRAMEWORK)
# define MAA_VERSION from git
if (NOT MAA_VERSION)
find_package(Git)
endif ()
if (GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty --broken --abbrev=40
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE err
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (result EQUAL 0)
set(MAA_VERSION "${output}")
else ()
message(WARNING "git describe returning ${result}, output:\n${err}")
endif()
endif ()
if (NOT MAA_VERSION AND GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE err
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (result EQUAL 0)
set(MAA_VERSION "${output}")
else ()
message(WARNING "git rev-parse returning ${result}, output:\n${err}")
endif ()
endif ()
if (NOT MAA_VERSION)
set(MAA_VERSION "DEBUG VERSION")
endif ()
message(STATUS "MAA_VERSION=${MAA_VERSION}")
add_compile_definitions(MAA_VERSION="${MAA_VERSION}")