From 52f2779a6d0ffb5fb17c6581c79d7d5444193345 Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Wed, 10 May 2023 20:10:22 +0000 Subject: [PATCH] add git hash as a property --- CMakeLists.txt | 21 +++++++++++++++++++++ GNUmakefile | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc67843..9420727 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,3 +60,24 @@ install(EXPORT CsgEbConfig if (CSG_CGAL_ENABLED) target_compile_definitions(csg-eb PUBLIC USE_CGAL) endif() + +set(CSGEB_GIT_HASH "") +execute_process( + COMMAND git describe --abbrev=12 --dirty --always --tags + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE CSGEB_GIT_HASH + ERROR_VARIABLE _tmperr + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +if(_tmperr) + message(WARNING "Failing to retrieve Git commit from repo: ${PROJECT_SOURCE_DIR}") +endif() +set_target_properties(csg-eb PROPERTIES CSGEB_GIT_HASH ${CSGEB_GIT_HASH} + EXPORT_PROPERTIES CSGEB_GIT_HASH) + +# to be used by gnumake +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CsgEbConfig.mk + "CSGEB_GIT_HASH := ${CSGEB_GIT_HASH}") +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CsgEbConfig.mk + DESTINATION "${CMAKE_INSTALL_PREFIX}" +) diff --git a/GNUmakefile b/GNUmakefile index 80d2bee..0ad76b4 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -8,6 +8,7 @@ TARGET ?= libcsg-eb.a BUILD_DIR ?= ./build +CONFIG_FILE ?= CsgEbConfig.mk SRCFILENAMES := csg.cpp \ levelset_2d.cpp \ @@ -46,11 +47,15 @@ $(BUILD_DIR)/%.cpp.o: %.cpp $(MKDIR_P) $(dir $@) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -std=c++17 -c $< -o $@ +$(CONFIG_FILE): $(TARGET) + @echo "CSGEB_GIT_HASH := $(shell git describe --abbrev=12 --dirty --always --tags)" > $@ + .PHONY: install -install: $(TARGET) +install: $(TARGET) $(CONFIG_FILE) @$(MKDIR_P) $(DESTDIR)/lib $(DESTDIR)/include install -m 0755 $< $(DESTDIR)/lib install -m 0755 include/*.hpp $(DESTDIR)/include + install -m 0755 $(CONFIG_FILE) $(DESTDIR) .PHONY: clean clean: -- GitLab