the amount of project() statements

Consider the following situation :
A code base consisting out of:

  • many libraries
  • many applications/executables

Assume organized like this

rootdir
|—executables
|—libraries

Where the executables contains a sub directory per application, and the libraries contains per directory a library (could be further divided in more hierarchical directories)
Every directory has a CMakeLists.txt, add_subdirectory() it child directories, until you reach a library directory (so no more hierarchical directories) which then does an add_library()
similar for the executables, bu tin the end they do an add_executable()

What would be the adviced amount of project() 's ?
Could it be a project per directory and per executable, of just 1 project at the top level, and consider the entire code base as the project out of which many executables and/or libraries could be built ?

kind regards

Typically, yes. You would normally only use multiple project()s if your top-level project was using add_subdirectory() to add a project made by a third party (or one made by you but that lives in its own code base.)

Basically, if the subdirectories are grouped into a single coherent codebase then you would only have a single top-level project.

1 Like