Best practice

When working with cmake, is it better to work with one large CMakeLists.txt in the root of the project or, as you can see, in some places, having one in each subdirectory?

I would suggest something like strings for large projects, with one in each directory being better.
If so, where should the threshold be?

+6
directory cmake
source share
1 answer

Of course, I would like to use several CMakeListst.txt files.

Generally, I think you should go for one CMakeLists.txt (and therefore a subdirectory) per target. So, each library or executable has its own CMakeLists.txt.

You can then create one β€œwizard” CMakeLists.txt that includes all the others using the add_subdirectory call. If you make sure you order these statements correctly, you can easily reference previously defined targets in another CMakeLists.txt file.

+4
source share

All Articles