Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CMake offer a method to set the working directory for a given build system to use when running/debugging the project?

I have a project with the following structure:

project_name/CMakeLists.txt project_name/src project_name/resources ... project_name-build/configuration_name/project_name.exe 

I want my application to be run in the root project directory project_name so it can directly access resources.

Does CMake provide a method to specify this property, or will I have to manually set it in each build environment I use?

I've looked around in the documentation and haven't found anything other than the possibility of setting up a post-build event to run my project from the desired directory which is less than desirable. I also found that the working directory setting for Visual Studio is saved in a per-user file (.vcxproj.user) which I don't believe CMake generates (which points to the answer being probably no).

like image 390
Peter Clark Avatar asked May 30 '14 09:05

Peter Clark


People also ask

What exactly does CMake do?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.

What is working directory in Visual Studio?

Working Directory is the location which Specifies the working directory of the program being debugged. It is the default place in which a program is looking up it's files. Normally the working directory is the directory the application is launched from \bin\debug by default.

What does project do in CMake?

A project logically groups a number of targets (that is, libraries, executables and custom build steps) into a self-contained collection that can be built on its own. In practice that means, if you have a project command in a CMakeLists.


2 Answers

Since CMake 3.8, there is the VS_DEBUGGER_WORKING_DIRECTORY target property, which allows you to set the debugger working directory for a target in Visual Studio.

Usage example:

set_property(TARGET MyTarget PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") 
like image 179
tambre Avatar answered Sep 23 '22 03:09

tambre


As drescherjm pointed out (in his comment on the question) CMake doesn't provide a method to directly set a working directory. However, CMake does provide indirect methods of doing so.

The path I think I'll take is to use the configure_file command to fill in a template .user file.

like image 44
Peter Clark Avatar answered Sep 24 '22 03:09

Peter Clark