How to change a build directory in CLion? Is it possible to use in-source-tree build? Why does CLion generate several build types at once?
Update: Starting with CLion 2016.3 this has changed! Please, find detailed information in our webhelp by the following links:
Learn there how to configure several Toolchains, change CMake generation path, introduce in-source builds, set which configuration types to build (Debug, Release, etc.) and provide other information for the build process.
CLion v2016.2 and earlier:
To change build output path, go to Build, Execution, Deployment | CMake settings and set it there. Alternatively, you can configure the RUNTIME_OUTPUT_DIRECTORY property in your CMakeLists.txt file.
Please note that CLion currently supports only out-of-source build and does a lot in the background that makes in-source-tree and CMake execution directory configurations impossible. Moreover, files under ~/.clion/system/cmake/generated are not intended to be used directly, as they are managed and updated by the IDE.
In case of a low amount of disk space for your user directory, you should probably move the whole ~/clion/system folder to another partition. Read here how to do it.
To guarantee the correct language model, CLion needs to generate the project for several build types (e.g. Debug, Release), and keep them synchronized and up to date. These generated files are stored in the private folder, and actually it's 'implementation details.' In this scheme there are not one but several CMAKE_BINARY_DIR folders, for each build type.
You can, however, benefit from it by changing the configuration type (Debug -> Release, or other ways) and getting the correct code resolve in editor, in compliance with the configuration type. How to change the configuration type.
Currently we do consider adding ability to specify the generation output directory under this feature request. Please, share your use case in the linked ticket.
Please sign in to leave a comment.
Hi Team! The out of source builds are great! I currently use the Build Output Path setting to put all the build artifacts together into a single folder which is a bit more accessible -- in case i need to run these executables from the CMD prompt in Windows. The problem i'm encountering though is that not all the files are actually being routed to this alternative output path. For example, the configured headers
Similarly, flat files copied into the build directory using file(COPY...) are also not copied.
Is there anything I'm doing wrong, or would this be an enhacement to the Build Output Path feature for the IDE?
When you set Build Output Path in CLion, it actually configures the CMAKE_RUNTIME_OUTPUT_DIRECTORY. So this is just the setting that is passed to CMake. So you can just use the CMAKE_RUNTIME_OUTPUT_DIRECTORY variable for the DESTINATION in your CMake files to do the job.
So...I was expecting that when I set the "Build Output Path", this would allow me to control the "--build" parameter passed to cmake. It doesn't. I'd like to control where my builds go. Is that possible?
Build Output Path in CLion is exactly the CMAKE_RUNTIME_OUTPUT_DIRECTORY variable of CMake. So it's the directory where the final artefacts are copied.
That's understood from your earlier comments. Once again, we're looking for control over where the build actually takes place (i.e. where object files are generated), not where build output products like libraries and executables are copied to. Every IDE I've ever used has allowed me to control where the build takes place, including the very awesome intellij. I would also suggest that "Build Output Path" is a misleading name given that the build output doesn't actually go there.
I will look around the support site for a "feature enhancement request" since this doesn't seem to be the right venue.
Steve, it's currently not possible to change the directory where the actual build takes place (https://youtrack.jetbrains.com/issue/CPP-3374), since it's the directory CLion uses internally.
We hope to fix it in 2016.3 version.
I'm confused. I'm using 2017.1.1, and it seems that in this and other recent releases I can no longer set an output path for binaries and libraries, and yet setting CMAKE_{RUNTIME,LIBRARY,ARCHIVE}_OUTPUT_DIRECTORY in my CMakeLists.txt still has no effect. This leaves me with no way to set an output location for build artifacts, meaning I simply cannot use CLion to perform builds. This seems like an extraordinary oversight - could you provide some advice please? Thanks.
Simon, sorry for the outdated information. CLion now supports in-source builds and other options. Generation path can be configured under File | Settings | Build, Execution, Deployment | CMake (https://www.jetbrains.com/help/clion/2017.1/cmake-settings.html)
Thanks for replying. However, this is for setting cmake generated files, not for setting cmake output directories, which still cannot be set. These are different things, but looking back on your documentation, FAQs and issue tracker I cannot help but notice a history of confusion between these two things on the part of jetbrains. I must be absolutely clear in distinguishing the two:
1. CMake generated files - files create by cmake when running a build, such as copies of sources files, object files, cmake cache files, etc.
2. Project artifacts - files created by the project, such as executables, libraries, archives.
The setting you refer to allows me to set the location of 1). I wish to set the location of 2) which is normally achieved by setting the cmake variables CMAKE_{RUNTIME,LIBRARY,ARCHIVE}_OUTPUT_DIRECTORY. CLion does something which means the value of these variables, when I build from within CLion, is always empty, whatever value I set within my CMakeLists.txt. There is no setting within CLion which corresponds to these variables. There used to be - the "Build Output Path" setting in versions pre-2016.3. But this setting was removed in 2016.3. The problem is that the behaviour of overriding my own value of these variables was NOT removed, meaning I now have no way of controlling them - and therefore my build is completely broken.
Simon,
we have removed the 'Build output path' settings in 2016.3; though, you still should be able to use CMAKE_{RUNTIME,LIBRARY,ARCHIVE}_OUTPUT_DIRECTORY to specify output directories for CMake.
CLion doesn't do anything to override these settings, but they might be already overridden in your CMakeCache.txt file. You can update the cached values using set( CACHE FORCE ) command.
Does it help?
Hello Anton, thanks for your reply. Happily, I have resolved the issue, which is not related to CLion. Oddly, in my CMakeLists.txt, I was setting the variables like this:
set(${CMAKE_RUNTIME_LIBRARY_OUTPUT_DIRECTORY} ${BIN})
Now, left hand operand should not have been ${}-wrapped - but for some reason this worked when ran this in CMake in a shell! I am using CMake 3.6 outside of CLion, perhaps this makes a difference? When I remove the ${}, everything works as expected.
Thank you for your time. I spotted this when I read the stack overflow example you linked me to!
Hi, the two links for CLion 2016.3+ at the top seem to be broken ("Changing configuration types" and "Changing CMake settings").
Thanks Elmar, we've updated the content
CLion does support out-of-source build, and this is very nice. Unfortunately, I faced a problem with that: my project is also built by a different toolchain, in docker. And this docker setup uses (or, to be precise, has been using until I found this problem), in-source build with CMake. So, the project root directory was 'poisoned' with CMakeCache.txt, Makefile, and cmake_install.cmake files.
This project would complain when opened with CLion, saying "cannot generate into /project/root it is already used for project …"
As soon as I removed the three files from the project/root directory, CLion was happy to build its versions of these files inside cmake-build-debug or wherever I chose to.
I consider this a bug: why would some files in the project/root directory prevent creating different ones in an entirely different location?
I have a similar issue which is affecting CMakePresets.json. I was able to use the CMake profiles page to set the build directory to a subdirectory in my root project called “build”. When I do that and run CMake configuration (with options --preset=Debug --log-context), everything works as expected and the CMake build files get generated inside the build folder. However, when i trigger the build command off the build menu, it errors out saying that the CMakePresets.json cannot be found. After some tinkering, I realized that the CLion executes cmake --build --preset=Debug from within the “build” folder I specified, NOT the ROOT project directory as it should be doing!!! I am able to work around this issue by NOT setting the “build” folder for cmake output files, but then those generated files get dumped into my root project folder, which is not ideal. Is there anyway to specify the “build” folder and still have CLIon execute cmake --build from project root? What am I missing here? (I am using the latest version of Clion (2024.*)