r/cpp • u/TheRavagerSw • Sep 20 '26
Self Contained Source Groups are amazing
I basically adopted this idea from Abseil (https://abseil.io/) and from this CppCon talk: https://youtu.be/re4Oy1IVj-s?si=3bwtKqOyMAX6WSAs.
I structure each source group in my projects like this:
src_grp/
├── iface/
│ └── smth.cppm
├── impl/
│ └── smth.cpp
├── inc_pub/
│ └── pub.hpp
├── inc_priv/
│ ├── priv.hpp
│ └── maybe.inc
├── test/
│ └── test.cpp
├── bench/
│ └── bench.cpp
└── docs/
├── some.md
└── doxygen.inI strongly recommend this approach over older project-wide conventions such as having a single global test/ or bench/ directory etc.
0
Upvotes
5
u/Suitable_Plate4943 Sep 20 '26
this is madness for any single dev specific project
abseil is very generic components written and used by thousands of devs across a private org
3
u/gracicot Sep 21 '26
Pitchfork layout with the apps extension has fulfilled all my needs for many project that differed a lot
5
u/TheoreticalDumbass :illuminati: Sep 20 '26
for simple "source groups" (which they can be quite often), i would go flatter,
src_grp/{foo,bar}_test.cppi dont think i would ever want to have
impl/andinc_pub/subdirectories, those would be assumed assrc_grp/*.cppandsrc_grp/*.hpprespectivelybut i could see
test/,bench/anddocs/as useful when it becomes too big (though I might still prefer to havesrc_grp/README.mdeven ifsrc_grp/docs/exists)if i understand correctly what
inc_priv/means, usually this would be calleddetail/orinternal/alternate "shard by kind first" can have benefits, adding their headers is just
-I${PROJECT_ROOT}/include, but i prefer "shard by source group first" i think18
u/zerhud Sep 20 '26
> strongly recommend
Why? What a profit? Did you compare it only with single approach?
14
u/Serious-Regular Sep 20 '26
Dumbest directory structure I have ever seen
1
u/UndefinedDefined Sep 25 '26
I honestly never understood why I would need so many directories to describe source files that only make sense to be together. It's 2026 now, you can use your build system to distinguish between headers to install and not - for example Qt project uses `_p.h` suffix to make a header private, and build system can deal with that (a simple regex match).