Add proper version management We now have proper sonames in Mac OS X and Linux, proper versioning on the pkg-config file and proper DLL naming in Windows. The version of the library is defined exclusively in 'src/git2.h'; the build scripts read it from there automatically. Signed-off-by: Vicent Marti <tanoku@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a29fcd..a7f9651 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,13 @@
PROJECT(libgit2 C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+FILE(STRINGS "src/git2.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
+
+STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
+STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}")
+STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
+SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
+
# Find required dependencies
FIND_PACKAGE(ZLIB REQUIRED)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} src)
@@ -80,7 +87,8 @@ ENDIF ()
# Compile and link libgit2
ADD_LIBRARY(git2 ${SRC} ${SRC_PLAT} ${SRC_SHA1})
TARGET_LINK_LIBRARIES(git2 ${ZLIB_LIBRARY} ${LIB_SHA1} ${PTHREAD_LIBRARY} ${SQLITE3_LIBRARIES})
-SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION 0.0.1 SOVERSION 0)
+SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
+SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR})
# Install
INSTALL(TARGETS git2
diff --git a/libgit2.pc.in b/libgit2.pc.in
index 83fc82f..ece5f2b 100644
--- a/libgit2.pc.in
+++ b/libgit2.pc.in
@@ -5,7 +5,7 @@ includedir=${prefix}/include
Name: libgit2
Description: The git library, take 2
-Version: 0.0.1
+Version: @version@
Requires: libcrypto
Libs: -L${libdir} -lgit2 -lz -lcrypto
Cflags: -I${includedir}
diff --git a/src/git2.h b/src/git2.h
index e7f56e9..70ab811 100644
--- a/src/git2.h
+++ b/src/git2.h
@@ -26,6 +26,11 @@
#ifndef INCLUDE_git_git_h__
#define INCLUDE_git_git_h__
+#define LIBGIT2_VERSION "0.3.0"
+#define LIBGIT2_VER_MAJOR 0
+#define LIBGIT2_VER_MINOR 3
+#define LIBGIT2_VER_REVISION 0
+
#include "git2/common.h"
#include "git2/errors.h"
#include "git2/zlib.h"
diff --git a/wscript b/wscript
index c2b9fb4..85e38df 100644
--- a/wscript
+++ b/wscript
@@ -104,6 +104,19 @@ def build(bld):
from waflib import Options
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
+def get_libgit2_version(git2_h):
+ import re
+ line = None
+
+ with open(git2_h) as f:
+ line = re.search(r'^#define LIBGIT2_VERSION "(\d\.\d\.\d)"$', f.read(), re.MULTILINE)
+
+ if line is None:
+ raise "Failed to detect libgit2 version"
+
+ return line.group(1)
+
+
def build_library(bld, build_type):
BUILD = {
@@ -115,6 +128,9 @@ def build_library(bld, build_type):
directory = bld.path
sources = directory.ant_glob('src/*.c')
+ # Find the version of the library, from our header file
+ version = get_libgit2_version(directory.find_node("src/git2.h").abspath())
+
# Compile platform-dependant code
# E.g. src/unix/*.c
# src/win32/*.c
@@ -136,12 +152,13 @@ def build_library(bld, build_type):
target='git2',
includes='src',
install_path='${LIBDIR}',
- use=ALL_LIBS
+ use=ALL_LIBS,
+ vnum=version,
)
# On Unix systems, build the Pkg-config entry file
if bld.env.PLATFORM == 'unix' and bld.is_install:
- bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' < ${SRC} > ${TGT}""",
+ bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' -e 's#@version@#%s#' < ${SRC} > ${TGT}""" % version,
source='libgit2.pc.in',
target='libgit2.pc',
install_path='${LIBDIR}/pkgconfig',