version.cmake 4.5 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]+")
6
while("${PADDLE_VERSION}" STREQUAL "")
7
  # Check current branch name
Y
Yu Yang 已提交
8
  execute_process(
9
    COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref ${tmp_version}
10
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
11 12
    OUTPUT_VARIABLE GIT_BRANCH_NAME
    RESULT_VARIABLE GIT_BRANCH_RESULT
Y
Yu Yang 已提交
13
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
14
  if(NOT ${GIT_BRANCH_RESULT})
15
    execute_process(
16 17
      COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --always
              ${tmp_version}
18 19 20 21
      WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
      OUTPUT_VARIABLE GIT_TAG_NAME
      RESULT_VARIABLE GIT_RESULT
      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
22
    if(NOT ${GIT_RESULT})
23
      # Check if current branch is release branch
24
      if(${GIT_BRANCH_NAME} MATCHES "release/${TAG_VERSION_REGEX}")
25
        # Check the tag is a correct version
26
        if(${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}")
27 28
          # if no tag was found, set PADDLE_VERSION to 0.0.0 to represent latest
          set(PADDLE_VERSION "0.0.0")
29
        elseif(${GIT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
30
          string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
31
        else() # otherwise, get the previous git tag name.
32 33
          set(tmp_version "${GIT_TAG_NAME}~1")
        endif()
M
minqiyang 已提交
34
      else()
35 36 37 38 39 40
        execute_process(
          COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags ${tmp_version}
          WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
          OUTPUT_VARIABLE GIT_EXACT_TAG_NAME
          RESULT_VARIABLE GIT_EXACT_TAG_RESULT
          ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
41
        if(NOT ${GIT_EXACT_TAG_NAME})
42
          # Check if current branch is tag branch
43
          if(${GIT_EXACT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
44 45
            string(REPLACE "v" "" PADDLE_VERSION ${GIT_EXACT_TAG_NAME})
          else()
46
            set(PADDLE_VERSION "0.0.0")
47 48
          endif()
        else()
49 50
          # otherwise, we always set PADDLE_VERSION to 0.0.0 to represent latest
          set(PADDLE_VERSION "0.0.0")
51
        endif()
52 53
      endif()
    else()
54
      set(PADDLE_VERSION "0.0.0")
55
      message(WARNING "Cannot add paddle version from git tag")
Y
Yu Yang 已提交
56 57
    endif()
  else()
58
    set(PADDLE_VERSION "0.0.0")
59
    message(WARNING "Cannot add paddle version for wrong git branch result")
Y
Yu Yang 已提交
60 61 62
  endif()
endwhile()

63 64
string(REPLACE "-" "." PADDLE_VER_LIST ${PADDLE_VERSION})
string(REPLACE "." ";" PADDLE_VER_LIST ${PADDLE_VER_LIST})
65 66 67 68 69 70
list(GET PADDLE_VER_LIST 0 PADDLE_MAJOR_VER)
list(GET PADDLE_VER_LIST 1 PADDLE_MINOR_VER)
list(GET PADDLE_VER_LIST 2 PADDLE_PATCH_VER)
math(EXPR PADDLE_VERSION_INTEGER "${PADDLE_MAJOR_VER} * 1000000
    + ${PADDLE_MINOR_VER} * 1000 + ${PADDLE_PATCH_VER}")

71
add_definitions(-DPADDLE_VERSION=${PADDLE_VERSION})
72
add_definitions(-DPADDLE_VERSION_INTEGER=${PADDLE_VERSION_INTEGER})
Y
Yu Yang 已提交
73
message(STATUS "Paddle version is ${PADDLE_VERSION}")
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

# write paddle version
function(version version_file)
  execute_process(
    COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -1
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
    OUTPUT_VARIABLE PADDLE_GIT_COMMIT)
  file(
    WRITE ${version_file}
    "Paddle version: ${PADDLE_VERSION}\n"
    "GIT COMMIT ID: ${PADDLE_GIT_COMMIT}\n"
    "WITH_MKL: ${WITH_MKL}\n"
    "WITH_MKLDNN: ${WITH_MKLDNN}\n"
    "WITH_GPU: ${WITH_GPU}\n"
    "WITH_ROCM: ${WITH_ROCM}\n"
    "WITH_IPU: ${WITH_IPU}\n")
  if(WITH_GPU)
    file(APPEND ${version_file}
         "CUDA version: ${CUDA_VERSION}\n"
         "CUDNN version: v${CUDNN_MAJOR_VERSION}.${CUDNN_MINOR_VERSION}\n")
  endif()
  if(WITH_ROCM)
    file(APPEND ${version_file}
         "HIP version: v${HIP_MAJOR_VERSION}.${HIP_MINOR_VERSION}\n"
         "MIOpen version: v${MIOPEN_MAJOR_VERSION}.${MIOPEN_MINOR_VERSION}\n")
  endif()
  if(WITH_IPU)
    file(APPEND ${version_file} "PopART version: ${POPART_VERSION}\n")
  endif()
  file(APPEND ${version_file}
       "CXX compiler version: ${CMAKE_CXX_COMPILER_VERSION}\n")
  if(TENSORRT_FOUND)
    file(
      APPEND ${version_file}
      "WITH_TENSORRT: ${TENSORRT_FOUND}\n"
      "TensorRT version: v${TENSORRT_MAJOR_VERSION}.${TENSORRT_MINOR_VERSION}.${TENSORRT_PATCH_VERSION}.${TENSORRT_BUILD_VERSION}\n"
    )
  endif()
  if(WITH_LITE)
    file(APPEND ${version_file} "WITH_LITE: ${WITH_LITE}\n"
                                "LITE_GIT_TAG: ${LITE_GIT_TAG}\n")
  endif()
endfunction()