@@ -76,23 +76,31 @@ option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
76
76
# Build info header
77
77
#
78
78
79
- # Write header template to binary dir to keep source directory clean
80
- file (WRITE "${CMAKE_BINARY_DIR} /BUILD_INFO.h.in" "\
81
- #ifndef BUILD_INFO_H\n\
82
- #define BUILD_INFO_H\n\
83
- \n\
84
- #define BUILD_NUMBER @BUILD_NUMBER@\n\
85
- #define BUILD_COMMIT \" @BUILD_COMMIT@\"\n\
86
- \n\
87
- #endif // BUILD_INFO_H\n\
88
- " )
89
-
90
79
# Generate initial build-info.h
91
80
include (${CMAKE_CURRENT_SOURCE_DIR} /scripts/build-info.cmake )
92
81
93
82
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /.git" )
83
+ set (GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /.git" )
84
+
85
+ # Is git submodule
86
+ if (NOT IS_DIRECTORY "${GIT_DIR} " )
87
+ file (READ ${GIT_DIR} REAL_GIT_DIR_LINK )
88
+ string (REGEX REPLACE "gitdir: (.*)\n $" "\\ 1" REAL_GIT_DIR ${REAL_GIT_DIR_LINK} )
89
+ set (GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /${REAL_GIT_DIR} " )
90
+ endif ()
91
+
94
92
# Add a custom target for build-info.h
95
93
add_custom_target (BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR} /build-info.h" )
94
+
95
+ # Add a custom command to rebuild build-info.h when .git/index changes
96
+ add_custom_command (
97
+ OUTPUT "${CMAKE_CURRENT_SOURCE_DIR} /build-info.h"
98
+ COMMENT "Generating build details from Git"
99
+ COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR} /scripts/build-info.cmake"
100
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
101
+ DEPENDS "${GIT_DIR} /index"
102
+ VERBATIM
103
+ )
96
104
else ()
97
105
message (WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository." )
98
106
endif ()
0 commit comments