Feature request: Allow $<PATH:...> generator expressions to take lists of paths
I recently wrote the following function to extract the directories of DLLs from the $<TARGET_RUNTIME_DLLS:tgt>
generator expression:
function(get_target_runtime_paths tgt out_var)
set(GE_OPEN "$<1:$><")
set(GE_CLOSE "$<ANGLE-R>")
set(DLLS "$<TARGET_RUNTIME_DLLS:${tgt}>")
set(PP_GE_OPEN "${GE_OPEN}PATH:GET_PARENT_PATH$<COMMA>")
set(SEPARATOR "${GE_CLOSE};${PP_GE_OPEN}")
set(RAW_DIRS "${PP_GE_OPEN}$<JOIN:${DLLS},${SEPARATOR}>${GE_CLOSE}")
set(DEDUPLICATED_DIRS "${GE_OPEN}REMOVE_DUPLICATES:${RAW_DIRS}${GE_CLOSE}")
set(SHELL_DIRS "${GE_OPEN}SHELL_PATH:${DEDUPLICATED_DIRS}${GE_CLOSE}")
set(${out_var} "$<GENEX_EVAL:${SHELL_DIRS}>" PARENT_SCOPE)
endfunction()
My use case was to set the PATH
environment variable of tests on Windows where rpaths aren't a thing. The solution is really hackish and took ages - it "joins" the list of DLLs with a carefully crafted separator, itself containing a semicolon, such that a list of single-path $<PATH:GET_PARENT_PATH,path>
escaped generator expressions is obtained. This is wrapped in a couple more escaped generator expressions for neatness and then evaluated with $<GENEX_EVAL:...>
.
If $<PATH:GET_PARENT_PATH,path>
took lists of paths, this would be reduced to
function(get_target_runtime_paths tgt out_var)
set(RAW_DIRS "$<PATH:GET_PARENT_PATH,$<TARGET_RUNTIME_DLLS:${tgt}>>")
set(${out_var} "$<SHELL_PATH:$<REMOVE_DUPLICATES:${RAW_DIRS}>>" PARENT_SCOPE)
endfunction()
There might also be simpler ways of rewriting get_target_runtime_paths
without any additional changes to CMake, but I couldn't find any. Either way, I think the use case remains valid. Taking lists of paths seems particularly natural because $<SHELL_PATH:paths>
already does so. I think the path
argument of all genexes starting with $<PATH:
could be allowed to be lists, even if it's a bit contrived for a few of them. If these generator expressions delegate to cmake_path
, list support could be considered for it too.