]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Refactor setup_git.cmake into its own macro
authorMatthias Maier <matthias.maier@iwr.uni-heidelberg.de>
Wed, 21 Jan 2015 17:40:32 +0000 (18:40 +0100)
committerMatthias Maier <tamiko@43-1.org>
Fri, 23 Jan 2015 14:00:07 +0000 (15:00 +0100)
CMakeLists.txt
cmake/macros/macro_deal_ii_query_git_information.cmake [new file with mode: 0644]
cmake/setup_git.cmake [deleted file]
cmake/setup_write_config.cmake

index 4f2c02d7a8791f74769c853234c7761a8fd53365..07032657f4cd03b48855a0a1adcb70223cf3e5ba 100644 (file)
@@ -126,7 +126,6 @@ ENDFOREACH()
 VERBOSE_INCLUDE(${CMAKE_SOURCE_DIR}/cmake/setup_cpack.cmake)
 VERBOSE_INCLUDE(${CMAKE_SOURCE_DIR}/cmake/setup_custom_targets.cmake)
 VERBOSE_INCLUDE(${CMAKE_SOURCE_DIR}/cmake/setup_finalize.cmake)
-VERBOSE_INCLUDE(${CMAKE_SOURCE_DIR}/cmake/setup_git.cmake)
 VERBOSE_INCLUDE(${CMAKE_SOURCE_DIR}/cmake/setup_write_config.cmake)
 
 ########################################################################
diff --git a/cmake/macros/macro_deal_ii_query_git_information.cmake b/cmake/macros/macro_deal_ii_query_git_information.cmake
new file mode 100644 (file)
index 0000000..6ca84c0
--- /dev/null
@@ -0,0 +1,94 @@
+## ---------------------------------------------------------------------
+##
+## Copyright (C) 2015 by the deal.II authors
+##
+## This file is part of the deal.II library.
+##
+## The deal.II library is free software; you can use it, redistribute
+## it, and/or modify it under the terms of the GNU Lesser General
+## Public License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+## The full text of the license can be found in the file LICENSE at
+## the top level of the deal.II distribution.
+##
+## ---------------------------------------------------------------------
+
+#
+# This file implements the DEAL_II_QUERY_GIT_INFORMATION macro, which is
+# part of the deal.II library.
+#
+# Usage:
+#       DEAL_II_QUERY_GIT_INFORMATION()
+#
+# This will try to gather information about current branch, as well as
+# short and long revision. If ${CMAKE_SOURCE_DIR} is the root of a git
+# repository the following variables will be populated:
+#
+#       DEAL_II_GIT_BRANCH
+#       DEAL_II_GIT_REVISION
+#       DEAL_II_GIT_SHORTREV
+#
+
+MACRO(DEAL_II_QUERY_GIT_INFORMATION)
+
+  MESSAGE(STATUS "Query git repository information.")
+
+  FIND_PACKAGE(Git)
+
+  #
+  # Only run the following if we have git and the source directory seems to
+  # be under version control.
+  #
+  IF(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
+    #
+    # Bogus configure_file calls to trigger a reconfigure, and thus an
+    # update of branch and commit information every time HEAD has changed.
+    #
+    CONFIGURE_FILE(
+      ${CMAKE_SOURCE_DIR}/.git/HEAD
+      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/HEAD
+      )
+    FILE(STRINGS ${CMAKE_SOURCE_DIR}/.git/HEAD _head_ref LIMIT_COUNT 1)
+    STRING(REPLACE "ref: " "" _head_ref ${_head_ref})
+    IF(EXISTS ${CMAKE_SOURCE_DIR}/.git/${_head_ref})
+      CONFIGURE_FILE(
+        ${CMAKE_SOURCE_DIR}/.git/${_head_ref}
+        ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/HEAD_REF
+        )
+    ENDIF()
+
+    #
+    # Query for revision:
+    #
+
+    EXECUTE_PROCESS(
+       COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%H %h"
+       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+       OUTPUT_VARIABLE _info
+       RESULT_VARIABLE _result
+       OUTPUT_STRIP_TRAILING_WHITESPACE
+       )
+    IF(${_result} EQUAL 0)
+      STRING(REGEX REPLACE "^\"([^ ]+) ([^ ]+)\"$"
+        "\\1" DEAL_II_GIT_REVISION "${_info}")
+      STRING(REGEX REPLACE "^\"([^ ]+) ([^ ]+)\"$"
+        "\\2" DEAL_II_GIT_SHORTREV "${_info}")
+    ENDIF()
+
+    #
+    # Query for branch:
+    #
+
+    EXECUTE_PROCESS(
+       COMMAND ${GIT_EXECUTABLE} symbolic-ref HEAD
+       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+       OUTPUT_VARIABLE _branch
+       RESULT_VARIABLE _result
+       OUTPUT_STRIP_TRAILING_WHITESPACE
+       )
+    IF(${_result} EQUAL 0)
+      STRING(REGEX REPLACE "refs/heads/" "" DEAL_II_GIT_BRANCH "${_branch}")
+    ENDIF()
+  ENDIF()
+
+ENDMACRO()
diff --git a/cmake/setup_git.cmake b/cmake/setup_git.cmake
deleted file mode 100644 (file)
index ac9f165..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-## ---------------------------------------------------------------------
-##
-## Copyright (C) 2014 - 2015 by the deal.II authors
-##
-## This file is part of the deal.II library.
-##
-## The deal.II library is free software; you can use it, redistribute
-## it, and/or modify it under the terms of the GNU Lesser General
-## Public License as published by the Free Software Foundation; either
-## version 2.1 of the License, or (at your option) any later version.
-## The full text of the license can be found in the file LICENSE at
-## the top level of the deal.II distribution.
-##
-## ---------------------------------------------------------------------
-
-#
-# Query git commit and branch information. If git was found and the source
-# directory is under version control the following variables are populated:
-#
-#     DEAL_II_GIT_BRANCH
-#     DEAL_II_GIT_REVISION
-#     DEAL_II_GIT_SHORTREV
-#
-
-FIND_PACKAGE(Git)
-
-#
-# Only run the following if we have git and the source directory seems to
-# be under version control.
-#
-IF(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
-  #
-  # Bogus configure_file calls to trigger a reconfigure, and thus an update
-  # of branch and commit information every time HEAD has changed.
-  #
-  CONFIGURE_FILE(
-    ${CMAKE_SOURCE_DIR}/.git/HEAD
-    ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/HEAD
-    )
-  FILE(STRINGS ${CMAKE_SOURCE_DIR}/.git/HEAD _head_ref LIMIT_COUNT 1)
-  STRING(REPLACE "ref: " "" _head_ref ${_head_ref})
-  IF(EXISTS ${CMAKE_SOURCE_DIR}/.git/${_head_ref})
-    CONFIGURE_FILE(
-      ${CMAKE_SOURCE_DIR}/.git/${_head_ref}
-      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/HEAD_REF
-      )
-  ENDIF()
-
-  #
-  # Query for branch and commit information:
-  #
-  EXECUTE_PROCESS(
-     COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%H %h"
-     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
-     OUTPUT_VARIABLE _info
-     RESULT_VARIABLE _result
-     OUTPUT_STRIP_TRAILING_WHITESPACE
-     )
-  IF(${_result} EQUAL 0)
-    STRING(REGEX REPLACE "^\"([^ ]+) ([^ ]+)\"$"
-      "\\1" DEAL_II_GIT_REVISION "${_info}")
-    STRING(REGEX REPLACE "^\"([^ ]+) ([^ ]+)\"$"
-      "\\2" DEAL_II_GIT_SHORTREV "${_info}")
-  ENDIF()
-
-  EXECUTE_PROCESS(
-     COMMAND ${GIT_EXECUTABLE} symbolic-ref HEAD
-     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
-     OUTPUT_VARIABLE _branch
-     RESULT_VARIABLE _result
-     OUTPUT_STRIP_TRAILING_WHITESPACE
-     )
-  IF(${_result} EQUAL 0)
-    STRING(REGEX REPLACE "refs/heads/" "" DEAL_II_GIT_BRANCH "${_branch}")
-  ENDIF()
-ENDIF()
-
-FILE(WRITE ${CMAKE_BINARY_DIR}/revision.log
-"###
-#
-#  Git information:
-#        Branch:   ${DEAL_II_GIT_BRANCH}
-#        Revision: ${DEAL_II_GIT_REVISION}
-#
-###"
-  )
index bd56e6de3466660c90519ff03723707c8ee30b6d..c458b72f3566eb47e0c8eaa060492b0f8d5ac7a6 100644 (file)
 ## ---------------------------------------------------------------------
 
 
+########################################################################
+#                                                                      #
+#                Query for git repository information:                 #
+#                                                                      #
+########################################################################
+
+DEAL_II_QUERY_GIT_INFORMATION()
+
+FILE(WRITE ${CMAKE_BINARY_DIR}/revision.log
+"###
+#
+#  Git information:
+#        Branch:   ${DEAL_II_GIT_BRANCH}
+#        Revision: ${DEAL_II_GIT_REVISION}
+#
+###"
+  )
+
+
 ########################################################################
 #                                                                      #
 #              Write a nice configuration summary to file:             #

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.