Force ignore `add_subdirectory` for project

I quite frequently build third-party CMake-based packages, and many of them do not provide options to skip building some parts that are (in fact) optional or not required at all for my purposes (like tests, sometimes building tests take even longer time than the main binaries).

It’ll be nice to have a CMake variable to force-ignore specified directories and do not perform add_subdirectory(). E.g., for the project without the BUILD_TESTING “standard” option and having unconditional add_subdirectory(tests), I’d be happy to configure them like

$ cmake -DCMAKE_FORCE_IGNORE_SUBDIRS=tests ...

Also, I guess, lovers of the ExternalProject module may like this feature to ignore unneeded build subdirectories :wink:

Opinions?

As a maintainer of a project, I would hate having to field support questions for why “when I disable directory X, things break”. In fact, I’d probably just empty out any such variable if detected and say “this project already has ways of doing that, I recommend you just configure the project properly”.

And I recommend that you send patches to projects that don’t allow for disabling of various bits as you see fit. It may not be as simple as ignoring a directory of a given name. It’d be far better for the support of disabling things to be maintained centrally rather than in a per-build tree way.

AFAIK there is no way to do what you are asking.

There are package managers like Conan that alleviate this issue. But if the third party library you are using isn’t supported by your package manger, the only thing you can do is try to upstream changes to make the project simpler to install.

The problem is that I see quite many of these kinds of projects… where a maintainer(s) is not proficient in CMake and just don’t understand what is he doing. :frowning:

Sending patches to all of them is hard and painful work… starting from creating a new account, forking, patching, sending PR, waiting for uncertain time (project maybe not really active, the maintainer is not familiar w/ CMake well and can’t understand what the patch is doing and why this is good, etc.) …

For sure, I can apply a patch with commenting add_subdirectory what I don’t want to build… I’ve just looked for an easier way (as for me) – just having this feature in CMake allowing me to set some variable at CMake run-time to disable unneeded dirs…