Skip to content

Commit

Permalink
Restore snapshot make target in cmake
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pmatilai committed Mar 30, 2023
1 parent 909e0ae commit 4f2627e
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 4f2627e

Please sign in to comment.