27

I've been having issues with changing the build directory via CLion. I've tried: set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin") but it does not seem to change and remains the same (/home/adil/.clion10/system/cmake/generated/c05c962b/c05c962b/Debug/Project).
I have also tried the workaround specified here, but that too does not seem to work.

Does anyone have a solution for this problem?

Habib
  • 219,104
  • 29
  • 407
  • 436
Adil
  • 572
  • 1
  • 6
  • 20
  • Also having this problem with build CL-138.2344.17 on Mac. – Spiro Michaylov Nov 11 '14 at 19:19
  • 1
    I have this problem too, but no solution below is acceptable. Changing CMakeLists.txt is a silly idea since this is a versioned file. Per-user configuration like the build directory should never go into the original sources and back upstream. – srking Apr 18 '15 at 21:28
  • @srking what about using CMake environmental variable set per-user when invoking cmake, for example: `cmake -DVARIABLE=value` – wiped Jul 08 '15 at 08:56
  • 2
    I might uninstall Clion, this problem is so annoying – Griffan Jul 09 '15 at 20:49
  • 2
    Pretty explained reply, check it out http://stackoverflow.com/a/28200869/1581505 – ilidar Jul 28 '15 at 11:20
  • @dktcup's link elaborates on... http://blog.jetbrains.com/clion/2014/09/clion-answers-frequently-asked-questions/ – cloudsurfin Oct 10 '15 at 22:32

4 Answers4

42

You need to prefix your bin with the path to the current directory your project resides in. You can use ${CMAKE_CURRENT_SOURCE_DIR}

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

Be sure to add this before related add_executable directive(s) in your CMakeLists.txt file.

CODE-REaD
  • 2,819
  • 3
  • 33
  • 60
wiped
  • 715
  • 6
  • 7
12

Go to Settings -> CMake and specify relative or absolute pass where you would like your build files to be stored in 'Build output path' field. For instance ./bin will output build files in YourProject/bin/Debug/yourExeFile.exe

enter image description here

Vlad Bezden
  • 83,883
  • 25
  • 248
  • 179
  • Dmitry Kozhevnikov from JetBrains said: *it's called "Settings | Build, Execution, Deployment | CMake | Build Directory" since 2020.2.* --- [Ability to specify the build/generation output directory : CPP-3374](https://youtrack.jetbrains.com/issue/CPP-3374/Ability-to-specify-the-buildgeneration-output-directory#focus=Comments-27-4590124.0-0) – li ki Jun 04 '22 at 05:24
4

The wiped's answer is correct, just I must be add that you have to put that set directive before the add_executable directive, and before the set directive where the source files are defined for the add_executable, if you don't do in this way, the output will be the same and no errors will launched.

Mariano Ruiz
  • 4,314
  • 2
  • 38
  • 34
2

You can use set_target_properties :

set_target_properties( YOUR_PROJECT PROPERTIES RUNTIME_OUTPUT_DIRECTORY "YOUR_BUILD_DIRECTORY")
LaurentTrk
  • 54
  • 3