2023-11-02 06:50:16 +00:00
|
|
|
set(TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/common/build-info.cpp.in")
|
|
|
|
set(OUTPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/common/build-info.cpp")
|
2023-05-01 16:23:47 +00:00
|
|
|
set(BUILD_NUMBER 0)
|
|
|
|
set(BUILD_COMMIT "unknown")
|
2023-09-15 20:59:49 +00:00
|
|
|
set(BUILD_COMPILER "unknown")
|
|
|
|
set(BUILD_TARGET "unknown")
|
2023-05-01 16:23:47 +00:00
|
|
|
|
|
|
|
# Look for git
|
|
|
|
find_package(Git)
|
|
|
|
if(NOT Git_FOUND)
|
2023-09-25 22:45:33 +00:00
|
|
|
find_program(GIT_EXECUTABLE NAMES git git.exe)
|
|
|
|
if(GIT_EXECUTABLE)
|
2023-05-01 16:23:47 +00:00
|
|
|
set(Git_FOUND TRUE)
|
2023-09-25 22:45:33 +00:00
|
|
|
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
|
2023-05-01 16:23:47 +00:00
|
|
|
else()
|
2023-09-25 22:45:33 +00:00
|
|
|
message(WARNING "Git not found. Build info will not be accurate.")
|
2023-05-01 16:23:47 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Get the commit count and hash
|
|
|
|
if(Git_FOUND)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE HEAD
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-11-02 06:50:16 +00:00
|
|
|
RESULT_VARIABLE RES
|
2023-05-01 16:23:47 +00:00
|
|
|
)
|
2023-11-02 06:50:16 +00:00
|
|
|
if (RES EQUAL 0)
|
|
|
|
set(BUILD_COMMIT ${HEAD})
|
|
|
|
endif()
|
2023-05-01 16:23:47 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE COUNT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2023-11-02 06:50:16 +00:00
|
|
|
RESULT_VARIABLE RES
|
2023-05-01 16:23:47 +00:00
|
|
|
)
|
2023-11-02 06:50:16 +00:00
|
|
|
if (RES EQUAL 0)
|
|
|
|
set(BUILD_NUMBER ${COUNT})
|
|
|
|
endif()
|
2023-09-15 20:59:49 +00:00
|
|
|
endif()
|
|
|
|
|
2023-09-25 22:45:33 +00:00
|
|
|
if(MSVC)
|
|
|
|
set(BUILD_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}")
|
|
|
|
set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME})
|
|
|
|
else()
|
|
|
|
execute_process(
|
|
|
|
COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}
|
|
|
|
OUTPUT_VARIABLE OUT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2023-09-15 20:59:49 +00:00
|
|
|
set(BUILD_COMPILER ${OUT})
|
2023-09-25 22:45:33 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} -dumpmachine
|
|
|
|
OUTPUT_VARIABLE OUT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2023-09-15 20:59:49 +00:00
|
|
|
set(BUILD_TARGET ${OUT})
|
|
|
|
endif()
|
|
|
|
|
2023-11-02 06:50:16 +00:00
|
|
|
# Only write the build info if it changed
|
|
|
|
if(EXISTS ${OUTPUT_FILE})
|
|
|
|
file(READ ${OUTPUT_FILE} CONTENTS)
|
|
|
|
string(REGEX MATCH "LLAMA_COMMIT = \"([^\"]*)\";" _ ${CONTENTS})
|
2023-09-15 20:59:49 +00:00
|
|
|
set(OLD_COMMIT ${CMAKE_MATCH_1})
|
2023-11-02 06:50:16 +00:00
|
|
|
string(REGEX MATCH "LLAMA_COMPILER = \"([^\"]*)\";" _ ${CONTENTS})
|
2023-09-15 20:59:49 +00:00
|
|
|
set(OLD_COMPILER ${CMAKE_MATCH_1})
|
2023-11-02 06:50:16 +00:00
|
|
|
string(REGEX MATCH "LLAMA_BUILD_TARGET = \"([^\"]*)\";" _ ${CONTENTS})
|
2023-09-15 20:59:49 +00:00
|
|
|
set(OLD_TARGET ${CMAKE_MATCH_1})
|
|
|
|
if (
|
|
|
|
NOT OLD_COMMIT STREQUAL BUILD_COMMIT OR
|
|
|
|
NOT OLD_COMPILER STREQUAL BUILD_COMPILER OR
|
|
|
|
NOT OLD_TARGET STREQUAL BUILD_TARGET
|
|
|
|
)
|
2023-11-02 06:50:16 +00:00
|
|
|
configure_file(${TEMPLATE_FILE} ${OUTPUT_FILE})
|
2023-05-01 16:23:47 +00:00
|
|
|
endif()
|
|
|
|
else()
|
2023-11-02 06:50:16 +00:00
|
|
|
configure_file(${TEMPLATE_FILE} ${OUTPUT_FILE})
|
2023-05-01 16:23:47 +00:00
|
|
|
endif()
|