Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/cmake/tools/ParseMacroArguments.cmake @ 9628

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

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 3.2 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 #    Parses a list of macro arguments which are separated by keywords and
24 #    writes the result to the _arg_KEYWORD variable. Switches are set to their
25 #    literal name if found and the lists contain their elements.
26 #    The order of the arguments is arbitrary.
27 #  Note:
28 #    You have to specify the switches and list_names as a
29 #    semicolon separated list or all hell breaks loose!
30 #  Example:
31 #    The arguments  BLUBB_FILES foo.cc bar.c NO_ASDF  will do the following:
32 #    SET(_arg_NO_ASDF _arg_NO_ASDF)
33 #    SET(_arg_BLUBB_FILES foo.cc bar.c)
34 #    But NO_FOO will not be set at all if it was specified as a switch
35 #
36
37MACRO(PARSE_MACRO_ARGUMENTS _switches _list_names)
38
39  # Using LIST(FIND ...) speeds up the process
40  SET(_keywords ${_switches} ${_list_names})
41
42  # Reset all arguments
43  FOREACH(_arg ${_switches} ${_list_names})
44    SET(_arg_${_arg})
45  ENDFOREACH(_arg)
46
47  # Parse all the arguments and set the corresponding variable
48  # If the option is just a switch, set the variable to its name for later use
49  FOREACH(_arg ${ARGN})
50
51    # Is the argument a keyword?
52    LIST(FIND _keywords ${_arg} _keyword_index)
53    IF(NOT _keyword_index EQUAL -1)
54
55      # Another optimisation
56      SET(_arg_found FALSE)
57      # Switches
58      FOREACH(_switch ${_switches})
59        IF(${_switch} STREQUAL ${_arg})
60          SET(_arg_${_switch} ${_switch})
61          SET(_arg_found TRUE)
62          # Avoid interpreting arguments after this one as options args for the previous one
63          SET(_storage_var)
64          BREAK()
65        ENDIF()
66      ENDFOREACH(_switch)
67
68      # Input options
69      IF(NOT _arg_found)
70        FOREACH(_list_name ${_list_names})
71          IF(${_list_name} STREQUAL ${_arg})
72            SET(_storage_var _arg_${_list_name})
73            BREAK()
74          ENDIF()
75        ENDFOREACH(_list_name)
76      ENDIF(NOT _arg_found)
77
78    ELSE()
79
80      # Arguments of an input option (like source files for SOURCE_FILES)
81      IF(_storage_var)
82        # Store in variable define above in the foreach loop
83        SET(${_storage_var} ${${_storage_var}} ${_arg})
84      ELSE()
85        MESSAGE(FATAL_ERROR "ORXONOX_ADD_${_target_type} was given a non compliant argument: ${_arg}")
86      ENDIF(_storage_var)
87
88    ENDIF()
89
90  ENDFOREACH(_arg)
91ENDMACRO(PARSE_MACRO_ARGUMENTS)
Note: See TracBrowser for help on using the repository browser.