Blame cmake/compat_2.8.3/CMakeParseArguments.cmake

Packit 1fb8d4
# CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
Packit 1fb8d4
#
Packit 1fb8d4
# CMAKE_PARSE_ARGUMENTS() is intended to be used in macros or functions for
Packit 1fb8d4
# parsing the arguments given to that macro or function.
Packit 1fb8d4
# It processes the arguments and defines a set of variables which hold the
Packit 1fb8d4
# values of the respective options.
Packit 1fb8d4
#
Packit 1fb8d4
# The <options> argument contains all options for the respective macro,
Packit 1fb8d4
# i.e. keywords which can be used when calling the macro without any value
Packit 1fb8d4
# following, like e.g. the OPTIONAL keyword of the install() command.
Packit 1fb8d4
#
Packit 1fb8d4
# The <one_value_keywords> argument contains all keywords for this macro
Packit 1fb8d4
# which are followed by one value, like e.g. DESTINATION keyword of the
Packit 1fb8d4
# install() command.
Packit 1fb8d4
#
Packit 1fb8d4
# The <multi_value_keywords> argument contains all keywords for this macro
Packit 1fb8d4
# which can be followed by more than one value, like e.g. the TARGETS or
Packit 1fb8d4
# FILES keywords of the install() command.
Packit 1fb8d4
#
Packit 1fb8d4
# When done, CMAKE_PARSE_ARGUMENTS() will have defined for each of the
Packit 1fb8d4
# keywords listed in <options>, <one_value_keywords> and
Packit 1fb8d4
# <multi_value_keywords> a variable composed of the given <prefix>
Packit 1fb8d4
# followed by "_" and the name of the respective keyword.
Packit 1fb8d4
# These variables will then hold the respective value from the argument list.
Packit 1fb8d4
# For the <options> keywords this will be TRUE or FALSE.
Packit 1fb8d4
#
Packit 1fb8d4
# All remaining arguments are collected in a variable
Packit 1fb8d4
# <prefix>_UNPARSED_ARGUMENTS, this can be checked afterwards to see whether
Packit 1fb8d4
# your macro was called with unrecognized parameters.
Packit 1fb8d4
#
Packit 1fb8d4
# As an example here a my_install() macro, which takes similar arguments as the
Packit 1fb8d4
# real install() command:
Packit 1fb8d4
#
Packit 1fb8d4
#   function(MY_INSTALL)
Packit 1fb8d4
#     set(options OPTIONAL FAST)
Packit 1fb8d4
#     set(oneValueArgs DESTINATION RENAME)
Packit 1fb8d4
#     set(multiValueArgs TARGETS CONFIGURATIONS)
Packit 1fb8d4
#     cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
Packit 1fb8d4
#     ...
Packit 1fb8d4
#
Packit 1fb8d4
# Assume my_install() has been called like this:
Packit 1fb8d4
#   my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub)
Packit 1fb8d4
#
Packit 1fb8d4
# After the cmake_parse_arguments() call the macro will have set the following
Packit 1fb8d4
# variables:
Packit 1fb8d4
#   MY_INSTALL_OPTIONAL = TRUE
Packit 1fb8d4
#   MY_INSTALL_FAST = FALSE (this option was not used when calling my_install()
Packit 1fb8d4
#   MY_INSTALL_DESTINATION = "bin"
Packit 1fb8d4
#   MY_INSTALL_RENAME = "" (was not used)
Packit 1fb8d4
#   MY_INSTALL_TARGETS = "foo;bar"
Packit 1fb8d4
#   MY_INSTALL_CONFIGURATIONS = "" (was not used)
Packit 1fb8d4
#   MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (no value expected after "OPTIONAL"
Packit 1fb8d4
#
Packit 1fb8d4
# You can the continue and process these variables.
Packit 1fb8d4
#
Packit 1fb8d4
# Keywords terminate lists of values, e.g. if directly after a one_value_keyword
Packit 1fb8d4
# another recognized keyword follows, this is interpreted as the beginning of
Packit 1fb8d4
# the new option.
Packit 1fb8d4
# E.g. my_install(TARGETS foo DESTINATION OPTIONAL) would result in
Packit 1fb8d4
# MY_INSTALL_DESTINATION set to "OPTIONAL", but MY_INSTALL_DESTINATION would
Packit 1fb8d4
# be empty and MY_INSTALL_OPTIONAL would be set to TRUE therefor.
Packit 1fb8d4
Packit 1fb8d4
#=============================================================================
Packit 1fb8d4
# Copyright 2010 Alexander Neundorf <neundorf@kde.org>
Packit 1fb8d4
#
Packit 1fb8d4
# Distributed under the OSI-approved BSD License (the "License");
Packit 1fb8d4
# see accompanying file Copyright.txt for details.
Packit 1fb8d4
#
Packit 1fb8d4
# This software is distributed WITHOUT ANY WARRANTY; without even the
Packit 1fb8d4
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit 1fb8d4
# See the License for more information.
Packit 1fb8d4
#=============================================================================
Packit 1fb8d4
# (To distribute this file outside of CMake, substitute the full
Packit 1fb8d4
#  License text for the above reference.)
Packit 1fb8d4
Packit 1fb8d4
Packit 1fb8d4
if(__CMAKE_PARSE_ARGUMENTS_INCLUDED)
Packit 1fb8d4
  return()
Packit 1fb8d4
endif()
Packit 1fb8d4
set(__CMAKE_PARSE_ARGUMENTS_INCLUDED TRUE)
Packit 1fb8d4
Packit 1fb8d4
Packit 1fb8d4
function(CMAKE_PARSE_ARGUMENTS prefix _optionNames _singleArgNames _multiArgNames)
Packit 1fb8d4
  # first set all result variables to empty/FALSE
Packit 1fb8d4
  foreach(arg_name ${_singleArgNames} ${_multiArgNames})
Packit 1fb8d4
    set(${prefix}_${arg_name})
Packit 1fb8d4
  endforeach(arg_name)
Packit 1fb8d4
Packit 1fb8d4
  foreach(option ${_optionNames})
Packit 1fb8d4
    set(${prefix}_${option} FALSE)
Packit 1fb8d4
  endforeach(option)
Packit 1fb8d4
Packit 1fb8d4
  set(${prefix}_UNPARSED_ARGUMENTS)
Packit 1fb8d4
Packit 1fb8d4
  set(insideValues FALSE)
Packit 1fb8d4
  set(currentArgName)
Packit 1fb8d4
Packit 1fb8d4
  # now iterate over all arguments and fill the result variables
Packit 1fb8d4
  foreach(currentArg ${ARGN})
Packit 1fb8d4
    list(FIND _optionNames "${currentArg}" optionIndex)  # ... then this marks the end of the arguments belonging to this keyword
Packit 1fb8d4
    list(FIND _singleArgNames "${currentArg}" singleArgIndex)  # ... then this marks the end of the arguments belonging to this keyword
Packit 1fb8d4
    list(FIND _multiArgNames "${currentArg}" multiArgIndex)  # ... then this marks the end of the arguments belonging to this keyword
Packit 1fb8d4
Packit 1fb8d4
    if(${optionIndex} EQUAL -1  AND  ${singleArgIndex} EQUAL -1  AND  ${multiArgIndex} EQUAL -1)
Packit 1fb8d4
      if(insideValues)
Packit 1fb8d4
        if("${insideValues}" STREQUAL "SINGLE")
Packit 1fb8d4
          set(${prefix}_${currentArgName} ${currentArg})
Packit 1fb8d4
          set(insideValues FALSE)
Packit 1fb8d4
        elseif("${insideValues}" STREQUAL "MULTI")
Packit 1fb8d4
          list(APPEND ${prefix}_${currentArgName} ${currentArg})
Packit 1fb8d4
        endif()
Packit 1fb8d4
      else(insideValues)
Packit 1fb8d4
        list(APPEND ${prefix}_UNPARSED_ARGUMENTS ${currentArg})
Packit 1fb8d4
      endif(insideValues)
Packit 1fb8d4
    else()
Packit 1fb8d4
      if(NOT ${optionIndex} EQUAL -1)
Packit 1fb8d4
        set(${prefix}_${currentArg} TRUE)
Packit 1fb8d4
        set(insideValues FALSE)
Packit 1fb8d4
      elseif(NOT ${singleArgIndex} EQUAL -1)
Packit 1fb8d4
        set(currentArgName ${currentArg})
Packit 1fb8d4
        set(${prefix}_${currentArgName})
Packit 1fb8d4
        set(insideValues "SINGLE")
Packit 1fb8d4
      elseif(NOT ${multiArgIndex} EQUAL -1)
Packit 1fb8d4
        set(currentArgName ${currentArg})
Packit 1fb8d4
        set(${prefix}_${currentArgName})
Packit 1fb8d4
        set(insideValues "MULTI")
Packit 1fb8d4
      endif()
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
  endforeach(currentArg)
Packit 1fb8d4
Packit 1fb8d4
  # propagate the result variables to the caller:
Packit 1fb8d4
  foreach(arg_name ${_singleArgNames} ${_multiArgNames} ${_optionNames})
Packit 1fb8d4
    set(${prefix}_${arg_name}  ${${prefix}_${arg_name}} PARENT_SCOPE)
Packit 1fb8d4
  endforeach(arg_name)
Packit 1fb8d4
  set(${prefix}_UNPARSED_ARGUMENTS ${${prefix}_UNPARSED_ARGUMENTS} PARENT_SCOPE)
Packit 1fb8d4
Packit 1fb8d4
endfunction(CMAKE_PARSE_ARGUMENTS _options _singleArgs _multiArgs)