Several questions regarding environment variables (PATH) and Windows/MSVC


since Windows doesn’t have RPATH, I’m having a bit of trouble getting PATH set up properly in a Visual Studio build.

I managed to set up the PATH properly in the VS_DEBUGGER_ENVIRONMENT target property.
First question: is there a special reason that there is no CMAKE_VS_DEBUGGER_ENVIRONMENT cmake variable, which would be used to initialize the VS_DEBUGGER_ENVIRONMENT target properties ?

Second question: what is the syntax to set multiple environment variables in the VS_DEBUGGER_ENVIRONMENT target property ?

Then I have an add_custom_command(), and I wanted to use
add_custom_command(… COMMAND ${CMAKE_COMMAND} -E env PATH=c:/some/dir;c:/some/other/dir;%PATH% $<TARGET_FILE:mytool> … ) to extend the existing PATH so that the executable will find its dlls.
I didn’t get it to work.
Should I put “%PATH%” in the add_custom_command() or $ENV{PATH} ?
Instead of “-E env PATH=C:/some/dir;c:/some/other/dir/”, it ended up as a whitespace separated list (“-E env PATH=C:/some/dir c:/some/other/dir …”), which cmake -E env couldn’t really make sense of.

I know I could create a bat-file which sets PATH and then starts the executable, but I’d like to get away without bat files if possible, especially since it seems cmake has all the necessary features.

Thanks for any pointers

cmd is what expands the %path% syntax. Using $ENV{PATH} would embed the configure-time PATH setting at build time. The semicolons also probably don’t help. If you’re able to require CMake 3.25+, cmake -E env --modify exists to make this a lot easier.