diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f4aa374e0b0..55d0478f0bdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/scripts/cmake/dist.cmake b/scripts/cmake/dist.cmake new file mode 100644 index 000000000000..fd7ae8a92240 --- /dev/null +++ b/scripts/cmake/dist.cmake @@ -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 +) diff --git a/scripts/cmake/version.cmake b/scripts/cmake/version.cmake index 7ed9c48f22a8..f0b7b3bfa33e 100644 --- a/scripts/cmake/version.cmake +++ b/scripts/cmake/version.cmake @@ -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")