2

I am currently starting a new project using C++ and CMake, in my last project I organized the code the following:

src
|--foo
|  |--bar.cpp
|  |--bar.hpp
|  |--CMakeLists.txt
|--baz
|  |--anotherFoo
|  |  |--Bahama.cpp
|  |  |--Bahama.hpp
|  |  |--CMakeLists.txt
|  |--baz.cpp
|  |--baz.hpp
|  |--CMakeLists.txt
|--CMakeLists.txt

so every subdirectory got its own CMakeLists.txt, which was included as library from other CMakeList files. Now I want to separate the .hpp and the .cpp files. Something like this:

src
|--foo
|  |--bar.cpp
|  |--CMakeLists.txt
|--baz
|  |--anotherFoo
|  |  |--Bahama.cpp
|  |  |--CMakeLists.txt
|  |--baz.cpp
|  |--CMakeLists.txt
|--CMakeLists.txt

include
|--foo
|  |--bar.hpp
|  |--CMakeLists.txt
|--baz
|  |--anotherFoo
|  |  |--Bahama.hpp
|  |  |--CMakeLists.txt
|  |--baz.hpp
|  |--CMakeLists.txt
|--CMakeLists.txt

What I am supposed to do with the CmakeLists files? Do I also need a CMakeLists file in every subdirectory, like I did in my example above? Or is there another way to do this? What do I write in this CMake files In the future I also want to add documentation with doxygen, how can I enable Doxygen support via Cmake in a structure like this?

should also every subdirectory get its own?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Exagon
  • 4,798
  • 6
  • 25
  • 53
  • 1
    check [this](https://stackoverflow.com/questions/33534115/preferred-cmake-project-structure) and [that](https://programmers.stackexchange.com/questions/289348/directory-organization-of-a-cmake-c-repository-containing-several-projects) questions, as well as [this repo](https://github.com/Barthelemy/CppProjectTemplate). – rsht Oct 07 '16 at 14:27
  • as for me, I will recommend separate includes to `project/include` folder (as in github repo above), as opposed to `project/src`. Also, I will add that I prefer to place includes in `include` folder only if they are not likely to change (e.g. library api, etc.). For "work-in-progress" includes: just place them in your `src` folder with your implementation (.cpp) files. – rsht Oct 07 '16 at 14:32
  • @rsht thanks for the all the information, the repo is realy nice – Exagon Oct 07 '16 at 15:09
  • @rsht the repo would be exactly my set up, except I am not familiar with CPack (but I will research about it) and I dont want to have two projects in one repo, so how would I setup the project, with all the cmake files, when I only want to use Boost.Test, Doxygen and Cmake for a single project? Sorry I am a Cmake beginner :\ – Exagon Oct 07 '16 at 18:00
  • you can just treat each project from the repo as separate (e.g. go and copy all template files from [this path](https://github.com/Barthelemy/CppProjectTemplate/tree/master/ProjA)). For all things that you don't know or that doesn't work - google it. If you find yourself really stuck on something - write here. But don't expect guys here to setup your cmake project for you :) good luck! – rsht Oct 08 '16 at 11:23
  • Why do you need to split headers? It'll brings some inconvenience to development process (already is...), so why to do that? Personally, I see no reason to do that... – zaufi Oct 11 '16 at 06:47

0 Answers0