From 4a8fc43d81e97594691f6afcf5e9adefdcbec9d7 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 3 May 2021 15:08:41 +0100 Subject: [PATCH] Prepare gitcommit.cmake to support multiple output types. I'm about to want to embed the current git commit into a Halibut source file, for which I'll need to add a second output mode to the existing script that finds it out. --- cmake/gitcommit.cmake | 6 +++++- cmake/setup.cmake | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/gitcommit.cmake b/cmake/gitcommit.cmake index 76753aa7..2be90292 100644 --- a/cmake/gitcommit.cmake +++ b/cmake/gitcommit.cmake @@ -37,7 +37,8 @@ else() endif() endif() -file(WRITE "${OUTPUT_FILE}" "\ +if(OUTPUT_TYPE STREQUAL header) + file(WRITE "${OUTPUT_FILE}" "\ /* * cmake_commit.h - string literal giving the source git commit, if known. * @@ -46,3 +47,6 @@ file(WRITE "${OUTPUT_FILE}" "\ const char commitid[] = \"${commit}\"; ") +else() + message(FATAL_ERROR "Set OUTPUT_TYPE when running this script") +endif() diff --git a/cmake/setup.cmake b/cmake/setup.cmake index ffc23184..8b64acc8 100644 --- a/cmake/setup.cmake +++ b/cmake/setup.cmake @@ -44,6 +44,7 @@ add_custom_target(check_git_commit -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DTOPLEVEL_SOURCE_DIR=${CMAKE_SOURCE_DIR} -DOUTPUT_FILE=${INTERMEDIATE_COMMIT_C} + -DOUTPUT_TYPE=header -P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake DEPENDS ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}