tools.cmake 2.63 KB
Newer Older
Simon Spannagel's avatar
Simon Spannagel committed
1
2
3
4
5
6
7
8
9
# Retrieve the project version string from git describe
FUNCTION(get_version PROJECT_VERSION)
    # Check if this is a source tarball build
    IF(NOT IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
        SET(SOURCE_PACKAGE 1)
    ENDIF(NOT IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)

    # Set package version
    IF(NOT SOURCE_PACKAGE)
10
11
        SET(TAG_FOUND FALSE)

Simon Spannagel's avatar
Simon Spannagel committed
12
13
14
15
16
17
18
19
20
21
22
23
        # Get the version from last git tag plus number of additional commits:
        FIND_PACKAGE(Git QUIET)
        IF(GIT_FOUND)
            EXEC_PROGRAM(git ${CMAKE_CURRENT_SOURCE_DIR} ARGS describe --tags HEAD OUTPUT_VARIABLE ${PROJECT_VERSION})
            STRING(REGEX REPLACE "^release-" "" ${PROJECT_VERSION} ${${PROJECT_VERSION}})
            STRING(REGEX REPLACE "([v0-9.]+)-([0-9]+)-([A-Za-z0-9]+)" "\\1+\\2^\\3" ${PROJECT_VERSION} ${${PROJECT_VERSION}})
            EXEC_PROGRAM(git ARGS status --porcelain ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE PROJECT_STATUS)
            IF(PROJECT_STATUS STREQUAL "")
                MESSAGE(STATUS "Git project directory is clean.")
            ELSE(PROJECT_STATUS STREQUAL "")
                MESSAGE(STATUS "Git project directory is dirty:\n ${PROJECT_STATUS}.")
            ENDIF(PROJECT_STATUS STREQUAL "")
24
25
26
27
28

            EXEC_PROGRAM(git ${CMAKE_CURRENT_SOURCE_DIR} ARGS describe --exact-match --tags HEAD OUTPUT_VARIABLE GIT_TAG RETURN_VALUE GIT_RETURN)
            IF(GIT_RETURN EQUAL 0)
                SET(TAG_FOUND TRUE)
            ENDIF()
Simon Spannagel's avatar
Simon Spannagel committed
29
30
31
32
33
34
        ELSE(GIT_FOUND)
            MESSAGE(STATUS "Git repository present, but could not find git executable.")
        ENDIF(GIT_FOUND)
    ELSE(NOT SOURCE_PACKAGE)
        # If we don't have git we can not really do anything
        MESSAGE(STATUS "Source tarball build - no repository present.")
35
        SET(TAG_FOUND TRUE)
Simon Spannagel's avatar
Simon Spannagel committed
36
37
    ENDIF(NOT SOURCE_PACKAGE)

38
39
40
    # Set the project version in the parent scope
    SET(TAG_FOUND ${TAG_FOUND} PARENT_SCOPE)

Simon Spannagel's avatar
Simon Spannagel committed
41
42
43
    # Set the project version in the parent scope
    SET(${PROJECT_VERSION} ${${PROJECT_VERSION}} PARENT_SCOPE)
ENDFUNCTION()
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

FUNCTION(add_runtime_dep RUNTIME_NAME)
    GET_FILENAME_COMPONENT(THISPROG ${RUNTIME_NAME} PROGRAM)
    LIST(APPEND CORRY_RUNTIME_DEPS ${THISPROG})
    LIST(REMOVE_DUPLICATES CORRY_RUNTIME_DEPS)
    SET(CORRY_RUNTIME_DEPS ${CORRY_RUNTIME_DEPS} CACHE INTERNAL "CORRY_RUNTIME_DEPS")
ENDFUNCTION()

FUNCTION(add_runtime_lib RUNTIME_NAME)
    FOREACH(name ${RUNTIME_NAME})
        GET_FILENAME_COMPONENT(THISLIB ${name} DIRECTORY)
        LIST(APPEND CORRY_RUNTIME_LIBS ${THISLIB})
        LIST(REMOVE_DUPLICATES CORRY_RUNTIME_LIBS)
        SET(CORRY_RUNTIME_LIBS ${CORRY_RUNTIME_LIBS} CACHE INTERNAL "CORRY_RUNTIME_LIBS")
    ENDFOREACH()
ENDFUNCTION()