Skip to content

Commit 9d1dcca

Browse files
author
Vicent Marti
committed
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 parent 7a68971 commit 9d1dcca

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
PROJECT(libgit2 C)
1515
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
1616

17+
FILE(STRINGS "src/git2.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
18+
19+
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
20+
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}")
21+
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
22+
SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
23+
1724
# Find required dependencies
1825
FIND_PACKAGE(ZLIB REQUIRED)
1926
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} src)
@@ -80,7 +87,8 @@ ENDIF ()
8087
# Compile and link libgit2
8188
ADD_LIBRARY(git2 ${SRC} ${SRC_PLAT} ${SRC_SHA1})
8289
TARGET_LINK_LIBRARIES(git2 ${ZLIB_LIBRARY} ${LIB_SHA1} ${PTHREAD_LIBRARY} ${SQLITE3_LIBRARIES})
83-
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION 0.0.1 SOVERSION 0)
90+
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
91+
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR})
8492

8593
# Install
8694
INSTALL(TARGETS git2

libgit2.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ includedir=${prefix}/include
55

66
Name: libgit2
77
Description: The git library, take 2
8-
Version: 0.0.1
8+
Version: @version@
99
Requires: libcrypto
1010
Libs: -L${libdir} -lgit2 -lz -lcrypto
1111
Cflags: -I${includedir}

src/git2.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#ifndef INCLUDE_git_git_h__
2727
#define INCLUDE_git_git_h__
2828

29+
#define LIBGIT2_VERSION "0.3.0"
30+
#define LIBGIT2_VER_MAJOR 0
31+
#define LIBGIT2_VER_MINOR 3
32+
#define LIBGIT2_VER_REVISION 0
33+
2934
#include "git2/common.h"
3035
#include "git2/errors.h"
3136
#include "git2/zlib.h"

wscript

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ def build(bld):
104104
from waflib import Options
105105
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
106106

107+
def get_libgit2_version(git2_h):
108+
import re
109+
line = None
110+
111+
with open(git2_h) as f:
112+
line = re.search(r'^#define LIBGIT2_VERSION "(\d\.\d\.\d)"$', f.read(), re.MULTILINE)
113+
114+
if line is None:
115+
raise "Failed to detect libgit2 version"
116+
117+
return line.group(1)
118+
119+
107120
def build_library(bld, build_type):
108121

109122
BUILD = {
@@ -115,6 +128,9 @@ def build_library(bld, build_type):
115128
directory = bld.path
116129
sources = directory.ant_glob('src/*.c')
117130

131+
# Find the version of the library, from our header file
132+
version = get_libgit2_version(directory.find_node("src/git2.h").abspath())
133+
118134
# Compile platform-dependant code
119135
# E.g. src/unix/*.c
120136
# src/win32/*.c
@@ -136,12 +152,13 @@ def build_library(bld, build_type):
136152
target='git2',
137153
includes='src',
138154
install_path='${LIBDIR}',
139-
use=ALL_LIBS
155+
use=ALL_LIBS,
156+
vnum=version,
140157
)
141158

142159
# On Unix systems, build the Pkg-config entry file
143160
if bld.env.PLATFORM == 'unix' and bld.is_install:
144-
bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' < ${SRC} > ${TGT}""",
161+
bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' -e 's#@version@#%s#' < ${SRC} > ${TGT}""" % version,
145162
source='libgit2.pc.in',
146163
target='libgit2.pc',
147164
install_path='${LIBDIR}/pkgconfig',

0 commit comments

Comments
 (0)