From 0b038448f244a31069779bd0ecd6b7d526ab28a1 Mon Sep 17 00:00:00 2001 From: Julien Michel Date: Mon, 2 Mar 2015 09:55:52 +0100 Subject: [PATCH] CONF: Restauring mercurial revision check, which will enable again the *IsNighltyRevision tests --- CMake/FindMercurial.cmake | 75 +++++++++++++++++++++++++++++++++++++++ CMake/SourceStatus.cmake | 26 ++++++++++++++ CMakeLists.txt | 1 + 3 files changed, 102 insertions(+) create mode 100644 CMake/FindMercurial.cmake create mode 100644 CMake/SourceStatus.cmake diff --git a/CMake/FindMercurial.cmake b/CMake/FindMercurial.cmake new file mode 100644 index 0000000000..487ea156bc --- /dev/null +++ b/CMake/FindMercurial.cmake @@ -0,0 +1,75 @@ +# - Extract information from a mercurial working copy + +# Example usage: +# find_package(Mercurial) +# if(Mercurial_FOUND) +# Mercurial_WC_IDENTIFY(${PROJECT_SOURCE_DIR} Project) +# message("Current revision is ${Project_WC_REVISION}") +# message("Mercurial version is ${Mercurial_VERSION_HG}") +# endif() + + +set(Mercurial_FOUND FALSE) +set(Mercurial_HG_FOUND FALSE) + +find_program(Mercurial_HG_EXECUTABLE hg + DOC "mercurial command line client") +mark_as_advanced(Mercurial_HG_EXECUTABLE) + +if(Mercurial_HG_EXECUTABLE) + set(Mercurial_HG_FOUND TRUE) + set(Mercurial_FOUND TRUE) + + macro(Mercurial_WC_IDENTIFY dir prefix) + # the subversion commands should be executed with the C locale, otherwise + # the message (which are parsed) may be translated, Alex + set(_Mercurial_SAVED_LC_ALL "$ENV{LC_ALL}") + set(ENV{LC_ALL} C) + execute_process(COMMAND ${Mercurial_HG_EXECUTABLE} version + WORKING_DIRECTORY ${dir} + OUTPUT_VARIABLE Mercurial_VERSION_HG + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + + execute_process(COMMAND ${Mercurial_HG_EXECUTABLE} identify ${dir} + OUTPUT_VARIABLE ${prefix}_WC_IDENTIFY +# ERROR_VARIABLE Mercurial_hg_identify_error +# RESULT_VARIABLE Mercurial_hg_identify_result + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + + execute_process(COMMAND ${Mercurial_HG_EXECUTABLE} status -m ${dir} + OUTPUT_VARIABLE ${prefix}_WC_STATUS +# ERROR_VARIABLE Mercurial_hg_status_error +# RESULT_VARIABLE Mercurial_hg_status_result + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + + if(NOT ${Mercurial_hg_identify_result} EQUAL 0) + message(SEND_ERROR "Command \"${Mercurial_HG_EXECUTABLE} identify ${dir}\" failed with output:\n${Mercurial_hg_identify_error}") + else() + + string(REGEX REPLACE "^(.*\n)?Mercurial Distributed SCM [(]version ([.0-9]+).*" + "\\2" Mercurial_VERSION_HG "${Mercurial_VERSION_HG}") + string(REGEX REPLACE "^(.*\n)?([0-9a-f]+).*" + "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_IDENTIFY}") + + endif() + + # restore the previous LC_ALL + set(ENV{LC_ALL} ${_Mercurial_SAVED_LC_ALL}) + + endmacro() + + + +endif() + + + +if(NOT Mercurial_FOUND) + if(NOT Mercurial_FIND_QUIETLY) + message(STATUS "Mercurial was not found.") + else() + if(Mercurial_FIND_REQUIRED) + message(FATAL_ERROR "Mercurial was not found.") + endif() + endif() +endif() diff --git a/CMake/SourceStatus.cmake b/CMake/SourceStatus.cmake new file mode 100644 index 0000000000..b6d94836dc --- /dev/null +++ b/CMake/SourceStatus.cmake @@ -0,0 +1,26 @@ +find_package(Mercurial) +if(Mercurial_FOUND) + message(STATUS "Repository status :") + Mercurial_WC_IDENTIFY(${PROJECT_SOURCE_DIR} OTB) + message(STATUS " Mercurial version is ${Mercurial_VERSION_HG}") + message(STATUS " Repository revision is ${OTB_WC_REVISION}") + set(OTB_WC_REVISION ${OTB_WC_REVISION} CACHE STRING "Repository version" FORCE) + mark_as_advanced(OTB_WC_REVISION) + if(OTB_WC_STATUS) + message(STATUS " Local file modifications:") + string(REPLACE "\n" "\n-- " OTB_WC_STATUS_PRETTYPRINT " ${OTB_WC_STATUS}") + message(STATUS "${OTB_WC_STATUS_PRETTYPRINT}") + else() + message(STATUS " No files modified locally") + endif() + string(REGEX REPLACE "\n" ";" OTB_WC_STATUS "${OTB_WC_STATUS}") + set(OTB_WC_STATUS ${OTB_WC_STATUS} CACHE STRING "Repository status" FORCE) + mark_as_advanced(OTB_WC_STATUS) + + if(OTB_DATA_ROOT) + Mercurial_WC_IDENTIFY(${OTB_DATA_ROOT} OTB_DATA) + set(OTB_DATA_WC_REVISION ${OTB_DATA_WC_REVISION} CACHE STRING "Repository version" FORCE) + mark_as_advanced(OTB_DATA_WC_REVISION) + endif() + +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f43b752c6..774a08c753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ if( CMAKE_HOST_WIN32 ) endif() set(CMAKE_MODULE_PATH ${OTB_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH}) +include (SourceStatus) include(PreventInSourceBuilds) include(PreventInBuildInstalls) include(OTBModuleMacros) -- GitLab