refactor(cmake): Determine version in cmake

We need to have the version string available in multiple places not just
the source code. It is now hardcoded in the root CMakeLists.txt and all
files that need it will be configured with cmake.

This also removed the unecessary duality of GIT_TAG and APP_VERSION and
GIT_TAG_NAMESPACE and APP_VERSION_NAMESPACE.
This commit is contained in:
patrick96 2018-12-14 09:30:17 +01:00 committed by Patrick Ziegler
parent 800d24c92f
commit fc2d2db76f
7 changed files with 17 additions and 86 deletions

View File

@ -22,6 +22,22 @@ endif()
project(polybar C CXX)
set(VERSION_MAJOR "3")
set(VERSION_MINOR "3")
set(VERSION_PATCH "0")
# TODO set APP_VERSION by checking it command was successful
execute_process(COMMAND git describe --tags --dirty=-git
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE APP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(NOT APP_VERSION)
set(APP_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
endif()
STRING(REGEX REPLACE "[^a-zA-Z0-9_]" "_" APP_VERSION_NAMESPACE "v${APP_VERSION}")
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake

View File

@ -1,34 +0,0 @@
#!/bin/sh
main() {
if [ $# -eq 0 ]; then
version=$(git describe --tags --abbrev=0)
set -- "${version%.*}.$((${version##*.}+1))"
fi
git tag "$@" || exit 1
tag_curr="$(git tag --sort=version:refname | tail -1)"
tag_prev="$(git tag --sort=version:refname | tail -2 | head -1)"
if [ -x ./common/version.sh ]; then
./common/version.sh "$tag_curr"
fi
sed -r "s/${tag_prev}/${tag_curr}/g" -i \
README.md CMakeLists.txt \
contrib/polybar.aur/PKGBUILD \
contrib/polybar-git.aur/PKGBUILD
git add -u README.md CMakeLists.txt \
contrib/polybar.aur/PKGBUILD \
contrib/polybar-git.aur/PKGBUILD \
include/version.hpp
git commit -m "build: Bump version to ${tag_curr}"
# Recreate the tag to include the last commit
[ $# -eq 1 ] && git tag -f "$@"
}
main "$@"

View File

@ -1,29 +0,0 @@
#!/bin/sh
msg() {
if [ -t 1 ]; then
printf " \033[1;32m**\033[0m %s\n" "$@"
else
printf "** %s\n" "$@"
fi
}
main() {
if [ $# -eq 0 ]; then
set -- "$(git describe --tags --dirty=-dev)"
fi
GIT_TAG_NAMESPACE=$(echo "v$1" | sed "s/[^a-zA-Z0-9_]/_/g")
msg "Current version: $1"
sed -r "/#define GIT_TAG/s/GIT_TAG .*/GIT_TAG \"$1\"/" -i include/version.hpp
sed -r "/#define GIT_TAG_NAMESPACE/s/GIT_TAG_NAMESPACE .*/GIT_TAG_NAMESPACE $GIT_TAG_NAMESPACE/" -i include/version.hpp
if git diff include/version.hpp 2>/dev/null | grep -q .; then
msg "Updated include/version.hpp"
else
msg "<include/version.hpp> is already up-to-date"
fi
}
main "$@"

View File

@ -24,15 +24,6 @@ if(WITH_XKB)
endif()
string(REPLACE ";" ", " XPP_EXTENSION_LIST "${XPP_EXTENSION_LIST}")
execute_process(COMMAND git describe --tags --dirty=-git
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE APP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(APP_VERSION)
STRING(REGEX REPLACE "[^a-zA-Z0-9_]" "_" APP_VERSION_NAMESPACE "v${APP_VERSION}")
endif()
configure_file(
${CMAKE_CURRENT_LIST_DIR}/settings.hpp.cmake
${CMAKE_BINARY_DIR}/generated-sources/settings.hpp

View File

@ -4,18 +4,9 @@
#include <string>
#include <vector>
#include "version.hpp"
#define APP_NAME "@PROJECT_NAME@"
#cmakedefine APP_VERSION "@APP_VERSION@"
#ifndef APP_VERSION
#define APP_VERSION GIT_TAG
#endif
#cmakedefine APP_VERSION_NAMESPACE @APP_VERSION_NAMESPACE@
#ifndef APP_VERSION_NAMESPACE
#define APP_VERSION_NAMESPACE GIT_TAG_NAMESPACE
#endif
#define BASE_PATH "@PROJECT_SOURCE_DIR@"
#cmakedefine01 ENABLE_ALSA
#cmakedefine01 ENABLE_MPD

View File

@ -1,4 +0,0 @@
#pragma once
#define GIT_TAG "3.3.0"
#define GIT_TAG_NAMESPACE v3_3_0

View File

@ -14,7 +14,7 @@ http_downloader::http_downloader(int connection_timeout) {
curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, connection_timeout);
curl_easy_setopt(m_curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, true);
curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "polybar/" GIT_TAG);
curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "polybar/" APP_VERSION);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, http_downloader::write);
curl_easy_setopt(m_curl, CURLOPT_FORBID_REUSE, true);
}