[CMake] Arbitrary order named arguments
Doug
douglas.linder at gmail.com
Thu Jul 19 23:42:25 EDT 2012
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.
More information about the CMake
mailing list