Files
mlpack/CMake/CreateGitVersionHeader.cmake
Alexander Leinoff 2330419b86 Removes CMake block termination arguments
Previously CMake block termination commands were required to have arguments
matching the command starting the block. This is no longer necessary and not
the preferred style. This type of change has been implemented in other open
source projects such as: ITK, vxl, and BRAINSTools. It is the preferred style
for KDE. Consistent style practices help improve readability and
maintainability of code.

This was implemented with the shell script:
NOTE: MUST USE GNU compliant version of sed
in else endif endforeach endfunction endmacro endwhile; do
        echo 's/\b'"$c"'\(\s*\)(.\+)/'"$c"'\1()/'
    done >convert.sed \
    && git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' '*CMakeLists.txt' \
       | xargs -0 gsed -i -f convert.sed \
    && rm convert.sed

This is a reimplementation of ITK commit
e52dbe7fa476f6283c9b9d1507fca052355113a4

Fixes #585
2016-03-21 17:23:25 -05:00

30 lines
1.2 KiB
CMake

# Using the CMake tools to create the gitversion.hpp, which just contains
# the implementation of GetVersion() assuming that we are working inside of a
# git repository.
find_package(Git)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE NEW_GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Get the current version, if it exists.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/gitversion.hpp)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/gitversion.hpp
_OLD_GITVERSION_CONTENTS)
string(REGEX REPLACE ".*return \"mlpack git-([0-9a-f]+)\".*" "\\1"
OLD_GIT_REVISION ${_OLD_GITVERSION_CONTENTS})
else()
set(OLD_GIT_REVISION "notfound")
endif()
if("${OLD_GIT_REVISION}" STREQUAL "${NEW_GIT_REVISION}")
message(STATUS "gitversion.hpp is already up to date.")
else()
# Remove the old version.
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/gitversion.hpp)
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/src/mlpack/core/util/gitversion.hpp
"return \"mlpack git-${NEW_GIT_REVISION}\";\n")
message(STATUS "Updated gitversion.hpp.")
endif()