cmake/FindVersion.cmake
author Tero Marttila <terom@fixme.fi>
Thu, 15 Jan 2009 21:33:54 +0200
changeset 396 e1a24791d192
child 397 13fa0546ef87
permissions -rw-r--r--
build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
396
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
# CMake build script to determine project version number.
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
#
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
# this will set PROJECT_VERSION to a string
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
FUNCTION (FindProjectVersion project_path)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
    # XXX: only support mercurial for now
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
    MESSAGE (STATUS "project_path=${project_path}")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
    # first, determine tag
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
    EXECUTE_PROCESS (
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
        COMMAND hg identify --tag
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
        WORKING_DIRECTORY "${project_path}"
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
        RESULT_VARIABLE hg_error_code 
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
        OUTPUT_VARIABLE hg_tag
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
        OUTPUT_STRIP_TRAILING_WHITESPACE
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    )
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    if (hg_error_code)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
        MESSAGE (FATAL_ERROR "`hg identify --tag` failed")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
    endif (hg_error_code)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    # if tag is other than tip, use that
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
    if ("${hg_tag}" STREQUAL "tip")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
        # use the revision hash
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
        EXECUTE_PROCESS (
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
            COMMAND hg identify --id
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
            WORKING_DIRECTORY "${project_path}"
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
            RESULT_VARIABLE hg_error_code 
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
            OUTPUT_VARIABLE hg_id
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
            OUTPUT_STRIP_TRAILING_WHITESPACE
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
        )
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
        if (hg_error_code)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
            MESSAGE (FATAL_ERROR "`hg identify --id` failed")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
        endif (hg_error_code)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
        SET (PROJECT_VERSION "${hg_id}" PARENT_SCOPE)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
        MESSAGE (STATUS "Version: mercurial tip id: ${hg_id}")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
    else ("${hg_tag}" STREQUAL "tip")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
        SET (PROJECT_VERSION "${hg_tag}" PARENT_SCOPE)
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
        MESSAGE (STATUS "Version: mercurial tag: ${hg_tag}")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
    endif ("${hg_tag}" STREQUAL "tip")
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
e1a24791d192 build scripts autodetect project version using 91d96387b359+ tip, and version is included in window title
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
ENDFUNCTION (FindProjectVersion)