[CMake] Setting Working Directory for Debugging in MS VC++ via CMake

Brad King brad.king at kitware.com
Wed Aug 2 17:06:39 EDT 2006


Steve Johns wrote:
> Recently, in an MS VC++ 7.1 (.NET 2003) build prepared using CMake, I've
> had a problem with the application finding a config file that it needs
> to read at startup.  Even though I placed the file in the app's startup
> dir (i.e. 'blahblah/Debug', when debugging ) the app was not finding the
> file.  This despite the fact that when the app was run outside the IDE
> (e.g. simply from a command window) it always found the file (in the
> startup dir) without a problem.
> 
> Ultimately it was found that manually setting the 'Working Directory'
> property (in the property pane) for the ALL_BUILD target to
> 'blahblah/Debug' would enable the config file to be found.
> 
> Note:  setting the 'Working Directory' property for the single project
> that creates the application executable DID NOT work.
> 
> So, now my question is:
> 
> What can I do in CMake, or in CMakeLists.txt files, to set that
> (debugging) 'Working Directory' property for the ALL_BUILD target
> automatically as part of the CMake build process?
> 
> Thanks kindly to anyone who can shed some light on this for me ...

This property is not actually stored in the project files, so CMake
cannot set the value.  It is stored in some file inside the %APPDATA%
directory for Visual Studio.

I don't think the current working directory should have to be set
properly for an application to find its config file.  You should be able
to compute the path relative to the executable location.  The exe
location can be obtained at runtime by inspecting argv[0] and
getenv("PATH").

-Brad



More information about the CMake mailing list