diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ac9f70ab14b4176828ac516b57d7df8223b2d42..7b4242374914b83a73454199a670c1bd77993b2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,28 +73,8 @@ include(coveralls) # Set PaddlePaddle version to Git tag name or Git commit ID. find_package(Git REQUIRED) -execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match --abbrev=0 - WORKING_DIRECTORY ${PROJ_ROOT} - OUTPUT_VARIABLE GIT_TAG_NAME - RESULT_VARIABLE GIT_RESULT - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -if(NOT ${GIT_RESULT}) - set(PADDLE_VERSION ${GIT_TAG_NAME}) -else() - execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 --format=%h - WORKING_DIRECTORY ${PROJ_ROOT} - OUTPUT_VARIABLE GIT_SHA1 - RESULT_VARIABLE GIT_RESULT - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT ${GIT_RESULT}) - set(PADDLE_VERSION ${GIT_SHA1}) - else() - set(PADDLE_VERSION "unknown") - message(WARNING "Cannot add paddle version from git tag") - endif() -endif() +# version.cmake will get the current PADDLE_VERSION +include(version) add_definitions(-DPADDLE_VERSION=\"${PADDLE_VERSION}\") diff --git a/cmake/version.cmake b/cmake/version.cmake new file mode 100644 index 0000000000000000000000000000000000000000..a0518e07e88a1ff468c301523f888c7d95e15185 --- /dev/null +++ b/cmake/version.cmake @@ -0,0 +1,24 @@ +# Get the latest git tag. +set(PADDLE_VERSION $ENV{PADDLE_VERSION}) +set(tmp_version "HEAD") +while ("${PADDLE_VERSION}" STREQUAL "") + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 ${tmp_version} + WORKING_DIRECTORY ${PROJ_ROOT} + 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 + if (${GIT_TAG_NAME} MATCHES "v[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?") + 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() + +message(STATUS "Paddle version is ${PADDLE_VERSION}")