CMakePP / CMakePPLang

Object-oriented extension to the CMake language.
http://cmakepp.github.io/CMakePPLang/
Apache License 2.0
11 stars 4 forks source link

Multiple return values with 'cpp_return' #63

Closed zachcran closed 1 year ago

zachcran commented 1 year ago

Is your feature request related to a problem? Please describe. cpp_return() is a useful tool for returning a value from a function, wrapping the calls to set(return_variable "${return_value}" PARENT_SCOPE) and return() in one concise function. However, if a user wants to return more than one value from a function, you cannot use cpp_return() for each return value, since cpp_return() calls return() inside.

Describe the solution you'd like I propose that cpp_return() accept a list of return variables, and set each of them in the PARENT_SCOPE before calling return().

Describe alternatives you've considered The only alternative I can think of is to call the set(return_variable "${return_value}" PARENT_SCOPE) command for each return variable except the last one, for which cpp_return() can be used.

Additional context I think this would be a fairly simple extension going from:

macro(cpp_return _cr_rv)
    set("${_cr_rv}" "${${_cr_rv}}" PARENT_SCOPE)
    return()
endmacro()

to iterating over a variable list of arguments. Something like:

macro(cpp_return)
    foreach(_cr_rv ${ARGN})
        set("${_cr_rv}" "${${_cr_rv}}" PARENT_SCOPE)
    endforeach()
    return()
endmacro()
ryanmrichard commented 1 year ago

Done in #64