# Any way to tell cmake to prioritise a file in compile order?

**URL:** https://discourse.cmake.org/t/any-way-to-tell-cmake-to-prioritise-a-file-in-compile-order/1005
**Category:** Usage
**Created:** [April 13, 2020, 5:01pm UTC](https://discourse.cmake.org/t/any-way-to-tell-cmake-to-prioritise-a-file-in-compile-order/1005 "2020-04-13T17:01:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![asm](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@asm](https://discourse.cmake.org/u/asm)
#### Post date: [April 13, 2020, 5:01pm UTC](https://discourse.cmake.org/t/any-way-to-tell-cmake-to-prioritise-a-file-in-compile-order/1005/1 "2020-04-13T17:01:54Z")

</div>

I have a large project with many, many files.

One file takes a very long time to compile - about 2.5 minutes. I don’t have control over that file because it’s a third party dependency.

The build (across cores) looks like this:

 ![CC Build 20200404](https://discourse.cmake.org/uploads/default/original/1X/529daf89827f4098412e4a1596a6a5bbcefc7da9.png)

With fewer cores, it’s possible this file starts late in the compile which extends the compile time a lot.

So - is there a nice way in cmake to ask it to compile this file as early as possible?

Thanks!

---

<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: [April 13, 2020, 5:32pm UTC](https://discourse.cmake.org/t/any-way-to-tell-cmake-to-prioritise-a-file-in-compile-order/1005/2 "2020-04-13T17:32:09Z")

</div>

CMake doesn’t have any (and therefore does not provide any) control over this. With that build output, I assume you’re using the `Ninja` generator. In that case, [this issue](https://github.com/ninja-build/ninja/issues/232) is of interest.

---

<div class="post-metadata">

### Author: ![asm](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@asm](https://discourse.cmake.org/u/asm)
#### Post date: [April 13, 2020, 5:45pm UTC](https://discourse.cmake.org/t/any-way-to-tell-cmake-to-prioritise-a-file-in-compile-order/1005/3 "2020-04-13T17:45:26Z")

</div>

Ah - thanks Ben!

I went back-and-forth as to whether this would be a cmake or a ninja thing.

I’ll take a look.

---

<div class="post-metadata">

### Author: ![asm](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@asm](https://discourse.cmake.org/u/asm)
#### Post date: [April 16, 2020, 8:44pm UTC](https://discourse.cmake.org/t/any-way-to-tell-cmake-to-prioritise-a-file-in-compile-order/1005/4 "2020-04-16T20:44:49Z")

</div>

In case anyone lands here looking for something similar, I asked the same question over on the [ninja repo](https://github.com/ninja-build/ninja/issues/1761).

There is an [open PR to support this](https://github.com/ninja-build/ninja/pull/1333), but it’s old and hasn’t been merged…

Another thing in that PR is pretty cool: on rebuild it uses info from previous builds to adjust the order automatically.
