There are some cute native functions that let you specify arguments in
random order with named keys preceeding them, eg.
execute_process(COMMAND blah WORKING_DIRECTORY blah2 OUTPUT_FILE x TIMEOUT 2)
===
execute_process(COMMAND blah WORKING_DIRECTORY blah2 TIMEOUT 2 OUTPUT_FILE x)
I'm doing this like this at the moment, but it's clumsy:
function(args NAMED ARGS)
set(STATE 0)
foreach(ARG ${ARGS})
list(FIND NAMED ${ARG} HAS_NAMED_ITEM)
if(STATE)
set(${STATE} ${ARG} PARENT_SCOPE)
set(STATE 0)
else()
if(NOT HAS_NAMED_ITEM EQUAL -1)
set(STATE ${ARG})
endif()
endif()
endforeach()
endfunction()
function(blah)
set(NAMED_ARGS LD_CONF;C_FLAGS)
args("${NAMED_ARGS}" "${ARGV}")
message("C_FLAGS --> ${C_FLAGS}")
message("LD_CONF --> ${LD_CONF}")
endfunction()
It's particularly annoying when I need a required value (or multiple
ones), like:
function(blah2 REQUIRED)
list(REMOVE_AT ARGV 0)
set(NAMED_ARGS LD_CONF;C_FLAGS)
args("${NAMED_ARGS}" "${ARGV}")
message("REQUIRED --> ${REQUIRED}")
message("C_FLAGS --> ${C_FLAGS}")
message("LD_CONF --> ${LD_CONF}")
endfunction()
blah2("item_required" C_FLAGS "G" LD_CONF "blah")
Anyone suggest a better way?
~
Doug.
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake