Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/cmake/tools/SeparateFlags.cmake @ 9348

Last change on this file since 9348 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1 #
2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
4 #
5 #        This program is free software; you can redistribute it and/or
6 #         modify it under the terms of the GNU General Public License
7 #        as published by the Free Software Foundation; either version 2
8 #            of the License, or (at your option) any later version.
9 #
10 #       This program is distributed in the hope that it will be useful,
11 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #                 GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License along
16 #      with this program; if not, write to the Free Software Foundation,
17 #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #
19 #
20 #  Author:
21 #    Reto Grieder
22 #  Description:
23 #    Separates a string of program flags like "--blubb -test -D AA".
24 #    " -" or " /" denotes the start of a flag.
25 #    The same sequence inside double quotation marks is being ignored.
26 #    Spaces not within quotes are cleaned meaningfully.
27 #  Note:
28 #    This macro cannot cope with semicolons in the flag string!
29
30FUNCTION(SEPARATE_FLAGS _flags _output_variable)
31  # Visual studio (esp. IntelliSense) doesn't like dashes to specify arguments
32  # Always use foward slashes instead
33  IF(MSVC)
34    SET(_argument_starter "/")
35  ELSE()
36    SET(_argument_starter "-")
37  ENDIF(MSVC)
38
39  SET(_flags_prep " ${_flags} -")
40  # Separate the chunks
41  STRING(REPLACE " " " ;" _flag_chunks "${_flags_prep}") # Max loop iterations
42  SET(_flag_string)
43  SET(_parsed_flags)
44  # Loop is necessary because the regex engine is greedy
45  FOREACH(_chunk ${_flag_chunks})
46    SET(_flag_string "${_flag_string}${_chunk}")
47    # Replace all " -" and " /" inside quotation marks
48    STRING(REGEX REPLACE "^(([^\"]*\"[^\"]*\")*[^\"]*\"[^\"]*) [/-]([^\"]*\")"
49           "\\1@39535493@\\3" _flag_string "${_flag_string}")
50    # Extract one flag if possible
51    SET(_flag)
52    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "${_argument_starter}\\1" _flag "${_flag_string}")
53    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "\\2"  _flag_string "${_flag_string}")
54    IF(NOT _flag STREQUAL _flag_string)
55      STRING(STRIP "${_flag}" _flag_stripped)
56      LIST(APPEND _parsed_flags "${_flag_stripped}")
57    ENDIF(NOT _flag STREQUAL _flag_string)
58  ENDFOREACH(_chunk)
59
60  # Re-replace all " -" and " /" inside quotation marks
61  STRING(REGEX REPLACE "@39535493@" " -" _parsed_flags "${_parsed_flags}")
62  SET(${_output_variable} "${_parsed_flags}" PARENT_SCOPE)
63ENDFUNCTION(SEPARATE_FLAGS)
Note: See TracBrowser for help on using the repository browser.