[Orxonox-commit 583] r3115 - branches/pch/cmake

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Jun 3 19:45:10 CEST 2009


Author: rgrieder
Date: 2009-06-03 19:45:10 +0200 (Wed, 03 Jun 2009)
New Revision: 3115

Added:
   branches/pch/cmake/SeparateFlags.cmake
   branches/pch/cmake/SetCacheAdvanced.cmake
Modified:
   branches/pch/cmake/FlagUtilities.cmake
Log:
Split the flag parser and the advanced cache writer from "FlagUtilities.cmake".

Modified: branches/pch/cmake/FlagUtilities.cmake
===================================================================
--- branches/pch/cmake/FlagUtilities.cmake	2009-06-03 17:20:36 UTC (rev 3114)
+++ branches/pch/cmake/FlagUtilities.cmake	2009-06-03 17:45:10 UTC (rev 3115)
@@ -23,107 +23,56 @@
  #    Sets the compiler/linker flags. After the flags you can specify more args:
  #    Release, Debug, RelWithDebInfo, MinSizeRel: Build configs (inclusive)
  #    ReleaseAll: Sets the flags of all three release builds
- #    CACHE: Values are witten with SET_CACHE (see above)
+ #    CACHE: Values are witten with SET_CACHE_ADVANCED
  #    FORCE: When writing to the cache, the values are set anyway
  #    Any variable names (like WIN32, MSVC, etc.): Condition (combined with AND)
  #    You can suffix the condition with a NOT if you wish
- #  Functions:
+ #  Function names:
  #    [ADD/SET/REMOVE]_[COMPILER/LINKER]_FLAGS
  #  Caution: -If you use CACHE after calling the macro without CACHE, the value
- #            Will not get written unless FORCE is specified.
+ #            Will not be written unless FORCE is specified.
  #          - Also be aware to always specify the flags in quotes.
  #  Example:
  #    REMOVE_COMPILER_FLAGS("/Gm "asdf" -q"test -foo" CXX ReleaseAll NOT UNIX)
  #    This will only remove the CXX (C++) flags on a non Unix system for the
  #    Release, RelWithDebInfo and MinSizeRel configurations. The macros should
- #    be able to cope with "test -foo" that is like another flag in the string.
+ #    be able to cope with "test -foo" as string argument for a flag.
  #
 
-# Write to the cache by force, but only if the user didn't edit the value
-# Additional argument is the value (may also be a list)
-MACRO(SET_CACHE _varname _type _docstring)
-  SET(_value ${ARGN})
-  IF(NOT "${_type}" MATCHES "^(STRING|BOOL|PATH|FILEPATH)$")
-    MESSAGE(FATAL_ERROR "${_type} is not a valid CACHE entry type")
-  ENDIF()
+INCLUDE(SeparateFlags)
+INCLUDE(SetCacheAdvanced)
 
-  IF(NOT DEFINED _INTERNAL_${_varname} OR "${_INTERNAL_${_varname}}" STREQUAL "${${_varname}}")
-    SET(${_varname} "${_value}" CACHE ${_type} "${_docstring}" FORCE)
-    SET(_INTERNAL_${_varname} "${_value}" CACHE INTERNAL "Do not edit in any case!")
-  ENDIF()
-ENDMACRO(SET_CACHE)
+# Compiler flags, additional arguments:
+# C, CXX: Specify a language, default is both
+MACRO(SET_COMPILER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(SET "C;CXX" "" "${_flags}" "${ARGN}")
+ENDMACRO(SET_COMPILER_FLAGS)
+# Add flags (flags don't get added twice)
+MACRO(ADD_COMPILER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "C;CXX" "" "${_flags}" "${ARGN}")
+ENDMACRO(ADD_COMPILER_FLAGS)
+# Remove flags
+MACRO(REMOVE_COMPILER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "C;CXX" "" "${_flags}" "${ARGN}")
+ENDMACRO(REMOVE_COMPILER_FLAGS)
 
-# Visual studio (esp. IntelliSense) doesn't like dashes to specify arguments
-# Always use foward slashes instead
-IF(MSVC)
-  SET(ARGUMENT_STARTER "/")
-ELSE()
-  SET(ARGUMENT_STARTER "-")
-ENDIF(MSVC)
 
-# Separates a string of flags. " -" or " /" denotes the start of a flag.
-# The same sequence inside double quotation marks is ignored.
-# Spaces not within quotes are cleaned meaningfully.
-# This macro cannot cope with semicolons in the flag string!
-MACRO(SEPARATE_FLAGS _flags _output_variable)
-  SET(_flags_prep " ${_flags} -")
-  STRING(REPLACE " " " ;" _flag_chunks ${_flags_prep}) # Max loop iterations
-  SET(_flag_string)
-  SET(_parsed_flags)
-  # Loop is necessary because the regex engine is greedy
-  FOREACH(_chunk ${_flag_chunks})
-    SET(_flag_string "${_flag_string}${_chunk}")
-    # Replace all " -" and " /" inside quotation marks
-    STRING(REGEX REPLACE "^(([^\"]*\"[^\"]*\")*[^\"]*\"[^\"]*) [/-]([^\"]*\")"
-           "\\1 at 39535493@\\3" _flag_string "${_flag_string}")
-    # Extract one flag if possible
-    SET(_flag)
-    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "${ARGUMENT_STARTER}\\1" _flag "${_flag_string}")
-    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "\\2"  _flag_string "${_flag_string}")
-    IF(NOT _flag STREQUAL _flag_string)
-      LIST(APPEND _parsed_flags "${_flag}")
-    ENDIF(NOT _flag STREQUAL _flag_string)
-  ENDFOREACH(_chunk)
+# Linker flags, additional arguments:
+# EXE, SHARED, MODULE: Specify a linker mode, default is all three
+MACRO(SET_LINKER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(SET "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
+ENDMACRO(SET_LINKER_FLAGS)
+# Add flags (flags don't get added twice)
+MACRO(ADD_LINKER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
+ENDMACRO(ADD_LINKER_FLAGS)
+# Remove flags
+MACRO(REMOVE_LINKER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
+ENDMACRO(REMOVE_LINKER_FLAGS)
 
-  # Re-replace all " -" and " /" inside quotation marks
-  STRING(REGEX REPLACE "@39535493@" " -" ${_output_variable} "${_parsed_flags}")
-ENDMACRO(SEPARATE_FLAGS)
 
 # Internal macro, do not use
-# Modifies the flags according to the mode: set, add or remove
-# Also sets flags according to the CACHE and FORCE parameter.
-# If only CACHE is specified, SET_CACHE() is used.
-MACRO(_INTERNAL_PARSE_FLAGS _mode _flags _varname _write_to_cache _force)
-  SEPARATE_FLAGS("${_flags}" _arg_flag_list)
-
-  IF("${_mode}" STREQUAL "SET")
-    # SET
-    SET(_flag_list "${_arg_flag_list}")
-  ELSE()
-    # ADD or REMOVE
-    SEPARATE_FLAGS("${${_varname}}" _flag_list)
-    FOREACH(_flag ${_arg_flag_list})
-      LIST(${_mode} _flag_list "${_flag}")
-    ENDFOREACH(_flag)
-  ENDIF()
-
-  LIST(REMOVE_DUPLICATES _flag_list)
-  LIST(SORT _flag_list)
-  STRING(REPLACE ";" " " _flag_list "${_flag_list}")
-
-  IF(_write_to_cache)
-    IF(_force)
-      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
-      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
-    ELSE()
-      SET_CACHE(${_varname} STRING "${${_varname}}" "${_flag_list}")
-    ENDIF()
-  ELSE()
-    SET(${_varname} "${_flag_list}")
-  ENDIF()
-ENDMACRO(_INTERNAL_PARSE_FLAGS)
-
-# Internal macro, do not use
 # Parses the given additional arguments and sets the flags to the
 # corresponding variables.
 MACRO(_INTERNAL_PARSE_FLAGS_ARGS _mode _keys _key_postfix _flags)
@@ -154,11 +103,11 @@
     ELSE()
       IF(_invert_condition)
         SET(_invert_condition FALSE)
-    IF(${_arg})
+        IF(${_arg})
           SET(_arg_cond FALSE)
-    ELSE()
+        ELSE()
           SET(_arg_cond TRUE)
-    ENDIF()
+       ENDIF()
       ELSE()
         SET(_arg_cond ${${_arg}})
       ENDIF()
@@ -190,30 +139,39 @@
 ENDMACRO(_INTERNAL_PARSE_FLAGS_ARGS)
 
 
-# Compiler flags, additional arguments:
-# C, CXX: Specify a language, default is both
-MACRO(SET_COMPILER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(SET "C;CXX" "" "${_flags}" "${ARGN}")
-ENDMACRO(SET_COMPILER_FLAGS)
-# Add flags (flags don't get added twice)
-MACRO(ADD_COMPILER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "C;CXX" "" "${_flags}" "${ARGN}")
-ENDMACRO(ADD_COMPILER_FLAGS)
-# Remove flags
-MACRO(REMOVE_COMPILER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "C;CXX" "" "${_flags}" "${ARGN}")
-ENDMACRO(REMOVE_COMPILER_FLAGS)
+# Internal macro, do not use
+# Modifies the flags according to the mode: set, add or remove
+# Also sets flags according to the CACHE and FORCE parameter.
+# If only CACHE is specified, SET_CACHE_ADVANCED() is used.
+MACRO(_INTERNAL_PARSE_FLAGS _mode _flags _varname _write_to_cache _force)
+  SEPARATE_FLAGS("${_flags}" _arg_flag_list)
 
-# Linker flags, additional arguments:
-# EXE, SHARED, MODULE: Specify a linker mode, default is all three
-MACRO(SET_LINKER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(SET "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
-ENDMACRO(SET_LINKER_FLAGS)
-# Add flags (flags don't get added twice)
-MACRO(ADD_LINKER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
-ENDMACRO(ADD_LINKER_FLAGS)
-# Remove flags
-MACRO(REMOVE_LINKER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
-ENDMACRO(REMOVE_LINKER_FLAGS)
+  IF("${_mode}" STREQUAL "SET")
+    # SET
+    SET(_flag_list "${_arg_flag_list}")
+  ELSE()
+    # ADD or REMOVE
+    SEPARATE_FLAGS("${${_varname}}" _flag_list)
+    IF(NOT _flag_list)
+      SET(_flag_list "") # LIST command requires a list in any case
+    ENDIF()
+    FOREACH(_flag ${_arg_flag_list})
+      LIST(${_mode} _flag_list "${_flag}")
+    ENDFOREACH(_flag)
+  ENDIF()
+
+  LIST(REMOVE_DUPLICATES _flag_list)
+  LIST(SORT _flag_list)
+  STRING(REPLACE ";" " " _flag_list "${_flag_list}")
+
+  IF(_write_to_cache)
+    IF(_force)
+      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
+      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
+    ELSE()
+      SET_CACHE_ADVANCED(${_varname} STRING "${${_varname}}" "${_flag_list}")
+    ENDIF()
+  ELSE()
+    SET(${_varname} "${_flag_list}")
+  ENDIF()
+ENDMACRO(_INTERNAL_PARSE_FLAGS)

Added: branches/pch/cmake/SeparateFlags.cmake
===================================================================
--- branches/pch/cmake/SeparateFlags.cmake	                        (rev 0)
+++ branches/pch/cmake/SeparateFlags.cmake	2009-06-03 17:45:10 UTC (rev 3115)
@@ -0,0 +1,63 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Separates a string of program flags like "--blubb -test -D AA".
+ #    " -" or " /" denotes the start of a flag.
+ #    The same sequence inside double quotation marks is being ignored.
+ #    Spaces not within quotes are cleaned meaningfully.
+ #  Note:
+ #    This macro cannot cope with semicolons in the flag string!
+
+FUNCTION(SEPARATE_FLAGS _flags _output_variable)
+  # Visual studio (esp. IntelliSense) doesn't like dashes to specify arguments
+  # Always use foward slashes instead
+  IF(MSVC)
+    SET(_argument_starter "/")
+  ELSE()
+    SET(_argument_starter "-")
+  ENDIF(MSVC)
+
+  SET(_flags_prep " ${_flags} -")
+  # Separate the chunks
+  STRING(REPLACE " " " ;" _flag_chunks "${_flags_prep}") # Max loop iterations
+  SET(_flag_string)
+  SET(_parsed_flags)
+  # Loop is necessary because the regex engine is greedy
+  FOREACH(_chunk ${_flag_chunks})
+    SET(_flag_string "${_flag_string}${_chunk}")
+    # Replace all " -" and " /" inside quotation marks
+    STRING(REGEX REPLACE "^(([^\"]*\"[^\"]*\")*[^\"]*\"[^\"]*) [/-]([^\"]*\")"
+           "\\1 at 39535493@\\3" _flag_string "${_flag_string}")
+    # Extract one flag if possible
+    SET(_flag)
+    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "${_argument_starter}\\1" _flag "${_flag_string}")
+    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "\\2"  _flag_string "${_flag_string}")
+    IF(NOT _flag STREQUAL _flag_string)
+      STRING(STRIP "${_flag}" _flag_stripped)
+      LIST(APPEND _parsed_flags "${_flag_stripped}")
+    ENDIF(NOT _flag STREQUAL _flag_string)
+  ENDFOREACH(_chunk)
+
+  # Re-replace all " -" and " /" inside quotation marks
+  STRING(REGEX REPLACE "@39535493@" " -" _parsed_flags "${_parsed_flags}")
+  SET(${_output_variable} "${_parsed_flags}" PARENT_SCOPE)
+ENDFUNCTION(SEPARATE_FLAGS)


Property changes on: branches/pch/cmake/SeparateFlags.cmake
___________________________________________________________________
Added: svn:eol-style
   + native

Added: branches/pch/cmake/SetCacheAdvanced.cmake
===================================================================
--- branches/pch/cmake/SetCacheAdvanced.cmake	                        (rev 0)
+++ branches/pch/cmake/SetCacheAdvanced.cmake	2009-06-03 17:45:10 UTC (rev 3115)
@@ -0,0 +1,36 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Write to the cache by force, but only if the user hasn't changed the value
+ #    Additional argument is the value (may also be a list)
+
+FUNCTION(SET_CACHE_ADVANCED _varname _type _docstring)
+  SET(_value ${ARGN})
+  IF(NOT "${_type}" MATCHES "^(STRING|BOOL|PATH|FILEPATH)$")
+    MESSAGE(FATAL_ERROR "${_type} is not a valid CACHE entry type")
+  ENDIF()
+
+  IF(NOT DEFINED _INTERNAL_${_varname} OR "${_INTERNAL_${_varname}}" STREQUAL "${${_varname}}")
+    SET(${_varname} "${_value}" CACHE ${_type} "${_docstring}" FORCE)
+    SET(_INTERNAL_${_varname} "${_value}" CACHE INTERNAL "Do not edit in any case!")
+  ENDIF()
+ENDFUNCTION(SET_CACHE_ADVANCED)


Property changes on: branches/pch/cmake/SetCacheAdvanced.cmake
___________________________________________________________________
Added: svn:eol-style
   + native




More information about the Orxonox-commit mailing list