1e1ad8c50SMark Nunberg# Gets the libcouchbase version
2e1ad8c50SMark Nunberg# Sets:
3e1ad8c50SMark Nunberg#  LCB_VERSION: Version string
4e1ad8c50SMark Nunberg#  LCB_CHANGESET: SCM Revision number
5e1ad8c50SMark Nunberg#  LCB_VERSION_HEX Numeric hex version
6e1ad8c50SMark Nunberg#  LCB_VERSION_MAJOR
7e1ad8c50SMark Nunberg#  LCB_VERSION_MINOR
8e1ad8c50SMark Nunberg#  LCB_VERSION_PATCH
9e1ad8c50SMark Nunberg
10e1ad8c50SMark Nunberg## Try git first ##
11e70ee32fSMark NunbergFIND_PROGRAM(GIT_EXECUTABLE NAMES git git.exe)
12bdca123eSMark NunbergMACRO(RUNGIT outvar)
13bdca123eSMark Nunberg    EXECUTE_PROCESS(COMMAND git ${ARGN}
14bdca123eSMark Nunberg        OUTPUT_VARIABLE ${outvar}
152a07f70bSMark Nunberg        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
16bdca123eSMark Nunberg        OUTPUT_STRIP_TRAILING_WHITESPACE)
17bdca123eSMark NunbergENDMACRO()
18bdca123eSMark Nunberg
1932409ce1SSergey Avseyevif (GIT_EXECUTABLE AND NOT LCB_SKIP_GIT_VERSION)
2094c0f067SSergey Avseyev    RUNGIT(LCB_REVDESCRIBE describe --long --abbrev=10)
2124097c37SSergey Avseyev    RUNGIT(LCB_VERSION describe --abbrev=10)
22543b8464SMark Nunberg    STRING(REPLACE "-" "_" LCB_VERSION "${LCB_VERSION}")
2300236339SMark Nunberg    MESSAGE(STATUS "Sanitized VERSION=${LCB_VERSION}")
24bdca123eSMark Nunberg    RUNGIT(LCB_VERSION_CHANGESET rev-parse HEAD)
25bdca123eSMark Nunberg
26e1ad8c50SMark Nunberg    EXECUTE_PROCESS(
27e1ad8c50SMark Nunberg        COMMAND echo ${LCB_VERSION}
28e1ad8c50SMark Nunberg        COMMAND awk -F. "{printf \"0x%0.2d%0.2d%0.2d\", $1, $2, $3}"
292a07f70bSMark Nunberg        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
30e1ad8c50SMark Nunberg        OUTPUT_VARIABLE LCB_VERSION_HEX)
31e1ad8c50SMark NunbergENDIF()
32e1ad8c50SMark Nunberg
3331786854SMark NunbergIF(LCB_VERSION)
3431786854SMark Nunberg    # Have the version information
35c6b6dbceSMark Nunberg    CONFIGURE_FILE(${LCB_GENINFODIR}/distinfo.cmake.in ${LCB_GENINFODIR}/distinfo.cmake)
3631786854SMark NunbergENDIF()
3731786854SMark Nunberg
38e1ad8c50SMark Nunberg# library version
39c6b6dbceSMark NunbergIF(NOT LCB_VERSION AND EXISTS ${LCB_GENINFODIR}/distinfo.cmake)
40c6b6dbceSMark Nunberg    INCLUDE(${LCB_GENINFODIR}/distinfo.cmake)
41e1ad8c50SMark NunbergENDIF()
42e1ad8c50SMark Nunberg
43e1ad8c50SMark NunbergIF (NOT LCB_VERSION)
4400236339SMark Nunberg    SET(LCB_NOGITVERSION ON)
4569f9a4ebSSergey Avseyev    SET(LCB_VERSION "3.0.0")
46e1ad8c50SMark NunbergENDIF()
47e1ad8c50SMark NunbergIF (NOT LCB_VERSION_CHANGESET)
48e1ad8c50SMark Nunberg    SET(LCB_VERSION_CHANGESET "0xdeadbeef")
49e1ad8c50SMark NunbergENDIF()
50e1ad8c50SMark NunbergIF (NOT LCB_VERSION_HEX)
51da2e7c11SSergey Avseyev    SET(LCB_VERSION_HEX 0x030000)
52e1ad8c50SMark NunbergENDIF()
53e1ad8c50SMark Nunberg
54e1ad8c50SMark Nunberg# Now parse the version string
55e1ad8c50SMark NunbergSTRING(REPLACE "." ";" LCB_VERSION_LIST "${LCB_VERSION}")
56e1ad8c50SMark NunbergLIST(GET LCB_VERSION_LIST 0 LCB_VERSION_MAJOR)
57e1ad8c50SMark NunbergLIST(GET LCB_VERSION_LIST 1 LCB_VERSION_MINOR)
58e1ad8c50SMark NunbergLIST(GET LCB_VERSION_LIST 2 LCB_VERSION_PATCH)
59e1ad8c50SMark Nunberg
60b3f8b193SMark Nunberg# Determine the SONAME for the library
61b3f8b193SMark NunbergIF(APPLE)
6269f9a4ebSSergey Avseyev    SET(LCB_SONAME_MAJOR "7")
63b3f8b193SMark NunbergELSE()
6469f9a4ebSSergey Avseyev    SET(LCB_SONAME_MAJOR "6")
65b3f8b193SMark NunbergENDIF()
66397eb8eaSSergey AvseyevSET(LCB_SONAME_FULL "${LCB_SONAME_MAJOR}.0.1")
67b3f8b193SMark Nunberg
68e1ad8c50SMark NunbergMESSAGE(STATUS
69e1ad8c50SMark Nunberg    "libcouchbase ${LCB_VERSION_MAJOR},${LCB_VERSION_MINOR},${LCB_VERSION_PATCH}")
70e1ad8c50SMark NunbergMESSAGE(STATUS "Building libcouchbase ${LCB_VERSION}/${LCB_VERSION_CHANGESET}")
71