1
votes

My question is the following: Is there a way to tell CMakeFiles where to generate it's makefiles, such as cmake_install.cmake, CMakeCache.txt etc.?

More specifically, is there a way to set some commands in the CMakeFiles that specifies where to output these generated files? I have tried to search around the web to find some answers, and most people say there's no explicit way of doing this, while others say I might be able to, using custom commands. Sadly, I'm not very strong in cmake, so I couldn't figure this out.

I'm currently using the CLion IDE and there you can specifically set the output path through the settings, but for flexibility reasons I would like as much as possible to be done through the CMakeFiles such that compiling from different computers isn't that big of a hassle.

I would also like to avoid explicitly adding additional command line arguments etc.

I hope someone might have an answer for me, thanks in advance!

1
Thank you for the answer. However, as implicited above I would like to avoid this. I would like be able to use a specific output directory without first running cmake inside that directory. - Christian Bülow Skovborg
What I can say for sure is that there are no cmake commands to do that. And what is proposed on internet, to use custom_command, make cmake unusefull. If you realy need, you could consider modifying cmake source code, it is well organized and the code is clean and easy to read. (no horrible macros, descriptive names, no premature optimization and so on) - Oliv
Just write a cmake wrapper, that cd to that directory and runs cmake there - Slava

1 Answers

2
votes

You can't (easily) do this and you shouldn't try to do it.

The build tree is CMake's territory. It allows you some tiny amount of customization there (for instance you can specify where the final build artifacts will be placed through the *_OUTPUT_DIRECTORY target properties), but it does not give you any direct control over where intermediate files, like object files or internal make scripts used for bookkeeping are being placed.

This is a feature. You have no idea how all the build systems supported by CMake work internally. Maybe you can move that internal file to a different location in your build process, which is based on Unix Makefiles. But maybe that will also horribly break my build process, which is using Visual Studio. The bottom line is: You shouldn't have to care about this. CMake should take care of it, and by taking some freedom away from you, it ensures that it can actually do that job on all supported build toolchains.

But this might still be an unsatisfactory answer to you. You're the developer, shouldn't you be in full control of the results produced by your build? Of course you should, which is why CMake again grants you full control over what goes into the install tree. That is, whatever ends up in the install directory when you call make install (or whatever is the equivalent of installing in your build toolchain) is again under your control.

So you do control everything that matters: The source tree, the install tree, and that tiny portion of the build tree where the final build artifacts go. The rest of the build tree is off-limits for you and for good reasons.