# CMAKE\_OPTIMIZE\_DEPENDENCIES increases the number of deps for a target

**URL:** https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773
**Category:** Usage
**Created:** [November 2, 2022, 4:20pm UTC](https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773 "2022-11-02T16:20:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Zachary\_Turner](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zachary_turner/32/1551_2.png) [@Zachary\_Turner](https://discourse.cmake.org/u/Zachary_Turner)
#### Post date: [November 2, 2022, 4:20pm UTC](https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773/1 "2022-11-02T16:20:35Z")

</div>

I am trying out CMAKE\_OPTIMIZE\_DEPENDENCIES.

I did an experiment where I configured twice, once with COD=0, and again with COD=1. Then I wrote a little tool in Python that parsed the cmake-file-api reply for the codemodel, and went through every target and printed out the list of dependencies, as reported in the “dependencies” object of the target-xxx.json file.

When I do this, there are some targets where the dependency count _increases_ with COD=1. I’ve read the documentation and I don’t see how this is possible. The documentation says that COD first removes all dependencies, and then only adds them back if certain conditions are met. This reads to me as though the number of direct + indirect dependencies must _necessarily_ be less with COD=1 than it is with COD=0.

The only thing I’m not sure about is whether the dependencies reported in the file-api reply includes both direct + indirect, and the file-api documentation doesn’t make this clear either. If it reports direct+indirect, then I think this is a bug in the implementation of COD. If it only reports direct, then the behavior is probably correct.

Any advice appreciated.

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [November 2, 2022, 4:35pm UTC](https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773/2 "2022-11-02T16:35:07Z")

</div>

Please post a minimum reproducible example which causes the number of dependencies to increase.

---

<div class="post-metadata">

### Author: ![Zachary\_Turner](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zachary_turner/32/1551_2.png) [@Zachary\_Turner](https://discourse.cmake.org/u/Zachary_Turner)
#### Post date: [November 2, 2022, 4:44pm UTC](https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773/3 "2022-11-02T16:44:34Z")

</div>

> [@kyle.edwards](#):
>
> dependencies to increase

Do you have any suggestions about how to minimize my repro? This is a pretty large application with a few thousand targets, and the problem only happens on some of them. It’s closed source, so I can’t just link to the repository and tell you the configure steps either.

---

<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 2, 2022, 4:47pm UTC](https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773/4 "2022-11-02T16:47:34Z")

</div>

> [@Zachary\_Turner](#):
>
> Do you have any suggestions about how to minimize my repro?

You can strip out those that don’t change first. Once you have that minimized, replacing sources and such with dummy files would be the next thing I’d do.

---

<div class="post-metadata">

### Author: ![Mikael\_Persson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mikael_persson/32/980_2.png) [@Mikael\_Persson](https://discourse.cmake.org/u/Mikael_Persson)
#### Post date: [November 7, 2022, 1:00pm UTC](https://discourse.cmake.org/t/cmake-optimize-dependencies-increases-the-number-of-deps-for-a-target/6773/5 "2022-11-07T13:00:00Z")

</div>

I think cod may increase the number of dependencies if the build system has cycles and missing dependencies.
