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 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.

 

11 comments

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 

configure_file(
"${PROJECT_SOURCE_DIR}/MyProjectConfig.h.in"
"${PROJECT_BINARY_DIR}/MyProjectConfig.h"
)

Similarly, flat files copied into the build directory using file(COPY...) are also not copied. 

file(COPY ./etc/post_run.rcf DESTINATION etc)

Is there anything I'm doing wrong, or would this be an enhacement to the Build Output Path feature for the IDE?

0

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. 

0

 

 

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?

Edited by Steve Wilson
0

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.

0

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.

0

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.

0

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.

0

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)

0

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.

0

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?

0

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!

0

Please sign in to leave a comment.

Have more questions?

Submit a request