I’d like to be able to optionally specify a file to the add_subdirectory() command, which it will use as CMakeLists.txt, as if it were overlaid into the subdirectory. The file can have any path and name (not necessarily CMakeLists.txt).
Like an “out-of-source build” (such as described in Professional CMake, section 2.2), this capability would introduce the notion of an “out-of-source configuration”, where a CMakeLists.txt file does not necessarily live next to or above the source files it configures.
My use case:
I believe a feature such as I’m suggesting here would allow a flatter, more straight-forward file/dir layout, like this:
How do you propose to use CMake in cases such as I described? Isn’t this common enough to consider?
My example here actually oversimplifies the libraries that I’m probably going to wind up using. They have nested git submodules, so I won’t be able implement the option 2 (extra subdirs).
CMake itself vendors several third-party libraries (with options to use external copies) and has no problem maintaining CMakeLists.txt files embedded among their source trees. We use scripts to import snapshots of the upstream libraries into pristine vendor branches and then subtree-merge them into our repo, integrating with any local changes such as the addition of CMakeLists.txt.
To date, I’ve been using add_subdirectory() with forks of the library repos
Yes. In the case of Git submodules one can point them at dedicated forks/branches where CMakeLists.txt files are added. That also has the advantage of versioning the CMake build system with the code it builds, and enabling it to be used by multiple dependents without duplication. I consider this better than the solutions proposed above, and it sounds like you’re already doing it.
Interesting. Not a fan of git subtree, personally. I prefer the clearer delineation that git submodule provides. (Also the upstream vendor is using git submodule in my case.)
Sorry, I don’t follow. You quoted a statement of mine, not a question. What does your “yes” mean here?
For want of the feature I proposed here, I’m working on implementing this as I’m refactoring our library submodules. I’d rather pull the CMakeLists.txt files out of the submodules, so that I don’t have to maintain custom branches within them. But I have several submodules, some nested, so I don’t want to have a single monolithic CMakeLists.txt for them all.
Suppose if I want to only build some of the files in a submodule for one project, and a different subset for another. In this case doesn’t it make sense to allow separation of CMakeLists.txt from the source it configures? CMakeLists.txt gets captured in the project commit, and the submodule commit is pegged.