[CMake] how to define current working directory of command line tool

J Decker d3ck0r at gmail.com
Mon Oct 11 16:35:43 EDT 2010


On Mon, Oct 11, 2010 at 2:20 AM, Jochen Wilhelmy <j.wilhelmy at arcor.de> wrote:
>
>>> Hi!
>>>
>>>>>>>
>>>>>>> Is it possible to define the current working directory of a command
>>>>>>> line
>>>>>>> tool
>>>>>>> that is built with cmake? since the build is usually out-of-source I
>>>>>>> have
>>>>>>> to set the current working directory in the ide, e.g visual studio or
>>>>>>> xcode. more convenient would be to set it in cmake.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> Do you mean in add_custom_command()/add_custom_target() ?
>>>>>> Both have an optional WORKING_DIRECTORY argument.
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> no, i mean add_executable. when I build and start the directory I'd
>>>>> like to set the
>>>>> working directory that the executable is started in.
>>>>>
>>>>> -Jochen
>>>>>
>>>>>
>>>>
>>>> I think that you have a misconception with respect to the concept of
>>>> "working directory".
>>>>
>>>> In a Unix-style environment, the "working directory" is determined by
>>>> the "shell" command line interpreter. The actual value is determined only at
>>>> execution-time. It is not something "built-in" to the executable.
>>>>
>>>>
>>>
>>> No, I mean this very unix-style working directory. Of course this is only
>>> a debug setting, i.e. it does not influence the
>>> build result. But if I write a command line tool, e.g. a copy, then I
>>> have some test files to copy and need some arguments
>>> for the copy tool to tell it which files to copy. Therefore it is
>>> possible to set the working directory and command line
>>> arguments in an ide (visual studio or xcode). For xcode there is even the
>>> effect that after cmake runs the current
>>> setting is lost which is not the case for visual studio since these
>>> settings are stored in a separate file.
>>>
>>> -Jochen
>>>
>>
>> Are you trying to run the executable with ADD_TEST? In that case the
>> working directory is always CMAKE_CURRENT_BINARY_DIR. If you need to change
>> it, create a wrapper script (you can do so using the CMake language in order
>> to not depend on any other interpreter).
>>
>
> no, just add_executable and then starting the target in debug mode inside
> the ide. but maybe add_test is the solution to my
> problem, i have to look at it. is this for starting an executable with some
> command line arguments?

That would be a handy feature... but the debugging properties of a
target are saved in .vcxproj.user so they tend to stick around after
setting them... even rebuilding the solution and projects with cmake
the debug settings remain so it's not a huge deal to just set it by
hand... would be nice to be able to specify those, but then again, I'm
glad it doesn't write the .user files so that changes I make there do
stay.

>
> -Jochen
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list