From 4f2627e08bf2880a5d16f62a675bba87d027035a Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 30 Mar 2023 10:39:50 +0300 Subject: [PATCH] Restore snapshot make target in cmake Refactor the dist rule into a slightly more generic function that we can call with suitable values for generating dist and snapshot tarballs. This includes preliminaries for requiring a tag for dist tarball but that involves further complications so not done yet. Local HEAD is not exactly the right thing to be building dist tarballs from. --- CMakeLists.txt | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b9742766..387990b8a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,15 +390,27 @@ install(DIRECTORY DESTINATION ${RPMCONFIGDIR}/lua) install(DIRECTORY DESTINATION ${RPMCONFIGDIR}/macros.d) install(FILES CONTRIBUTING.md COPYING CREDITS INSTALL README TYPE DOC) -set(namever ${PROJECT_NAME}-${PROJECT_VERSION}) -set(distfmt tar.gz) -set(distname ${namever}.${distfmt}) -add_custom_command(OUTPUT ${distname} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND git archive - --format=${distfmt} - --output=${CMAKE_BINARY_DIR}/${distname} - --prefix=${namever}/ - HEAD -) -add_custom_target(dist DEPENDS ${distname}) +function(add_tarball targetname namever treeish) + set(distfmt tar.gz) + set(tarname ${namever}.${distfmt}) + add_custom_command(OUTPUT ${tarname} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND git archive + --format=${distfmt} + --output=${CMAKE_BINARY_DIR}/${tarname} + --prefix=${namever}/ + ${treeish} + ) + add_custom_target(${targetname} DEPENDS ${tarname}) +endfunction() + +add_tarball(dist ${PROJECT_NAME}-${PROJECT_VERSION} HEAD) + +if (EXISTS ${CMAKE_SOURCE_DIR}/.git) + execute_process(COMMAND git rev-list --count HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE gitcount + OUTPUT_STRIP_TRAILING_WHITESPACE) + add_tarball(snapshot + ${PROJECT_NAME}-${PROJECT_VERSION}-git${gitcount} HEAD) +endif()