#
# CMake build script to determine project version number.
#
# this will set PROJECT_VERSION to a string
#
FUNCTION (FindProjectVersion project_path)
# Mercurial
if (EXISTS ${project_path}/.hg)
# first, determine tag
EXECUTE_PROCESS (
COMMAND hg identify --tag
WORKING_DIRECTORY "${project_path}"
RESULT_VARIABLE hg_error_code
OUTPUT_VARIABLE hg_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (hg_error_code)
MESSAGE (FATAL_ERROR "`hg identify --tag` failed")
endif (hg_error_code)
# if tag is other than tip, use that
if ("${hg_tag}" STREQUAL "tip")
# use the revision hash
EXECUTE_PROCESS (
COMMAND hg identify --id
WORKING_DIRECTORY "${project_path}"
RESULT_VARIABLE hg_error_code
OUTPUT_VARIABLE hg_id
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (hg_error_code)
MESSAGE (FATAL_ERROR "`hg identify --id` failed")
endif (hg_error_code)
SET (PROJECT_VERSION "${hg_id}" PARENT_SCOPE)
MESSAGE (STATUS "Version: mercurial tip id: ${hg_id}")
else ("${hg_tag}" STREQUAL "tip")
SET (PROJECT_VERSION "${hg_tag}" PARENT_SCOPE)
MESSAGE (STATUS "Version: mercurial tag: ${hg_tag}")
endif ("${hg_tag}" STREQUAL "tip")
else (EXISTS ${project_path}/.hg)
SET (PROJECT_VERSION "???" PARENT_SCOPE)
MESSAGE (STATUS "No version information available")
endif (EXISTS ${project_path}/.hg)
ENDFUNCTION (FindProjectVersion)