Setting working directory to executable directory

Hi guys!

I am having a bit of a problem here with figuring out how to set my Kdevelop projects working directory to the directory of the executable that is being created.

I am using a CMakeLists.txt file

I will admit that I am newer at working with CMake. I have extensively searched online for help with this and have not had success. I am hoping someone here can point me in the right direction.

Thank you in advance!
If you want, you could change the working directory through C++ directly:

#include <filesystem>
int main()
    auto path = std::filesystem::current_path(); //getting path
    std::filesystem::current_path(path); //setting path
Last edited on
CMake allows you to "build" in directory somewhere else.

Typically, you build a cmake project as:
cd project-dir
mkdir build
cd build
cmake ..

That last line means, "create the make files used for the build here, from the source directory above".

By default, this is what kdevelop uses, a subdirectory called "build".

To change it:
* open the project in kdevelop
* choose "Configure CMake settings"
* in the right pane, select "Show Advanced"
* at the bottom of the new options, "Show advanced values"
* in the upper pane, scroll to <project-name>_BINARY_DIR

That shows the absolute path of the build directory, change that.
Thnx. Shortly after posting I found the solution.
Registered users can post here. Sign in or register to post.