mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-31 08:51:55 +00:00 
			
		
		
		
	Add git-based build information for better issue tracking (#1232)
* Add git-based build information for better issue tracking * macOS fix * "build (hash)" and "CMAKE_SOURCE_DIR" changes * Redo "CMAKE_CURRENT_SOURCE_DIR" and clearer build messages * Fix conditional dependency on missing target * Broke out build-info.cmake, added find_package fallback, and added build into to all examples, added dependencies to Makefile * 4 space indenting for cmake, attempt to clean up my mess in Makefile * Short hash, less fancy Makefile, and don't modify build-info.h if it wouldn't change it
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -32,6 +32,7 @@ models/* | |||||||
| /vdot | /vdot | ||||||
| /Pipfile | /Pipfile | ||||||
|  |  | ||||||
|  | build-info.h | ||||||
| arm_neon.h | arm_neon.h | ||||||
| compile_commands.json | compile_commands.json | ||||||
|  |  | ||||||
|   | |||||||
| @@ -72,6 +72,41 @@ option(LLAMA_CLBLAST                "llama: use CLBlast" | |||||||
| option(LLAMA_BUILD_TESTS            "llama: build tests"    ${LLAMA_STANDALONE}) | option(LLAMA_BUILD_TESTS            "llama: build tests"    ${LLAMA_STANDALONE}) | ||||||
| option(LLAMA_BUILD_EXAMPLES         "llama: build examples" ${LLAMA_STANDALONE}) | option(LLAMA_BUILD_EXAMPLES         "llama: build examples" ${LLAMA_STANDALONE}) | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Build info header | ||||||
|  | # | ||||||
|  |  | ||||||
|  | # Write header template to binary dir to keep source directory clean | ||||||
|  | file(WRITE "${CMAKE_BINARY_DIR}/BUILD_INFO.h.in" "\ | ||||||
|  | #ifndef BUILD_INFO_H\n\ | ||||||
|  | #define BUILD_INFO_H\n\ | ||||||
|  | \n\ | ||||||
|  | #define BUILD_NUMBER @BUILD_NUMBER@\n\ | ||||||
|  | #define BUILD_COMMIT \"@BUILD_COMMIT@\"\n\ | ||||||
|  | \n\ | ||||||
|  | #endif // BUILD_INFO_H\n\ | ||||||
|  | ") | ||||||
|  |  | ||||||
|  | # Generate initial build-info.h | ||||||
|  | include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake) | ||||||
|  |  | ||||||
|  | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") | ||||||
|  |     # Add a custom target for build-info.h | ||||||
|  |     add_custom_target(BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h") | ||||||
|  |  | ||||||
|  |     # Add a custom command to rebuild build-info.h when .git/index changes | ||||||
|  |     add_custom_command( | ||||||
|  |         OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h" | ||||||
|  |         COMMENT "Generating build details from Git" | ||||||
|  |         COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake" | ||||||
|  |         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||||||
|  |         DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/.git/index" | ||||||
|  |         VERBATIM | ||||||
|  |     ) | ||||||
|  | else() | ||||||
|  |     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.") | ||||||
|  | endif() | ||||||
|  |  | ||||||
| # | # | ||||||
| # Compile flags | # Compile flags | ||||||
| # | # | ||||||
|   | |||||||
							
								
								
									
										51
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								Makefile
									
									
									
									
									
								
							| @@ -181,41 +181,56 @@ llama.o: llama.cpp ggml.h ggml-cuda.h llama.h llama-util.h | |||||||
| common.o: examples/common.cpp examples/common.h | common.o: examples/common.cpp examples/common.h | ||||||
| 	$(CXX) $(CXXFLAGS) -c $< -o $@ | 	$(CXX) $(CXXFLAGS) -c $< -o $@ | ||||||
|  |  | ||||||
| clean: | libllama.so: llama.o ggml.o $(OBJS) | ||||||
| 	rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult | 	$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS) | ||||||
|  |  | ||||||
| main: examples/main/main.cpp ggml.o llama.o common.o $(OBJS) | clean: | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state build-info.h | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Examples | ||||||
|  | # | ||||||
|  |  | ||||||
|  | main: examples/main/main.cpp build-info.h ggml.o llama.o common.o $(OBJS) | ||||||
|  | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
| 	@echo | 	@echo | ||||||
| 	@echo '====  Run ./main -h for help.  ====' | 	@echo '====  Run ./main -h for help.  ====' | ||||||
| 	@echo | 	@echo | ||||||
|  |  | ||||||
| quantize: examples/quantize/quantize.cpp ggml.o llama.o $(OBJS) | quantize: examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS) | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
|  |  | ||||||
| quantize-stats: examples/quantize-stats/quantize-stats.cpp ggml.o llama.o $(OBJS) | quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS) | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
|  |  | ||||||
| perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o common.o $(OBJS) | perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS) | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
|  |  | ||||||
| embedding: examples/embedding/embedding.cpp ggml.o llama.o common.o $(OBJS) | embedding: examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS) | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
|  |  | ||||||
| vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS) | save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o $(OBJS) | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
|  |  | ||||||
| libllama.so: llama.o ggml.o $(OBJS) | build-info.h: $(wildcard .git/index) scripts/build-info.sh | ||||||
| 	$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS) | 	@scripts/build-info.sh > $@.tmp | ||||||
|  | 	@if ! cmp -s $@.tmp $@; then \ | ||||||
|  | 		mv $@.tmp $@; \ | ||||||
|  | 	else \ | ||||||
|  | 		rm $@.tmp; \ | ||||||
|  | 	fi | ||||||
|  |  | ||||||
| # | # | ||||||
| # Tests | # Tests | ||||||
| # | # | ||||||
|  |  | ||||||
| benchmark-matmult: examples/benchmark/benchmark-matmult.cpp ggml.o $(OBJS) | benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS) | ||||||
| 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | 	$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) | ||||||
| 	./$@ | 	./$@ | ||||||
|  |  | ||||||
|  | vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS) | ||||||
|  | 	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) | ||||||
|  |  | ||||||
| .PHONY: tests | .PHONY: tests | ||||||
| tests: | tests: | ||||||
| 	bash ./tests/run-tests.sh | 	bash ./tests/run-tests.sh | ||||||
|   | |||||||
| @@ -2,3 +2,6 @@ set(TARGET benchmark) | |||||||
| add_executable(${TARGET} benchmark-matmult.cpp) | add_executable(${TARGET} benchmark-matmult.cpp) | ||||||
| target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||||||
| target_compile_features(${TARGET} PRIVATE cxx_std_11) | target_compile_features(${TARGET} PRIVATE cxx_std_11) | ||||||
|  | if(TARGET BUILD_INFO) | ||||||
|  |   add_dependencies(${TARGET} BUILD_INFO) | ||||||
|  | endif() | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include <locale.h> | #include <locale.h> | ||||||
| #include "ggml.h" | #include "ggml.h" | ||||||
|  | #include "build-info.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| #include <math.h> | #include <math.h> | ||||||
| #include <cstring> | #include <cstring> | ||||||
| @@ -90,9 +91,10 @@ int main(int argc, char ** argv)  { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // create the ggml context |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|     printf("Starting Test\n"); |     printf("Starting Test\n"); | ||||||
|  |  | ||||||
|  |     // create the ggml context | ||||||
|     struct ggml_context * ctx; |     struct ggml_context * ctx; | ||||||
|     //const int sizex = 4096; |     //const int sizex = 4096; | ||||||
|     //const int sizey = 11008; |     //const int sizey = 11008; | ||||||
|   | |||||||
| @@ -2,3 +2,6 @@ set(TARGET embedding) | |||||||
| add_executable(${TARGET} embedding.cpp) | add_executable(${TARGET} embedding.cpp) | ||||||
| target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||||||
| target_compile_features(${TARGET} PRIVATE cxx_std_11) | target_compile_features(${TARGET} PRIVATE cxx_std_11) | ||||||
|  | if(TARGET BUILD_INFO) | ||||||
|  |   add_dependencies(${TARGET} BUILD_INFO) | ||||||
|  | endif() | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "common.h" | #include "common.h" | ||||||
| #include "llama.h" | #include "llama.h" | ||||||
|  | #include "build-info.h" | ||||||
|  |  | ||||||
| #include <ctime> | #include <ctime> | ||||||
|  |  | ||||||
| @@ -18,6 +19,8 @@ int main(int argc, char ** argv) { | |||||||
|                 "expect poor results\n", __func__, params.n_ctx); |                 "expect poor results\n", __func__, params.n_ctx); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|  |  | ||||||
|     if (params.seed <= 0) { |     if (params.seed <= 0) { | ||||||
|         params.seed = time(NULL); |         params.seed = time(NULL); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,3 +2,6 @@ set(TARGET main) | |||||||
| add_executable(${TARGET} main.cpp) | add_executable(${TARGET} main.cpp) | ||||||
| target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||||||
| target_compile_features(${TARGET} PRIVATE cxx_std_11) | target_compile_features(${TARGET} PRIVATE cxx_std_11) | ||||||
|  | if(TARGET BUILD_INFO) | ||||||
|  |   add_dependencies(${TARGET} BUILD_INFO) | ||||||
|  | endif() | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ | |||||||
|  |  | ||||||
| #include "common.h" | #include "common.h" | ||||||
| #include "llama.h" | #include "llama.h" | ||||||
|  | #include "build-info.h" | ||||||
|  |  | ||||||
| #include <cassert> | #include <cassert> | ||||||
| #include <cinttypes> | #include <cinttypes> | ||||||
| @@ -81,6 +82,8 @@ int main(int argc, char ** argv) { | |||||||
|                 "expect poor results\n", __func__, params.n_ctx); |                 "expect poor results\n", __func__, params.n_ctx); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|  |  | ||||||
|     if (params.seed <= 0) { |     if (params.seed <= 0) { | ||||||
|         params.seed = time(NULL); |         params.seed = time(NULL); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,3 +2,6 @@ set(TARGET perplexity) | |||||||
| add_executable(${TARGET} perplexity.cpp) | add_executable(${TARGET} perplexity.cpp) | ||||||
| target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||||||
| target_compile_features(${TARGET} PRIVATE cxx_std_11) | target_compile_features(${TARGET} PRIVATE cxx_std_11) | ||||||
|  | if(TARGET BUILD_INFO) | ||||||
|  |   add_dependencies(${TARGET} BUILD_INFO) | ||||||
|  | endif() | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "common.h" | #include "common.h" | ||||||
| #include "llama.h" | #include "llama.h" | ||||||
|  | #include "build-info.h" | ||||||
|  |  | ||||||
| #include <cmath> | #include <cmath> | ||||||
| #include <ctime> | #include <ctime> | ||||||
| @@ -106,6 +107,8 @@ int main(int argc, char ** argv) { | |||||||
|                 "expect poor results\n", __func__, params.n_ctx); |                 "expect poor results\n", __func__, params.n_ctx); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|  |  | ||||||
|     if (params.seed <= 0) { |     if (params.seed <= 0) { | ||||||
|         params.seed = time(NULL); |         params.seed = time(NULL); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| #include "ggml.h" | #include "ggml.h" | ||||||
|  | #include "build-info.h" | ||||||
|  |  | ||||||
| #define LLAMA_API_INTERNAL | #define LLAMA_API_INTERNAL | ||||||
| #include "llama.h" | #include "llama.h" | ||||||
| @@ -308,6 +309,8 @@ int main(int argc, char ** argv) { | |||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|  |  | ||||||
|     // load the model |     // load the model | ||||||
|     fprintf(stderr, "Loading model\n"); |     fprintf(stderr, "Loading model\n"); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,3 +2,6 @@ set(TARGET quantize) | |||||||
| add_executable(${TARGET} quantize.cpp) | add_executable(${TARGET} quantize.cpp) | ||||||
| target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT}) | target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT}) | ||||||
| target_compile_features(${TARGET} PRIVATE cxx_std_11) | target_compile_features(${TARGET} PRIVATE cxx_std_11) | ||||||
|  | if(TARGET BUILD_INFO) | ||||||
|  |   add_dependencies(${TARGET} BUILD_INFO) | ||||||
|  | endif() | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "ggml.h" | #include "ggml.h" | ||||||
| #include "llama.h" | #include "llama.h" | ||||||
|  | #include "build-info.h" | ||||||
|  |  | ||||||
| #include <cstdio> | #include <cstdio> | ||||||
| #include <map> | #include <map> | ||||||
| @@ -50,6 +51,8 @@ int main(int argc, char ** argv) { | |||||||
|         ftype = (enum llama_ftype)atoi(argv[3]); |         ftype = (enum llama_ftype)atoi(argv[3]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|  |  | ||||||
|     int nthread = argc > 4 ? atoi(argv[4]) : 0; |     int nthread = argc > 4 ? atoi(argv[4]) : 0; | ||||||
|  |  | ||||||
|     const int64_t t_main_start_us = ggml_time_us(); |     const int64_t t_main_start_us = ggml_time_us(); | ||||||
|   | |||||||
| @@ -2,3 +2,6 @@ set(TARGET save-load-state) | |||||||
| add_executable(${TARGET} save-load-state.cpp) | add_executable(${TARGET} save-load-state.cpp) | ||||||
| target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||||||
| target_compile_features(${TARGET} PRIVATE cxx_std_11) | target_compile_features(${TARGET} PRIVATE cxx_std_11) | ||||||
|  | if(TARGET BUILD_INFO) | ||||||
|  |   add_dependencies(${TARGET} BUILD_INFO) | ||||||
|  | endif() | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #include "common.h" | #include "common.h" | ||||||
| #include "llama.h" | #include "llama.h" | ||||||
|  | #include "build-info.h" | ||||||
|  |  | ||||||
| #include <vector> | #include <vector> | ||||||
| #include <cstdio> | #include <cstdio> | ||||||
| @@ -17,6 +18,8 @@ int main(int argc, char ** argv) { | |||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); | ||||||
|  |  | ||||||
|     if (params.n_predict < 0) { |     if (params.n_predict < 0) { | ||||||
|         params.n_predict = 16; |         params.n_predict = 16; | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										53
									
								
								scripts/build-info.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								scripts/build-info.cmake
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | |||||||
|  | set(TEMPLATE_FILE "${CMAKE_BINARY_DIR}/BUILD_INFO.h.in") | ||||||
|  | set(HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h") | ||||||
|  | set(BUILD_NUMBER 0) | ||||||
|  | set(BUILD_COMMIT "unknown") | ||||||
|  |  | ||||||
|  | # Look for git | ||||||
|  | find_package(Git) | ||||||
|  | if(NOT Git_FOUND) | ||||||
|  |     execute_process( | ||||||
|  |         COMMAND which git | ||||||
|  |         OUTPUT_VARIABLE GIT_EXECUTABLE | ||||||
|  |         OUTPUT_STRIP_TRAILING_WHITESPACE | ||||||
|  |     ) | ||||||
|  |     if(NOT GIT_EXECUTABLE STREQUAL "") | ||||||
|  |         set(Git_FOUND TRUE) | ||||||
|  |         message(STATUS "Found Git using 'which': ${GIT_EXECUTABLE}") | ||||||
|  |     else() | ||||||
|  |         message(WARNING "Git not found using 'find_package' or 'which'. Build info will not be accurate. Consider installing Git or ensuring it is in the PATH.") | ||||||
|  |     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 | ||||||
|  |         RESULT_VARIABLE GIT_HEAD_RESULT | ||||||
|  |     ) | ||||||
|  |     execute_process( | ||||||
|  |         COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD | ||||||
|  |         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||||||
|  |         OUTPUT_VARIABLE COUNT | ||||||
|  |         OUTPUT_STRIP_TRAILING_WHITESPACE | ||||||
|  |         RESULT_VARIABLE GIT_COUNT_RESULT | ||||||
|  |     ) | ||||||
|  |     if(GIT_HEAD_RESULT EQUAL 0 AND GIT_COUNT_RESULT EQUAL 0) | ||||||
|  |         set(BUILD_COMMIT ${HEAD}) | ||||||
|  |         set(BUILD_NUMBER ${COUNT}) | ||||||
|  |     endif() | ||||||
|  | endif() | ||||||
|  |  | ||||||
|  | # Only write the header if it's changed to prevent unnecessary recompilation | ||||||
|  | if(EXISTS ${HEADER_FILE}) | ||||||
|  |     file(STRINGS ${HEADER_FILE} CONTENTS REGEX "BUILD_COMMIT \"([^\"]*)\"") | ||||||
|  |     list(GET CONTENTS 0 EXISTING) | ||||||
|  |     if(NOT EXISTING STREQUAL "#define BUILD_COMMIT \"${BUILD_COMMIT}\"") | ||||||
|  |         configure_file(${TEMPLATE_FILE} ${HEADER_FILE}) | ||||||
|  |     endif() | ||||||
|  | else() | ||||||
|  |     configure_file(${TEMPLATE_FILE} ${HEADER_FILE}) | ||||||
|  | endif() | ||||||
							
								
								
									
										22
									
								
								scripts/build-info.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								scripts/build-info.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | BUILD_NUMBER="0" | ||||||
|  | BUILD_COMMIT="unknown" | ||||||
|  |  | ||||||
|  | REV_LIST=$(git rev-list --count HEAD) | ||||||
|  | if [ $? -eq 0 ]; then | ||||||
|  |   BUILD_NUMBER=$REV_LIST | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | REV_PARSE=$(git rev-parse --short HEAD) | ||||||
|  | if [ $? -eq 0 ]; then | ||||||
|  |   BUILD_COMMIT=$REV_PARSE | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | echo "#ifndef BUILD_INFO_H" | ||||||
|  | echo "#define BUILD_INFO_H" | ||||||
|  | echo "" | ||||||
|  | echo "#define BUILD_NUMBER $BUILD_NUMBER" | ||||||
|  | echo "#define BUILD_COMMIT \"$BUILD_COMMIT\"" | ||||||
|  | echo "" | ||||||
|  | echo "#endif // BUILD_INFO_H" | ||||||
		Reference in New Issue
	
	Block a user
	 DannyDaemonic
					DannyDaemonic