From 69269fcba5e699cbc54d1f12b221ce105541333f Mon Sep 17 00:00:00 2001
From: themarex <themarex@042f3d55-54a8-47e9-b7fb-15903f145c44>
Date: Wed, 15 Oct 2014 08:28:43 +0000
Subject: [PATCH] Fix Subversion module in cmake and add astyle

git-svn-id: http://svn.code.sf.net/p/simox/code/trunk@712 042f3d55-54a8-47e9-b7fb-15903f145c44
---
 CMakeLists.txt                    |  21 +++-
 CMakeModules/FindAStyle.cmake     |  13 +++
 CMakeModules/FindSubversion.cmake | 158 ++++++++++++++++++++++++++++++
 armarx.astylerc                   |  48 +++++++++
 4 files changed, 238 insertions(+), 2 deletions(-)
 create mode 100644 CMakeModules/FindAStyle.cmake
 create mode 100644 CMakeModules/FindSubversion.cmake
 create mode 100644 armarx.astylerc

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a136b7923..03dfc8699 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -122,11 +122,14 @@ install(EXPORT SimoxTargets DESTINATION
 #############################################################
 # PACKAGING (DEB)
 
-FIND_PACKAGE(Subversion)
+FIND_PACKAGE(Subversion QUIET)
 IF(Subversion_FOUND)
     Subversion_WC_INFO(${CMAKE_HOME_DIRECTORY} Project)
     MESSAGE("Current revision is ${Project_WC_REVISION}")
-ENDIF(Subversion_FOUND)
+ELSE()
+    SET(Project_WC_REVISION "Unknown")
+    MESSAGE("Could not determine current svn revision.")
+ENDIF()
 
 IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
     SET(CPACK_DEBIAN_ARCHITECTURE "amd64")
@@ -164,5 +167,19 @@ set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Simox C++ Headers")
 SET(CPACK_COMPONENTS_ALL Applications Headers Libraries ApplicationData)
 INCLUDE(CPack)
 
+#############################################################
+# STYLE
+
+FIND_PACKAGE(AStyle QUIET)
+
+if(AStyle_FOUND)
+    add_custom_target(astyle
+                      COMMAND ${AStyle_EXECUTABLE} --options="${PROJECT_SOURCE_DIR}/armarx.astylerc" --recursive --preserve-date --formatted "*.cpp" "*.h" "*.hpp"
+                      WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
+                      COMMENT "Formatting source files in: ${PROJECT_SOURCE_DIR}")
+else()
+    add_custom_target(astyle
+                      COMMENT "Unable to format source files: AStyle was not found!")
+endif()
 
 
diff --git a/CMakeModules/FindAStyle.cmake b/CMakeModules/FindAStyle.cmake
new file mode 100644
index 000000000..a43b5ad67
--- /dev/null
+++ b/CMakeModules/FindAStyle.cmake
@@ -0,0 +1,13 @@
+# This module defines the following variables:
+# AStyle_FOUND      : 1 if astyle was found, 0 otherwise
+# AStyle_EXECUTABLE : astyle executable location
+
+include(FindPackageHandleStandardArgs)
+
+find_program(AStyle_EXECUTABLE astyle)
+
+find_package_handle_standard_args(AStyle DEFAULT_MSG AStyle_EXECUTABLE)
+# Hack: since the macro makes the package name uppercase
+set(AStyle_FOUND ${ASTYLE_FOUND})
+
+mark_as_advanced(AStyle_EXECUTABLE)
diff --git a/CMakeModules/FindSubversion.cmake b/CMakeModules/FindSubversion.cmake
new file mode 100644
index 000000000..c537db877
--- /dev/null
+++ b/CMakeModules/FindSubversion.cmake
@@ -0,0 +1,158 @@
+#.rst:
+# FindSubversion
+# --------------
+#
+# Extract information from a subversion working copy
+#
+# The module defines the following variables:
+#
+# ::
+#
+#   Subversion_SVN_EXECUTABLE - path to svn command line client
+#   Subversion_VERSION_SVN - version of svn command line client
+#   Subversion_FOUND - true if the command line client was found
+#   SUBVERSION_FOUND - same as Subversion_FOUND, set for compatiblity reasons
+#
+#
+#
+# The minimum required version of Subversion can be specified using the
+# standard syntax, e.g.  find_package(Subversion 1.4)
+#
+# If the command line client executable is found two macros are defined:
+#
+# ::
+#
+#   Subversion_WC_INFO(<dir> <var-prefix>)
+#   Subversion_WC_LOG(<dir> <var-prefix>)
+#
+# Subversion_WC_INFO extracts information of a subversion working copy
+# at a given location.  This macro defines the following variables:
+#
+# ::
+#
+#   <var-prefix>_WC_URL - url of the repository (at <dir>)
+#   <var-prefix>_WC_ROOT - root url of the repository
+#   <var-prefix>_WC_REVISION - current revision
+#   <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
+#   <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
+#   <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
+#   <var-prefix>_WC_INFO - output of command `svn info <dir>'
+#
+# Subversion_WC_LOG retrieves the log message of the base revision of a
+# subversion working copy at a given location.  This macro defines the
+# variable:
+#
+# ::
+#
+#   <var-prefix>_LAST_CHANGED_LOG - last log of base revision
+#
+# Example usage:
+#
+# ::
+#
+#   find_package(Subversion)
+#   if(SUBVERSION_FOUND)
+#     Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
+#     message("Current revision is ${Project_WC_REVISION}")
+#     Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
+#     message("Last changed log is ${Project_LAST_CHANGED_LOG}")
+#   endif()
+
+#=============================================================================
+# Copyright 2006-2009 Kitware, Inc.
+# Copyright 2006 Tristan Carel
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+find_program(Subversion_SVN_EXECUTABLE svn
+  PATHS
+    [HKEY_LOCAL_MACHINE\\Software\\TortoiseSVN;Directory]/bin
+  DOC "subversion command line client")
+mark_as_advanced(Subversion_SVN_EXECUTABLE)
+
+if(Subversion_SVN_EXECUTABLE)
+  # the subversion commands should be executed with the C locale, otherwise
+  # the message (which are parsed) may be translated, Alex
+  set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
+  set(ENV{LC_ALL} C)
+
+  execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} --version
+    OUTPUT_VARIABLE Subversion_VERSION_SVN
+    OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  # restore the previous LC_ALL
+  set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
+
+  string(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
+    "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
+
+  macro(Subversion_WC_INFO dir prefix)
+    # the subversion commands should be executed with the C locale, otherwise
+    # the message (which are parsed) may be translated, Alex
+    set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
+    set(ENV{LC_ALL} C)
+
+    execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
+      OUTPUT_VARIABLE ${prefix}_WC_INFO
+      ERROR_VARIABLE Subversion_svn_info_error
+      RESULT_VARIABLE Subversion_svn_info_result
+      OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+    if(NOT ${Subversion_svn_info_result} EQUAL 0)
+#      message(WARNING "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
+    else()
+
+      string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
+        "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
+      string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
+        "\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}")
+      string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
+        "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
+      string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
+        "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
+      string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
+        "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
+      string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
+        "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
+
+    endif()
+
+    # restore the previous LC_ALL
+    set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
+
+  endmacro()
+
+  macro(Subversion_WC_LOG dir prefix)
+    # This macro can block if the certificate is not signed:
+    # svn ask you to accept the certificate and wait for your answer
+    # This macro requires a svn server network access (Internet most of the time)
+    # and can also be slow since it access the svn server
+    execute_process(COMMAND
+      ${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir}
+      OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
+      ERROR_VARIABLE Subversion_svn_log_error
+      RESULT_VARIABLE Subversion_svn_log_result
+      OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+    if(NOT ${Subversion_svn_log_result} EQUAL 0)
+#      message(WARNING "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}")
+    endif()
+  endmacro()
+
+endif()
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE
+                                             VERSION_VAR Subversion_VERSION_SVN )
+
+# for compatibility
+set(Subversion_FOUND ${SUBVERSION_FOUND})
+set(Subversion_SVN_FOUND ${SUBVERSION_FOUND})
diff --git a/armarx.astylerc b/armarx.astylerc
new file mode 100644
index 000000000..494c21be3
--- /dev/null
+++ b/armarx.astylerc
@@ -0,0 +1,48 @@
+# http://astyle.sourceforge.net/astyle.html
+#
+#
+
+# Predefined style option -A3
+--style=allman
+
+# Indent using 4 spaces per indent. Don't use tab -s4
+--indent=spaces=4
+
+# Indent 'switch' blocks so that the 'case X:' statement are 
+# indented in the switch block. -S
+--indent-switches
+
+# Indent multi-line preprocessor definitions ending with a backslash -w
+--indent-preprocessor
+
+# Pad empty lines around header blocks (eg. 'if', 'while' ...) -f
+--break-blocks
+
+# Delete empty lines within a function or method. -x
+#--delete-empty-lines
+
+# Insert space padding around operators. -p
+--pad-oper
+--pad-header
+
+# Remove extra space padding around parenthesis on the inside and outside -U
+--unpad-paren
+
+# Converts tabs into spaces in the non-indentation part of the line -c
+--convert-tabs
+
+# Do not retain a backup of the origional file
+--suffix=none
+
+--indent-namespaces
+--indent-col1-comments
+--min-conditional-indent=0
+
+--align-pointer=type
+#--align-reference=type
+
+--add-brackets
+
+#--break-after-logical
+
+--lineend=linux
-- 
GitLab