Make add_custom_command smart enough to run executable targets on DLL platforms
To get a custom command to portably run my executable target, I had to resort to this:
add_custom_command(
OUTPUT ${test_main}
# If the executable target depends on DLLs their directories need to be injected into the PATH
# or they won't be found and the target will fail to run, so invoke it through cmake. Because
COMMAND
${CMAKE_COMMAND} -E env
"PATH=$<JOIN:$<TARGET_RUNTIME_DLL_DIRS:generate-xctest-main>;$ENV{PATH},;>"
--
$<TARGET_FILE:generate-xctest-main> -o ${test_main} ${sources}
DEPENDS ${sources} generate-xctest-main
COMMENT "Generate runner for test target ${test_target}")
This ought to be handled automatically by cmake.
This is related to #24129 and #25686 but I don't have permission to link issues.
Edited by Dave Abrahams