4 space indenting for cmake, attempt to clean up my mess in Makefile
This commit is contained in:
parent
3e7ec6e1e2
commit
ddb3e88376
4 changed files with 115 additions and 72 deletions
|
@ -80,20 +80,20 @@ option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
|
|||
include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
# Add a custom target to regenerate build-info.h when .git/index changes
|
||||
add_custom_target(BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
|
||||
# Add a custom target to regenerate build-info.h when .git/index changes
|
||||
add_custom_target(BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
|
||||
|
||||
# Add a custom command to generate 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
|
||||
)
|
||||
# Add a custom command to generate 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.")
|
||||
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()
|
||||
|
||||
#
|
||||
|
|
83
Makefile
83
Makefile
|
@ -187,40 +187,40 @@ clean:
|
|||
rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult build-info.h
|
||||
|
||||
build-info.h: $(GIT_INDEX)
|
||||
@BUILD_NUMBER="0";\
|
||||
BUILD_COMMIT="unknown";\
|
||||
echo "git rev-list HEAD --count"; REV_LIST=`git rev-list HEAD --count`;\
|
||||
if [ $$? -eq 0 ]; then BUILD_NUMBER=$$REV_LIST; fi;\
|
||||
echo "git rev-parse HEAD"; REV_PARSE=`git rev-parse 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" >> $@;
|
||||
scripts/build-info.sh > $@
|
||||
|
||||
main: examples/main/main.cpp build-info.h ggml.o llama.o common.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out build-info.h,$^) -o $@ $(LDFLAGS)
|
||||
@echo
|
||||
@echo '==== Run ./main -h for help. ===='
|
||||
@echo
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
|
||||
quantize: examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out build-info.h,$^) -o $@ $(LDFLAGS)
|
||||
TARGETS_CPP += main
|
||||
DEPS_main := examples/main/main.cpp ggml.o llama.o common.o
|
||||
EXEC_main :=\
|
||||
@echo;\
|
||||
echo "==== Run ./main -h for help. ====";\
|
||||
echo
|
||||
|
||||
quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out build-info.h,$^) -o $@ $(LDFLAGS)
|
||||
TARGETS_CPP += quantize
|
||||
DEPS_quantize := examples/quantize/quantize.cpp ggml.o llama.o
|
||||
|
||||
perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out build-info.h,$^) -o $@ $(LDFLAGS)
|
||||
TARGETS_CPP += quantize-stats
|
||||
DEPS_quantize-stats := examples/quantize-stats/quantize-stats.cpp ggml.o llama.o
|
||||
|
||||
embedding: examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out build-info.h,$^) -o $@ $(LDFLAGS)
|
||||
TARGETS_CPP += perplexity
|
||||
DEPS_perplexity := examples/perplexity/perplexity.cpp ggml.o llama.o common.o
|
||||
|
||||
vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
|
||||
TARGETS_CPP += embedding
|
||||
DEPS_embedding := examples/embedding/embedding.cpp ggml.o llama.o common.o
|
||||
|
||||
TARGETS_CPP += save-load-state
|
||||
DEPS_save-load-state := examples/save-load-state/save-load-state.cpp ggml.o llama.o common.o
|
||||
|
||||
TARGETS_CPP += vdot
|
||||
DEPS_vdot := pocs/vdot/vdot.cpp ggml.o
|
||||
|
||||
#
|
||||
# libllama
|
||||
#
|
||||
|
||||
libllama.so: llama.o ggml.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
|
||||
|
@ -229,10 +229,31 @@ libllama.so: llama.o ggml.o $(OBJS)
|
|||
# Tests
|
||||
#
|
||||
|
||||
benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $(filter-out build-info.h,$^) -o $@ $(LDFLAGS)
|
||||
./$@
|
||||
TARGETS_CPP += benchmark
|
||||
DEPS_benchmark := examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS)
|
||||
OUTP_benchmark := benchmark-matmult
|
||||
EXEC_benchmark := ./benchmark-matmult
|
||||
|
||||
.PHONY: tests
|
||||
tests:
|
||||
bash ./tests/run-tests.sh
|
||||
|
||||
#
|
||||
# Templates
|
||||
#
|
||||
|
||||
# C++ template
|
||||
# To use this template:
|
||||
# 1. Add your target to the TARGETS variable: TARGETS_CPP += target
|
||||
# 2. Set target-specific dependencies: DEPS_target := source1 dependency1 dependency2 ...
|
||||
# 3. Optionally, set target-specific output: OUTP_target := output_name
|
||||
# 4. Optionally, set target-specific command: EXEC_target := command
|
||||
define template_cpp
|
||||
OUTP_$(1) ?= $(1)
|
||||
$(1): $$(DEPS_$(1)) $$(OBJS) build-info.h
|
||||
$$(CXX) $$(CXXFLAGS) $$(filter-out build-info.h,$$^) -o $$(OUTP_$(1)) $$(LDFLAGS)
|
||||
$$(if $$(value EXEC_$(1)),$$(EXEC_$(1)))
|
||||
endef
|
||||
|
||||
# This iterates through TARGETS_CPP and call the template for each target
|
||||
$(foreach target,$(TARGETS_CPP),$(eval $(call template_cpp,$(target))))
|
||||
|
|
|
@ -3,38 +3,38 @@ set(COUNT 0)
|
|||
|
||||
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()
|
||||
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()
|
||||
|
||||
if(Git_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE TEMP_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 TEMP_COUNT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE GIT_COUNT_RESULT
|
||||
)
|
||||
if(GIT_HEAD_RESULT EQUAL 0 AND GIT_COUNT_RESULT EQUAL 0)
|
||||
set(HEAD ${TEMP_HEAD})
|
||||
set(COUNT ${TEMP_COUNT})
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE TEMP_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 TEMP_COUNT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE GIT_COUNT_RESULT
|
||||
)
|
||||
if(GIT_HEAD_RESULT EQUAL 0 AND GIT_COUNT_RESULT EQUAL 0)
|
||||
set(HEAD ${TEMP_HEAD})
|
||||
set(COUNT ${TEMP_COUNT})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h" "\
|
||||
|
|
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 HEAD --count)
|
||||
if [ $? -eq 0 ]; then
|
||||
BUILD_NUMBER=$REV_LIST
|
||||
fi
|
||||
|
||||
REV_PARSE=$(git rev-parse 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"
|
Loading…
Add table
Add a link
Reference in a new issue