[CMake] how to define current working directory of command line tool
Jochen Wilhelmy
j.wilhelmy at arcor.de
Mon Oct 11 05:20:35 EDT 2010
>> 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?
-Jochen
More information about the CMake
mailing list