5

I have been trying to figure out a good directory structure that is maintainable for large C++ projects. During my search I came across this resource here link. If I loosely follow the structure stated in that document, it seems I get something similar to the following

.
├── CMakeLists.txt
├── build
│   ├── Executable-OutputA
│   └── Library-OutputA
├── cmake
│   └── *.cmake
├── docs
├── include
│   └── *.h
├── lib
│   ├── LibraryA
│   │   ├── *.cpp
│   │   └── *.h
│   └── LibraryB
│       ├── *.cpp
│       └── *.h
├── src
│   ├── ExecutableA
│   │   ├── *.cpp
│   │   └── *.h
│   └── ExecutableB
│       ├── *.cpp
│       └── *.h
├── tests
└── third_party
    ├── External-ProjectA
    └── External-ProjectB
  • build: holds the outputted executables and libraries generated by the project
  • cmake: holds all the cmake packages that the project may require
  • doc: holds documentation files, typically doxygen
  • include: holds public headers files (might not be needed, not sure)
  • lib: holds all the libraries the user creates with their respective source and header files
  • src: holds all the executable projects the user makes with their respective headers and source files
  • tests: files to test both the executables and libraries
  • third_party: any third party projects, libraries, ect. usually downloaded from online or cloned

I believe this is an appropriate structure for large projects, but I do not have too much experience with projects that produce more than 3 or 4 targets. I want to ask the community for feedback and if they agree with the structure laid out above, or have better suggestions.

Edit: I have not been able to find too many posts detailing multiple target outputs as well as third party dependencies for large projects.

5
  • Possible duplicate of What's a good directory structure for larger C++ projects using Makefile?
    – Hasan
    Commented Oct 24, 2019 at 2:26
  • @SMMahmudulHasan I felt that my was different enough because I want to have multiple targets, not just an executable, or just a library. Also even in the answer, it says use cmake for large projects but does not elaborate on how to do so. I think that with all the complexity I have added with third party resources and such, my question warrants a different answer.
    – nick2225
    Commented Oct 24, 2019 at 2:35
  • This seems pretty sane. You might also take a look into some of the available package managers for C++, such as conan, instead of putting all third libraries into third_party folder.
    – darcamo
    Commented Oct 24, 2019 at 3:11
  • There is no universal good directory structure for CMake project. Just select the one you find convenient and follow it.
    – Tsyvarev
    Commented Oct 24, 2019 at 7:46
  • @Tsyvarev I agree. I just wanted feedback about this specific approach and its possible shortcomings that I may have missed.
    – nick2225
    Commented Oct 24, 2019 at 14:10

0

Browse other questions tagged or ask your own question.