Skip to content

Commit

Permalink
cmake: add dist target
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Jankowski <[email protected]>
  • Loading branch information
jajanusz authored and lgirdwood committed Feb 5, 2019
1 parent 6e26683 commit 8d408eb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ set(VERSION_H_PATH ${GENERATED_DIRECTORY}/include/version.h)
include(scripts/cmake/version.cmake)
sof_add_version_h_rule(${PROJECT_SOURCE_DIR}/scripts/cmake/version.cmake)

include(scripts/cmake/dist.cmake)

include(scripts/cmake/defconfigs.cmake)

# cmake itself cannot depend on files that don't exist
Expand Down
19 changes: 19 additions & 0 deletions scripts/cmake/dist.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# depends on version.cmake
# Adds dist target

set(TARBALL_PATH_TMP "${PROJECT_BINARY_DIR}/sof-${GIT_TAG}.tar")
set(TARBALL_PATH "${PROJECT_BINARY_DIR}/sof-${GIT_TAG}.tgz")
set(TARBALL_VERSION_BINARY_PATH "${PROJECT_BINARY_DIR}/${TARBALL_VERSION_FILE_NAME}")

add_custom_target(dist
COMMAND git archive -o "${TARBALL_PATH_TMP}" HEAD
COMMAND ${CMAKE_COMMAND} -E echo "${GIT_TAG}" > "${TARBALL_VERSION_BINARY_PATH}"
COMMAND ${CMAKE_COMMAND} -E echo "${GIT_LOG_HASH}" >> "${TARBALL_VERSION_BINARY_PATH}"
COMMAND tar rf "${TARBALL_PATH_TMP}" -C "${PROJECT_BINARY_DIR}" "${TARBALL_VERSION_FILE_NAME}"
COMMAND gzip -9 < "${TARBALL_PATH_TMP}" > "${TARBALL_PATH}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Creating tarball: ${TARBALL_PATH}"
BYPRODUCTS "$TARBALL_VERSION_BINARY_PATH" "${TARBALL_PATH_TMP}" "${TARBALL_PATH}"
VERBATIM
USES_TERMINAL
)
31 changes: 21 additions & 10 deletions scripts/cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
cmake_minimum_required(VERSION 3.10)

execute_process(COMMAND git describe --abbrev=4
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
set(TARBALL_VERSION_FILE_NAME ".tarball-version")
set(TARBALL_VERSION_SOURCE_PATH "${PROJECT_SOURCE_DIR}/${TARBALL_VERSION_FILE_NAME}")

execute_process(COMMAND git log --pretty=format:%h -1
OUTPUT_VARIABLE GIT_LOG_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(EXISTS ${TARBALL_VERSION_SOURCE_PATH})
file(STRINGS ${TARBALL_VERSION_SOURCE_PATH} lines ENCODING "UTF-8")
list(GET lines 0 GIT_TAG)
list(GET lines 1 GIT_LOG_HASH)
message(STATUS "Found ${TARBALL_VERSION_FILE_NAME}")
message(STATUS "Version: ${GIT_TAG} / ${GIT_LOG_HASH}")
else()
execute_process(COMMAND git describe --abbrev=4
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)

execute_process(COMMAND git log --pretty=format:%h -1
OUTPUT_VARIABLE GIT_LOG_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()

if(NOT GIT_TAG MATCHES "^v")
set(GIT_TAG "v0.0-0-g0000")
Expand Down

0 comments on commit 8d408eb

Please sign in to comment.