Commit 9d1dcca2 by Vicent Marti

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>
parent 7a689719
......@@ -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
......
......@@ -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}
......@@ -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"
......
......@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment