Ok, I deleted my original answer because it is better than @Florian suggested. Multiple quoted arguments require one additional setup. Consider a list of environment variables as such:
set(my_env_vars LDFLAGS="-Ldir1 -Ldir2" CFLAGS="-Idira -Idirb")
To get the desired extension, convert to a string and then replace ; a space.
set(my_env_string "${my_env_vars}") #produces LDFLAGS="...";CFLAGS="..." string(REPLACE ";" " " my_env_string "${my_env_string}")
Then you can continue @Florian's brilliant answer and add a trigger rule. If you need a semicolon in your line, you first need to convert them to something else first.
Please note that in this case I do not need to run using env :
set_target_properties(mytarget PROPERTIES RULE_LAUNCH_CUSTOM "${my_env_string}")
This, of course, depends on your shell.
On the other hand, my initial answer is lower, since I also have a case where I do not have access to the target name.
set(my_env LDFLAGS=\"-Ldir -Ldir2" CFLAGS=\"-Idira -Idirb\") add_custom_command(COMMAND sh -c "${my_env} grep LDFLAGS" VERBATIM)
This method still requires replacing the semicolons from the list-> string conversion.
source share