1# Gets the libcouchbase version
2# Sets:
3#  LCB_VERSION: Version string
4#  LCB_CHANGESET: SCM Revision number
5#  LCB_VERSION_HEX Numeric hex version
6#  LCB_VERSION_MAJOR
7#  LCB_VERSION_MINOR
8#  LCB_VERSION_PATCH
9
10## Try git first ##
11FIND_PROGRAM(GIT_EXECUTABLE NAMES git git.exe)
12MACRO(RUNGIT outvar)
13    EXECUTE_PROCESS(COMMAND git ${ARGN}
14        OUTPUT_VARIABLE ${outvar}
15        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
16        OUTPUT_STRIP_TRAILING_WHITESPACE)
17ENDMACRO()
18
19if (GIT_EXECUTABLE AND NOT LCB_SKIP_GIT_VERSION)
20    RUNGIT(LCB_REVDESCRIBE describe --long --abbrev=10)
21    RUNGIT(LCB_VERSION describe --abbrev=10)
22    STRING(REPLACE "-" "_" LCB_VERSION "${LCB_VERSION}")
23    MESSAGE(STATUS "Sanitized VERSION=${LCB_VERSION}")
24    RUNGIT(LCB_VERSION_CHANGESET rev-parse HEAD)
25
26    EXECUTE_PROCESS(
27        COMMAND echo ${LCB_VERSION}
28        COMMAND awk -F. "{printf \"0x%0.2d%0.2d%0.2d\", $1, $2, $3}"
29        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
30        OUTPUT_VARIABLE LCB_VERSION_HEX)
31ENDIF()
32
33IF(LCB_VERSION)
34    # Have the version information
35    CONFIGURE_FILE(${LCB_GENINFODIR}/distinfo.cmake.in ${LCB_GENINFODIR}/distinfo.cmake)
36ENDIF()
37
38# library version
39IF(NOT LCB_VERSION AND EXISTS ${LCB_GENINFODIR}/distinfo.cmake)
40    INCLUDE(${LCB_GENINFODIR}/distinfo.cmake)
41ENDIF()
42
43IF (NOT LCB_VERSION)
44    SET(LCB_NOGITVERSION ON)
45    SET(LCB_VERSION "3.0.0-alpha.2")
46ENDIF()
47IF (NOT LCB_VERSION_CHANGESET)
48    SET(LCB_VERSION_CHANGESET "0xdeadbeef")
49ENDIF()
50IF (NOT LCB_VERSION_HEX)
51    SET(LCB_VERSION_HEX 0x030000)
52ENDIF()
53
54# Now parse the version string
55STRING(REPLACE "." ";" LCB_VERSION_LIST "${LCB_VERSION}")
56LIST(GET LCB_VERSION_LIST 0 LCB_VERSION_MAJOR)
57LIST(GET LCB_VERSION_LIST 1 LCB_VERSION_MINOR)
58LIST(GET LCB_VERSION_LIST 2 LCB_VERSION_PATCH)
59
60# Determine the SONAME for the library
61IF(APPLE)
62    SET(LCB_SONAME_MAJOR "4")
63ELSE()
64    SET(LCB_SONAME_MAJOR "3")
65ENDIF()
66SET(LCB_SONAME_FULL "${LCB_SONAME_MAJOR}.0.2")
67
68MESSAGE(STATUS
69    "libcouchbase ${LCB_VERSION_MAJOR},${LCB_VERSION_MINOR},${LCB_VERSION_PATCH}")
70MESSAGE(STATUS "Building libcouchbase ${LCB_VERSION}/${LCB_VERSION_CHANGESET}")
71