Blame cmake/compat_2.8.3/CMakeParseArguments.cmake

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