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

**URL:** https://discourse.cmake.org/t/several-questions-regarding-environment-variables-path-and-windows-msvc/7780
**Category:** Usage
**Created:** [March 27, 2023, 10:09pm UTC](https://discourse.cmake.org/t/several-questions-regarding-environment-variables-path-and-windows-msvc/7780 "2023-03-27T22:09:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [March 27, 2023, 10:09pm UTC](https://discourse.cmake.org/t/several-questions-regarding-environment-variables-path-and-windows-msvc/7780/1 "2023-03-27T22:09:06Z")

</div>

Hi,

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  
Alex

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 3, 2023, 11:28am UTC](https://discourse.cmake.org/t/several-questions-regarding-environment-variables-path-and-windows-msvc/7780/2 "2023-04-03T11:28:38Z")

</div>

`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`](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-E_env-modify) exists to make this a lot easier.
