There's no "diamond of death" problem, like in C++.Įdit: Here's one of my projects that shows a more real-world example, complete with multiple executables, lots of libraries with dependencies (including third-party libraries), header-only libraries, platform-specific switches, and other stuff you're likely to run into in real world projects. So, I don't see a problem with this sort of setup. If the dependency is not there, there will be an error, and that's fine, since it's a required dependency. There's no need to check for the dependency, and try to guard against an error. Target_include_directories(Lib_A PRIVATE "$ Lib_A Lib_B) # You may also need to give include paths So, in the root CMakefiles.txt, you'd have: # Honestly, I'm not even sure if the order matters or not, but I If both lib_A and lib_B depend on lib_C, then I just assume that lib_C is going to be defined before lib_A and lib_B. I typically don't call add_subdirectory() from the submodules themselves. Maybe I'm thinking the single file method will be more complicated than it is. I'll also admit that the having to do #ifndef cmake edition, i.e if(NOT TARGET. The main problem I have is debugging accross multiple CMakeLists files, which almost invariably happens because you can only call add_subdirectory on a set of directories once. With all this being said the recursive way does have some issues as well. Isn't having one massive CMakeLists file a pain to read and edit? Doesn't this also fly in the face of good software design where you want things to be independent and composible? What happens when you need to do some extensive pre build switching to bring in drivers specific to the microcontroller or board you're targeting? In the recursive scenario you just add the correct subdirectory. How do you select a subset of modules to build without attempting to build the others? Often I'll have things that are broken and don't want to attempt to build them. As far as the CMakeLists files though, having one large files seems like a bad idea for both maintenance and usability. I know recursive make was (is?) considered a no-no for parallelization reasons but it seems to work well for me so far (possibly due to influence from ninja). This allows the modules to be built independantly for testing and they pull in only what they need. I'm writing an RTOS targeting 32 bit microcontrollers in the Cortex-M4 area and have been using cmake recursively in each software module.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |