# Automatic reconfiguration when CMakeLists.txt files change

**URL:** https://discourse.cmake.org/t/automatic-reconfiguration-when-cmakelists-txt-files-change/12712
**Category:** Usage
**Tags:** os:linux, gen:ninja
**Created:** [October 8, 2024, 9:28am UTC](https://discourse.cmake.org/t/automatic-reconfiguration-when-cmakelists-txt-files-change/12712 "2024-10-08T09:28:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shukron](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shukron/32/436_2.png) [@shukron](https://discourse.cmake.org/u/shukron)
#### Post date: [October 8, 2024, 9:28am UTC](https://discourse.cmake.org/t/automatic-reconfiguration-when-cmakelists-txt-files-change/12712/1 "2024-10-08T09:28:30Z")

</div>

We have a very large project built by gnu make at the top level.  
One of the components in the project is a CMake-based application.

The rule to build the app from the top level makefile looks something like:

```auto
app: $(APP_MAKEFILE)
    # Build the app
    cmake --build $(APP_BUILD_DIR)

$(APP_MAKEFILE): <some external deps>
    # Generate a makefile
    cmake -S <source dir> -B $(APP_BUILD_DIR) <lots of args>

```

Now I noticed that sometimes I modify the CMakeLists.txt files in the app, and it fails to compile.  
It generally happens when I promote a normal variable to a cache one, or vice versa.

For example we might have

```auto
if (NOT WITH_FOO)
    set(WITH_FOO 0)
endif()
target_compile_definitions(target PRIVATE WITH_FOO=${WITH_FOO})

```

Which I then promote to:

```auto
option(WITH_FOO "Use foo module" 0)
target_compile_definitions(target PRIVATE WITH_FOO=$<BOOL:${WITH_FOO}>)

```

It seems that when making such changes and then invoking `make`, only the `app` target will be built by invoking `cmake --build <build dir>`, but it will not trigger a reconfiguration even though CMakeLists.txt files have changed.

So I guess my question is - how can trigger a reconfiguration only when one is required?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [October 8, 2024, 9:32pm UTC](https://discourse.cmake.org/t/automatic-reconfiguration-when-cmakelists-txt-files-change/12712/2 "2024-10-08T21:32:45Z")

</div>

If you modify a `CMakeLists.txt file` that was used in the previous `cmake` run, then if you do a build it should automatically re-run `cmake` first. Are you saying you are not seeing that happen? If you’re instead saying that the build doesn’t rebuild anything, that would be because the final set of commands written to the Makefile aren’t changing, so whatever was built last time is still up-to-date.
