MantisBT - CMake
View Issue Details
0008884CMakeModulespublic2009-04-14 05:502016-06-10 14:30
jneuhaus 
Bill Hoffman 
normalfeatureN/A
closedmoved 
Visual Studio 2008
CMake-2-6 
 
0008884: Set Visual Studio project "custom environment variables" setting with CMake
Feature Request

In Visual Studio, you can add custom environment variables that will
exist if you run your application from visual studio. They are at
[executable project]-->Properties-->Configuration
Properties-->Debugging-->Environment

Setting these is especially useful to add the correct (Debug/Release) include paths to your project.

Example:
My project needs to have a debug version of ITKCommon.dll in its PATH
when running in Debug mode and a Release version of the DLL in Release
mode respectively. Otherwise it will crash with a

Manually setting the project environment setting to
"PATH=%ITK_DIR%\bin\$(OutType);%PATH%" allows me to automatically use
the correct path, as is suggested in the VTK FAQ
(<http://vtkedge.org/Wiki/VTK_FAQ#Shared_builds_of_VTK_and_debugging_QVT [^]
KWidget_using_Visual_Studio>). But the next CMake run will overwrite this setting. Therefore, a posibility to set this with CMake would be really useful. Other use cases exist too. For example, it can be used to set other environment variables as well, that could be read by the application.
No tags attached.
Issue History
2009-04-14 05:50jneuhausNew Issue
2009-09-14 14:06Bill HoffmanStatusnew => assigned
2009-09-14 14:06Bill HoffmanAssigned To => Bill Hoffman
2009-09-14 14:07Bill HoffmanNote Added: 0017457
2009-09-29 06:21Mateusz LoskotNote Added: 0017814
2009-09-29 06:24Mateusz LoskotNote Added: 0017815
2009-10-08 08:35jneuhausNote Added: 0018025
2009-10-08 14:40Mateusz LoskotNote Added: 0018040
2009-10-09 15:19Patrick MoseleyNote Added: 0018053
2009-10-12 04:23jneuhausNote Added: 0018057
2012-02-01 23:15Andrew HillNote Added: 0028444
2012-02-01 23:16Andrew HillNote Edited: 0028444bug_revision_view_page.php?rev_id=524
2012-02-01 23:19Andrew HillNote Deleted: 0028444
2012-02-01 23:22Andrew HillNote Added: 0028445
2016-06-10 14:27Kitware RobotNote Added: 0041542
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0017457)
Bill Hoffman   
2009-09-14 14:07   
I am not sure if this is possible. I think those env vars are stored globally maybe in some registry entry, not sure, but I don't think they are in the project files.
(0017814)
Mateusz Loskot   
2009-09-29 06:21   
Bill,

I believe it is possible and it should be fairly straightforward.
This setting is stored in user-specific configuration file: PROJECT.vcproj.DOMAINNAME.USER.user
(I'm not sure but this form should work as well: PROJECT.vcproj.user)

Here is explantion of .user file template for CMake:

http://stackoverflow.com/questions/1005901/how-to-set-path-environment-variable-using-cmake-and-visual-studio-to-run-test [^]
(0017815)
Mateusz Loskot   
2009-09-29 06:24   
There is related bug report in CMake database:

http://www.itk.org/Bug/view.php?id=7885 [^]
(0018025)
jneuhaus   
2009-10-08 08:35   
It is definitely possible to store custom environment variables per project in the project files.
They are stored in a file with the following naming scheme at the same folder as the .vcproj file: [project name].vcproj.[user domain].[user name].user

To set them with the VS GUI:
[executable project]-->Properties-->Configuration
Properties-->Debugging-->Environment

They will become active when the project is executed.
(0018040)
Mateusz Loskot   
2009-10-08 14:40   
@jneuhaus I know well that it's possible to configure environment for Visual Studio projects using GUI of the IDE. What I'm interested in is exactly what is requested in this feature request: Set Visual Studio project "custom environment variables" setting with CMake.
(0018053)
Patrick Moseley   
2009-10-09 15:19   
We have the case of using CMake in a cross platform environment and would like to have this functionality not only for Visual Studio, but for Eclipse and XCode as well.

Rather than coming up with something for each of the different generators for the different platforms, it would be nice to have a CMake command that would allow you to set locations of additional "shared libraries" needed to execute the application built with CMake inside the various IDEs supported as generator targets. So on Windows (Visual Studio) it would add the directories to the PATH environment variable, on Unix (Eclipse) it would set the LD_LIBRARY_PATH, and on Mac (XCode) it would set the DYLD_LIBRARY_PATH environment variable.
(0018057)
jneuhaus   
2009-10-12 04:23   
Our project needs the correct Debug/Release version of multiple DLLs.
VS allows to use the keyword '$(OutType)' in the custom PATH setting. It will be replaced by Debug/Release when the executable is started by Visual Studio. Therefore, we can simply switch between Debug/Release configuration in Visual Studio and it will find the correct DLLs.

Another use case is that we want to set certain environment variables with different values for different executable projects in the same solution.

It would be nice, if CMake would allow to set the custom environment variables, so that we do not have to re-set them after cmake re-generates the project.
(0028445)
Andrew Hill   
2012-02-01 23:22   
Relates to (or duplicates) 2582 if following Patrick Moseley's suggestion

http://cmake.org/Bug/view.php?id=2582 [^]
(0041542)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.