Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake best practice

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

I would assume something along the lines of for large projects, having one in each directory is better.
If so, where should the threshold be?

like image 534
Ali Lown Avatar asked Sep 17 '10 20:09

Ali Lown


1 Answers

I would certainly go for using multiple CMakeListst.txt files.

As a rule of thumb I think you should go for one CMakeLists.txt (and thus subdirectory) per target. So, each library or executable has its own CMakeLists.txt.

You can then create one "master" CMakeLists.txt that includes all the others using the add_subdirectory call. If you take care that you order these statements correctly, you can easily reference previously defined targets in the other CMakeLists.txt file.

like image 97
pkit Avatar answered Oct 09 '22 14:10

pkit