0

I'm developing a cpp library and my CMakeList.txt starts to look like a big list of files. The library provides UI components so there is a lot of small classes, and UI related files. I find it hard to maintain as it hides logic and I wonder if there's something I can do.

I started making directories to regroup some files that are strongly connected to each other to make it clearer but it doesn't help the CMakeList. I consider two approaches:

  1. Using file and GLOB but I read that's not recommended
  2. Using "*.cmake" file in subfolders that will list files so I can keep the main CMakeLists.txt clean (or at least less overloaded).

To illustrate:

MyLibrary
│  CMakeLists.txt   ////< Big CMakeLists I want to split
│  filexxx.cpp
|  filexxx.h
│  more and more files
|  ...
└───Component
│   │   filexxx.cpp
│   │   filexxx.h
│   │   ...
└───SomeDialog
│   │   filexxx.cpp
│   │   filexxx.h
└───... ///< more directories
└───ui
│   │   someUiRelatedStuff.ui
│   │   someUiRelatedStuff.ui

CMakeLists.txt

set(${PROJECT_NAME}_SRC
   filexxx.cpp
   Component/filexxx.cpp
   SomeDialog/filexxx.cpp
   # and so on for hundred of lines ...
)

# same goes for _HDR and _UI

All I could find was how to organize large project with multiple libraries or executables but not how to manage a big one. The closest question was : How to write "CMakeLists.txt" for a big project with multiple subdirectories? but it's not really helping.

VSA
  • 43
  • 1
  • 5
  • 2
    I put a `CMakeLists.txt` in each library or executable folder and one in the root level. So each `CMakeLists.txt` at most handles a single target. – drescherjm Oct 07 '21 at 17:45
  • 3
    Consider OBJECT libraries, built with a CMakeLists.txt in each subfolder. – Richard Hodges Oct 07 '21 at 17:45
  • There may be patterns you're able to exploit. You may be able to create a cmake function that allows you to do something like this `my_component(filexxx COMPONENT DIALOG)` or even just `my_component(filexxx)` if there is a large number of sources with corresponding files in the "root" dir, `Component` and `SomeDialog`... – fabian Oct 07 '21 at 17:53

0 Answers0