diff --git a/CMake/version.cmake b/CMake/version.cmake index f2b85e76..46d79642 100644 --- a/CMake/version.cmake +++ b/CMake/version.cmake @@ -1,16 +1,27 @@ -set(tmp) -find_package(Git QUIET) -if(GIT_FOUND) - execute_process(COMMAND ${GIT_EXECUTABLE} - --git-dir=${CMAKE_SOURCE_DIR}/.git describe --tags - OUTPUT_VARIABLE tmp OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() -if(NOT tmp) - # Set this to the latest released version. - # This version is used when using release tarballs +set(SENSEI_VERSION "" CACHE STRING "SENSEI version") + +# Default detection of version +if (SENSEI_VERSION STREQUAL "") + # The default version is the current major release + # This is required for computing version in released + # source tarballs. set(tmp "v4.0.0") + + # If inside a git repo, attempt to inspect the tag instead + # of using the hardcoded value + if (EXISTS ${CMAKE_SOURCE_DIR}/.git) + find_package(Git QUIET) + if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} + --git-dir=${CMAKE_SOURCE_DIR}/.git describe --tags + OUTPUT_VARIABLE tmp OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() + endif () + + # Override the CACHE variable for configure with the computed + # version + set(SENSEI_VERSION ${tmp}) endif() -set(SENSEI_VERSION ${tmp} CACHE STRING "SENSEI version" FORCE) string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*$)" "\\1" SENSEI_VERSION_MAJOR ${SENSEI_VERSION})