# VS: CMP0147 always triggers custom steps rebuild for CMake 3.27+

**URL:** https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548
**Category:** Usage
**Tags:** os:windows, gen:vs
**Created:** [April 1, 2024, 12:24pm UTC](https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548 "2024-04-01T12:24:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![AJIOB](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ajiob/32/852_2.png) [@AJIOB](https://discourse.cmake.org/u/AJIOB)
#### Post date: [April 1, 2024, 12:24pm UTC](https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548/1 "2024-04-01T12:24:21Z")

</div>

Hello

I have a big closed-source project, that uses CMake as a main build system.

After upgrading from CMake 3.26 to CMake 3.27 I see, that my custom generators are always rebuild.

I just run 5 sequential builds and all of the time my custom generators were executed again.

When I add next lines, all was fixed & works as before.

```cmake
if(POLICY CMP0147)
    # This CMake 3.27 policy breaks incremental builds for IDL files
    cmake_policy(SET CMP0147 OLD)
endif()

```

My code for custom files generation:

```cmake
    add_custom_command(
        OUTPUT ${generatedSources}
        COMMAND_EXPAND_LISTS
        COMMAND
            # Shell launcher, that passes another args next
            "${idlScriptPath}"
            # Command to call IDL compiler
            "${IDL_COMPILER}"
                "${additionalFlags}"
        MAIN_DEPENDENCY "${filePath}"
        DEPENDS "${idlScriptPath}"
        DEPFILE "${depFile}"
        WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
        COMMENT "Processing IDL [${filePath}]"
    )

    # add sources and include paths
    target_sources(
        ${TARGET}
        PRIVATE ${generatedSources}
    )

```

All of the `generatedSources` have no spaces inside the names.

For Linux I’m using the Ninja generator & don’t see any problem with concurrency (with CMake 3.25 & 3.27.9).

## My Windows environment

- Visual Studio Professional 2022 (17.9.5)
- CMake 3.27.9, 3.28.4, 3.29.0 (reproduced on all CMake 3.27+ versions)

P.S. Every CMake was reconfigured for dedicated clean directory

---

<div class="post-metadata">

### Author: ![AJIOB](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ajiob/32/852_2.png) [@AJIOB](https://discourse.cmake.org/u/AJIOB)
#### Post date: [April 10, 2024, 9:26am UTC](https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548/2 "2024-04-10T09:26:48Z")

</div>

I united IDL `add_custom_command` results to the single `add_custom_target`, as described [here](https://cmake.org/cmake/help/latest/command/add_custom_command.html#example-generating-files-for-multiple-targets), and works nice on Windows without policies updating.

---

<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 11, 2024, 4:20pm UTC](https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548/3 "2024-04-11T16:20:10Z")

</div>

Just to clarify, you no longer need to set the policy to `OLD`?

Note that the policy should have been `OLD` unless you updated your minimum CMake version. If you did that, adapting to new policy behaviors is part of bumping the version. In that case, it seems you found the solution (tie the custom commands together with a single custom target).

---

<div class="post-metadata">

### Author: ![AJIOB](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ajiob/32/852_2.png) [@AJIOB](https://discourse.cmake.org/u/AJIOB)
#### Post date: [April 16, 2024, 8:39am UTC](https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548/4 "2024-04-16T08:39:12Z")

</div>

Yes, you are right.

But it looks like unexpected part of adding the CMake 3.27 part support.

The main reason I need to add the the CMake 3.27 as a supported one, because [CMP0144](https://cmake.org/cmake/help/latest/policy/CMP0144.html) generates lots of warnings while CMake 3.26 don’t.  
That was not nice, because CMake 3.27 doesn’t fully mimic to the CMake 3.26 behavior if the CMake 3.27 support is not enabled.

---

<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 27, 2024, 3:31pm UTC](https://discourse.cmake.org/t/vs-cmp0147-always-triggers-custom-steps-rebuild-for-cmake-3-27/10548/5 "2024-04-27T15:31:24Z")

</div>

> [@AJIOB](#):
>
> That was not nice, because CMake 3.27 doesn’t fully mimic to the CMake 3.26 behavior if the CMake 3.27 support is not enabled.

Can you please make a small test case that shows this?
