Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource2/cmake/ParseMacroArguments.cmake @ 5832

Last change on this file since 5832 was 5610, checked in by rgrieder, 15 years ago

Improved CMake performance for runs after the first one.
There are some optimisations in the macro argument parser and I manually added the header files for util and network (since they don't change too much and it still compiles with a missing header files).

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