# Force ignore \`add\_subdirectory\` for project

**URL:** https://discourse.cmake.org/t/force-ignore-add-subdirectory-for-project/4432
**Category:** Development
**Created:** [November 5, 2021, 8:00pm UTC](https://discourse.cmake.org/t/force-ignore-add-subdirectory-for-project/4432 "2021-11-05T20:00:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zaufi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zaufi/32/116_2.png) [@zaufi](https://discourse.cmake.org/u/zaufi)
#### Post date: [November 5, 2021, 8:00pm UTC](https://discourse.cmake.org/t/force-ignore-add-subdirectory-for-project/4432/1 "2021-11-05T20:00:39Z")

</div>

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 😉

Opinions?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 6, 2021, 1:46am UTC](https://discourse.cmake.org/t/force-ignore-add-subdirectory-for-project/4432/2 "2021-11-06T01:46:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [November 6, 2021, 8:11pm UTC](https://discourse.cmake.org/t/force-ignore-add-subdirectory-for-project/4432/3 "2021-11-06T20:11:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zaufi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zaufi/32/116_2.png) [@zaufi](https://discourse.cmake.org/u/zaufi)
#### Post date: [November 9, 2021, 11:07am UTC](https://discourse.cmake.org/t/force-ignore-add-subdirectory-for-project/4432/4 "2021-11-09T11:07:45Z")

</div>

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. ☹

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…
