summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-03-06 03:51:29 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-03-06 03:52:39 +0100
commit3304b718aac98103b5fb3c2855bb661887c62aa1 (patch)
tree20e4c8c5fba9c626cfc00ae480a705fe34a7e662
parent10bdf90fe25933148df7e5962d3e56a902a3185c (diff)
downloadxK-3304b718aac98103b5fb3c2855bb661887c62aa1.tar.gz
xK-3304b718aac98103b5fb3c2855bb661887c62aa1.tar.xz
xK-3304b718aac98103b5fb3c2855bb661887c62aa1.zip
Try to use version information from git
-rw-r--r--CMakeLists.txt34
-rw-r--r--config.h.in2
2 files changed, 24 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b6a82ad..1213ab6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,13 +13,25 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
# Version
-set (project_VERSION_MAJOR "0")
-set (project_VERSION_MINOR "9")
-set (project_VERSION_PATCH "2")
-
-set (project_VERSION "${project_VERSION_MAJOR}")
-set (project_VERSION "${project_VERSION}.${project_VERSION_MINOR}")
-set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
+set (project_version "0.9.2")
+
+# Try to append commit ID if it follows a version tag. It might be nicer if
+# we could also detect dirty worktrees but that's very hard to get right.
+find_package (Git)
+set (git_head "${PROJECT_SOURCE_DIR}/.git/HEAD")
+if (GIT_FOUND AND EXISTS ${git_head})
+ configure_file (${git_head} git-head.tag COPYONLY)
+ execute_process (COMMAND ${GIT_EXECUTABLE} describe --tags --match v*
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ RESULT_VARIABLE git_describe_result
+ OUTPUT_VARIABLE git_describe OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if (NOT git_describe_result)
+ string (REGEX REPLACE "^v" "" project_version "${git_describe}")
+ endif (NOT git_describe_result)
+endif (GIT_FOUND AND EXISTS ${git_head})
+
+# Dashes make filenames confusing and upset packaging software
+string (REPLACE "-" "+" project_version_safe "${project_version}")
# Dependencies
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
@@ -197,19 +209,19 @@ endforeach (page)
# CPack
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Experimental IRC client, daemon and bot")
-set (CPACK_PACKAGE_VERSION ${project_VERSION})
+set (CPACK_PACKAGE_VERSION "${project_version_safe}")
set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p.janouch@gmail.com>")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set (CPACK_GENERATOR "TGZ;ZIP")
set (CPACK_PACKAGE_FILE_NAME
- "${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
-set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}")
+ "${PROJECT_NAME}-${project_version_safe}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
+set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_version_safe}")
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
-set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}")
+set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_version_safe}")
set (CPACK_SET_DESTDIR TRUE)
include (CPack)
diff --git a/config.h.in b/config.h.in
index 0ad9559..100ac26 100644
--- a/config.h.in
+++ b/config.h.in
@@ -1,7 +1,7 @@
#ifndef CONFIG_H
#define CONFIG_H
-#define PROGRAM_VERSION "${project_VERSION}"
+#define PROGRAM_VERSION "${project_version}"
#define ZYKLONB_PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${zyklonb_plugin_dir}"
#cmakedefine HAVE_READLINE