rzjnzk
rzjnzk

Reputation: 140

Have cmake related files in a subdir under the project dir

I would like to have all cmake related files, i.e. CMakeKists.txt, CMakeCache.txt, CMakeFiles/, and Makefile; under a subdirectory of the project root directory, for example, build_files/.

How can this be done?

Upvotes: 1

Views: 82

Answers (1)

To directly answer your question: simply put CMakeLists.txt there, and run CMake from that directory. You will have to refer to all source files etc. using absolute paths or relative paths that start with .., of course, but it will work.

However, note that it is strongly discouraged (and with good reason) to run in-source builds with CMake; that is, generating buildsystems somewhere within the source tree. If not for backwards compatibility, even allowing them would be long deprecated or even forbidden in CMake itself.

It's much better to generate the buildsystem into a directory separate from your entire source tree. Even so, you can keep the CMakeLists.txt in the build_files, if you wish. Assuming your source is located under /path/source, you would then do it like this:

cd /path
mkdir build
cd build
cmake ../source/build_files

Upvotes: 1

Related Questions