Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/cmake/ParseMacroArguments.cmake @ 4065

Last change on this file since 4065 was 3196, checked in by rgrieder, 15 years ago

Merged pch branch back to trunk.

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[3116]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  # Parse all the arguments and set the corresponding variable
39  # If the option is just a switch, set the variable to its name for later use
40  FOREACH(_arg ${ARGN})
41    SET(_arg_found FALSE)
42
43    # Switches
44    FOREACH(_switch ${_switches})
45      IF(${_switch} STREQUAL ${_arg})
46        SET(_arg_${_switch} ${_switch})
47        SET(_arg_found TRUE)
48        # Avoid interpreting arguments after this one as options args for the previous one
49        SET(_storage_var)
50        BREAK()
51      ENDIF()
52    ENDFOREACH(_switch)
53
54    # Input options
55    IF(NOT _arg_found)
56      FOREACH(_list_name ${_list_names})
57        IF(${_list_name} STREQUAL ${_arg})
58          SET(_storage_var _arg_${_list_name})
59          SET(_arg_found TRUE)
60          BREAK()
61        ENDIF()
62      ENDFOREACH(_list_name)
63    ENDIF(NOT _arg_found)
64
65    # Arguments of an input option (like source files for SOURCE_FILES)
66    IF(NOT _arg_found)
67      IF(_storage_var)
68        # Store in variable define above in the foreach loop
69        SET(${_storage_var} ${${_storage_var}} ${_arg})
70      ELSE()
71        MESSAGE(FATAL_ERROR "ORXONOX_ADD_${_target_type} was given a non compliant argument: ${_arg}")
72      ENDIF(_storage_var)
73    ENDIF(NOT _arg_found)
74
75  ENDFOREACH(_arg)
76ENDMACRO(PARSE_MACRO_ARGUMENTS)
Note: See TracBrowser for help on using the repository browser.