version.cmake 1.2 KB
Newer Older
Y
Yu Yang 已提交
1 2 3
# Get the latest git tag.
set(PADDLE_VERSION $ENV{PADDLE_VERSION})
set(tmp_version "HEAD")
M
minqiyang 已提交
4
set(TAG_VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
5
set(COMMIT_VERSION_REGEX "[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+")
Y
Yu Yang 已提交
6 7
while ("${PADDLE_VERSION}" STREQUAL "")
  execute_process(
M
minqiyang 已提交
8
    COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --always ${tmp_version}
9
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
Y
Yu Yang 已提交
10 11 12 13 14
    OUTPUT_VARIABLE GIT_TAG_NAME
    RESULT_VARIABLE GIT_RESULT
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  if (NOT ${GIT_RESULT})
    # Check the tag is a correct version
M
minqiyang 已提交
15 16 17
    if (${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}")
      # if no tag was found, set PADDLE_VERSION to latest
      set(PADDLE_VERSION "latest")
18
    elseif (${GIT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
Y
Yu Yang 已提交
19 20 21 22 23 24 25 26 27 28
      string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
    else()  # otherwise, get the previous git tag name.
      set(tmp_version "${GIT_TAG_NAME}~1")
    endif()
  else()
    set(PADDLE_VERSION "0.0.0")
    message(WARNING "Cannot add paddle version from git tag")
  endif()
endwhile()

L
liaogang 已提交
29
add_definitions(-DPADDLE_VERSION=${PADDLE_VERSION})
Y
Yu Yang 已提交
30
message(STATUS "Paddle version is ${PADDLE_VERSION}")