[RTL] actctx.c: Use an alternative implicit activation context when an application...
[reactos.git] / sdk / cmake / CMakeParseArguments.cmake
1 # CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
2 #
3 # CMAKE_PARSE_ARGUMENTS() is intended to be used in macros or functions for
4 # parsing the arguments given to that macro or function.
5 # It processes the arguments and defines a set of variables which hold the
6 # values of the respective options.
7 #
8 # The <options> argument contains all options for the respective macro,
9 # i.e. keywords which can be used when calling the macro without any value
10 # following, like e.g. the OPTIONAL keyword of the install() command.
11 #
12 # The <one_value_keywords> argument contains all keywords for this macro
13 # which are followed by one value, like e.g. DESTINATION keyword of the
14 # install() command.
15 #
16 # The <multi_value_keywords> argument contains all keywords for this macro
17 # which can be followed by more than one value, like e.g. the TARGETS or
18 # FILES keywords of the install() command.
19 #
20 # When done, CMAKE_PARSE_ARGUMENTS() will have defined for each of the
21 # keywords listed in <options>, <one_value_keywords> and
22 # <multi_value_keywords> a variable composed of the given <prefix>
23 # followed by "_" and the name of the respective keyword.
24 # These variables will then hold the respective value from the argument list.
25 # For the <options> keywords this will be TRUE or FALSE.
26 #
27 # All remaining arguments are collected in a variable
28 # <prefix>_UNPARSED_ARGUMENTS, this can be checked afterwards to see whether
29 # your macro was called with unrecognized parameters.
30 #
31 # As an example here a my_install() macro, which takes similar arguments as the
32 # real install() command:
33 #
34 # function(MY_INSTALL)
35 # set(options OPTIONAL FAST)
36 # set(oneValueArgs DESTINATION RENAME)
37 # set(multiValueArgs TARGETS CONFIGURATIONS)
38 # cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
39 # ...
40 #
41 # Assume my_install() has been called like this:
42 # my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub)
43 #
44 # After the cmake_parse_arguments() call the macro will have set the following
45 # variables:
46 # MY_INSTALL_OPTIONAL = TRUE
47 # MY_INSTALL_FAST = FALSE (this option was not used when calling my_install()
48 # MY_INSTALL_DESTINATION = "bin"
49 # MY_INSTALL_RENAME = "" (was not used)
50 # MY_INSTALL_TARGETS = "foo;bar"
51 # MY_INSTALL_CONFIGURATIONS = "" (was not used)
52 # MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (no value expected after "OPTIONAL"
53 #
54 # You can the continue and process these variables.
55 #
56 # Keywords terminate lists of values, e.g. if directly after a one_value_keyword
57 # another recognized keyword follows, this is interpreted as the beginning of
58 # the new option.
59 # E.g. my_install(TARGETS foo DESTINATION OPTIONAL) would result in
60 # MY_INSTALL_DESTINATION set to "OPTIONAL", but MY_INSTALL_DESTINATION would
61 # be empty and MY_INSTALL_OPTIONAL would be set to TRUE therefor.
62
63 #=============================================================================
64 # Copyright 2010 Alexander Neundorf <neundorf@kde.org>
65 #
66 # Redistribution and use in source and binary forms, with or without
67 # modification, are permitted provided that the following conditions
68 # are met:
69 #
70 # * Redistributions of source code must retain the above copyright
71 # notice, this list of conditions and the following disclaimer.
72 #
73 # * Redistributions in binary form must reproduce the above copyright
74 # notice, this list of conditions and the following disclaimer in the
75 # documentation and/or other materials provided with the distribution.
76 #
77 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
78 # nor the names of their contributors may be used to endorse or promote
79 # products derived from this software without specific prior written
80 # permission.
81 #
82 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
83 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
84 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
85 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
86 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
87 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
88 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
89 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
90 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
91 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
92 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93 #=============================================================================
94
95
96 if(__CMAKE_PARSE_ARGUMENTS_INCLUDED)
97 return()
98 endif()
99 set(__CMAKE_PARSE_ARGUMENTS_INCLUDED TRUE)
100
101
102 function(CMAKE_PARSE_ARGUMENTS prefix _optionNames _singleArgNames _multiArgNames)
103 # first set all result variables to empty/FALSE
104 foreach(arg_name ${_singleArgNames} ${_multiArgNames})
105 set(${prefix}_${arg_name})
106 endforeach(arg_name)
107
108 foreach(option ${_optionNames})
109 set(${prefix}_${option} FALSE)
110 endforeach(option)
111
112 set(${prefix}_UNPARSED_ARGUMENTS)
113
114 set(insideValues FALSE)
115 set(currentArgName)
116
117 # now iterate over all arguments and fill the result variables
118 foreach(currentArg ${ARGN})
119 list(FIND _optionNames "${currentArg}" optionIndex) # ... then this marks the end of the arguments belonging to this keyword
120 list(FIND _singleArgNames "${currentArg}" singleArgIndex) # ... then this marks the end of the arguments belonging to this keyword
121 list(FIND _multiArgNames "${currentArg}" multiArgIndex) # ... then this marks the end of the arguments belonging to this keyword
122
123 if(${optionIndex} EQUAL -1 AND ${singleArgIndex} EQUAL -1 AND ${multiArgIndex} EQUAL -1)
124 if(insideValues)
125 if("${insideValues}" STREQUAL "SINGLE")
126 set(${prefix}_${currentArgName} ${currentArg})
127 set(insideValues FALSE)
128 elseif("${insideValues}" STREQUAL "MULTI")
129 list(APPEND ${prefix}_${currentArgName} ${currentArg})
130 endif()
131 else(insideValues)
132 list(APPEND ${prefix}_UNPARSED_ARGUMENTS ${currentArg})
133 endif(insideValues)
134 else()
135 if(NOT ${optionIndex} EQUAL -1)
136 set(${prefix}_${currentArg} TRUE)
137 set(insideValues FALSE)
138 elseif(NOT ${singleArgIndex} EQUAL -1)
139 set(currentArgName ${currentArg})
140 set(${prefix}_${currentArgName})
141 set(insideValues "SINGLE")
142 elseif(NOT ${multiArgIndex} EQUAL -1)
143 set(currentArgName ${currentArg})
144 set(${prefix}_${currentArgName})
145 set(insideValues "MULTI")
146 endif()
147 endif()
148
149 endforeach(currentArg)
150
151 # propagate the result variables to the caller:
152 foreach(arg_name ${_singleArgNames} ${_multiArgNames} ${_optionNames})
153 set(${prefix}_${arg_name} ${${prefix}_${arg_name}} PARENT_SCOPE)
154 endforeach(arg_name)
155 set(${prefix}_UNPARSED_ARGUMENTS ${${prefix}_UNPARSED_ARGUMENTS} PARENT_SCOPE)
156
157 endfunction(CMAKE_PARSE_ARGUMENTS _options _singleArgs _multiArgs)