PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/share/cmake/ParseArguments.cmake

http://github.com/imageworks/OpenColorIO
CMake | 57 lines | 30 code | 2 blank | 25 comment | 0 complexity | f4c30ba38a1b7293c0490dab996ec2b6 MD5 | raw file
 1#-------------------------------------------------------------------------------
 2# The PARSE_ARGUMENTS macro will take the arguments of another macro and define
 3# several variables. The first argument to PARSE_ARGUMENTS is a prefix to put
 4# on all variables it creates. The second argument is a list of names, and the
 5# third argument is a list of options. Both of these lists should be quoted.
 6# The rest of the PARSE_ARGUMENTS args are arguments from another macro to be
 7# parsed.
 8#
 9#     PARSE_ARGUMENTS(prefix arg_names options arg1 arg2...)
10#
11# For each item in options, PARSE_ARGUMENTS will create a variable with that
12# name, prefixed with prefix_. So, for example, if prefix is MY_MACRO and
13# options is OPTION1;OPTION2, then PARSE_ARGUMENTS will create the variables
14# MY_MACRO_OPTION1 and MY_MACRO_OPTION2. These variables will be set to true if
15# the option exists in the command line or false otherwise.
16#
17# For each item in arg_names, PARSE_ARGUMENTS will create a variable with that
18# name, prefixed with prefix_. Each variable will be filled with the arguments
19# that occur after the given arg_name is encountered up to the next arg_name or
20# the end of the arguments. All options are removed from these lists.
21# PARSE_ARGUMENTS also creates a prefix_DEFAULT_ARGS variable containing the
22# list of all arguments up to the first arg_name encountered.
23#
24# Downloaded from: http://www.itk.org/Wiki/CMakeMacroParseArguments
25#
26
27cmake_minimum_required(VERSION 2.4.7)
28
29MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
30    SET(DEFAULT_ARGS)
31    FOREACH(arg_name ${arg_names})    
32        SET(${prefix}_${arg_name})
33    ENDFOREACH(arg_name)
34    FOREACH(option ${option_names})
35        SET(${prefix}_${option} FALSE)
36    ENDFOREACH(option)
37    SET(current_arg_name DEFAULT_ARGS)
38    SET(current_arg_list)
39    FOREACH(arg ${ARGN})            
40        SET(larg_names ${arg_names})    
41        LIST(FIND larg_names "${arg}" is_arg_name)                   
42        IF (is_arg_name GREATER -1)
43            SET(${prefix}_${current_arg_name} ${current_arg_list})
44            SET(current_arg_name ${arg})
45            SET(current_arg_list)
46        ELSE (is_arg_name GREATER -1)
47            SET(loption_names ${option_names})    
48            LIST(FIND loption_names "${arg}" is_option)
49            IF (is_option GREATER -1)
50                SET(${prefix}_${arg} TRUE)
51            ELSE (is_option GREATER -1)
52                SET(current_arg_list ${current_arg_list} ${arg})
53            ENDIF (is_option GREATER -1)
54        ENDIF (is_arg_name GREATER -1)
55    ENDFOREACH(arg)
56    SET(${prefix}_${current_arg_name} ${current_arg_list})
57ENDMACRO(PARSE_ARGUMENTS)