CMake add_subdirectory shorthands

In Beman.Optional26, the top-level CMakeLists.txt has this:

add_subdirectory(src)

src/CMakeLists.txt includes add_subdirectory(Beman). This is done similarly in src/Beman/CMakeLists.txt

I’m wondering if it would be good practice to omit CMakeLists.txt files that simply pass control to another subdirectory. In in the above case, the top-level CMake file would instead use add_subdirectory(src/Beman/Optional26). I see two benefits:

  1. The GitHub interface recognizes directories with a single subdirectory allowing users to get to the interesting files with a single click.
  2. Less boilerplate. These passthrough CMakeLists.txt files probably need to also get a license notice, etc.

What do folks think?

Hello David,

I agree with you. I think we inherited this hierarchy and I just propagated it forward. :smiley: Also, if voted, I would also add this statement as a requirement/recommendation into the Beman Standard.

1 Like

+1 to this – in our work codebase we skip over directories to minimize the required cmake files.

Feedback incorporated in Split build production vs testing by neatudarius · Pull Request #29 · beman-project/Optional26 · GitHub.

I created PR 28 to add this to the Beman standard.

PR looks good to me.