# sbt file changes and rebuild?

**URL:** <https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415>\
**Category:** Build & Install\
**Created:** [March 4, 2020, 6:15pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415 "2020-03-04T18:15:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aron.helser](https://discourse.kitware.com/user_avatar/discourse.kitware.com/aron.helser/32/149_2.png) [@aron.helser](https://discourse.kitware.com/u/aron.helser)\
**Post date:** [March 4, 2020, 6:15pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/1 "2020-03-04T18:15:17Z")

</div>

I’m adding an operation to aeva-session, and I’m changing the associated .sbt file. If I just rebuild with `ninja`, the changes are not picked up - I have to explicitly run `cmake .` for my changes to the .sbt to be included. I’ve observed this behavior in smtk proper as well. I’m building on windows. Is this expected behavior, or is there a dependency we can add so cmake gets run automatically by ninja?

---

<div class="post-metadata">

**Author:** ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)\
**Post date:** [March 4, 2020, 6:23pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/2 "2020-03-04T18:23:05Z")

</div>

This is a known issue on all platforms.

Clippy says: It looks like you are volunteering to fix an issue! Would you like some help? You should probably start by changing the `smtk_operation_xml` function in `CMake/SMTKOperationXML.cmake` to add a target that writes a file instead of invoking `configureFileAsCVariable()` (which happens at cmake-time, not build-time).

---

<div class="post-metadata">

**Author:** ![aron.helser](https://discourse.kitware.com/user_avatar/discourse.kitware.com/aron.helser/32/149_2.png) [@aron.helser](https://discourse.kitware.com/u/aron.helser)\
**Post date:** [March 4, 2020, 6:50pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/3 "2020-03-04T18:50:00Z")

</div>

What’s an example of a target that writes a file, if you know one?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.kitware.com/u/ben.boeckel)\
**Post date:** [March 4, 2020, 7:52pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/4 "2020-03-04T19:52:24Z")

</div>

`vtkEncodeString.cmake` has what you want 🙂 . [https://gitlab.kitware.com/vtk/vtk/-/blob/master/CMake/vtkEncodeString.cmake](https://gitlab.kitware.com/vtk/vtk/-/blob/master/CMake/vtkEncodeString.cmake)

---

<div class="post-metadata">

**Author:** ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)\
**Post date:** [March 5, 2020, 2:24pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/5 "2020-03-05T14:24:34Z")

</div>

@aron.helser Yes, what @ben.boeckel said. It would be nice to port/copy/steal the function from `VTK/CMake/vtkEncodeString.cmake` that invokes `add_custom_command()` rather than calling `configure_file()`.

---

<div class="post-metadata">

**Author:** ![aron.helser](https://discourse.kitware.com/user_avatar/discourse.kitware.com/aron.helser/32/149_2.png) [@aron.helser](https://discourse.kitware.com/u/aron.helser)\
**Post date:** [March 5, 2020, 10:04pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/6 "2020-03-05T22:04:18Z")

</div>

I’m stuck - I’ve refactored following the pattern from `vtkEncodeString`, but I’m getting a cmake error:

```
-- Configuring done
CMake Error at smtk/CMakeLists.txt:107 (add_library):
  Cannot find source file:

    D:/akit/cmb/smtk/build/smtk/attribute/Write_xml.h

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.

```

David looked over my shoulder, and we can’t figure out how to tell cmake to expect this generated file. Here’s my [updated method](https://gitlab.kitware.com/aron.helser/smtk/-/blob/08f7e9cda46747f3fdb484f332c7d34cb085b1e2/CMake/SMTKOperationXML.cmake#L48). I’m only calling it in one place right now. Notice I tried to add a `GENERATED` property to the file. I return the generated filename to the parent scope, then add it to the list of headers, then in the main smtk cmake I feed the header list to `add_library()`. If I didn’t do this, cmake generation would complete, but the file wouldn’t generate so compilation failed.

@ben.boeckel can you take a look?

---

<div class="post-metadata">

**Author:** ![aron.helser](https://discourse.kitware.com/user_avatar/discourse.kitware.com/aron.helser/32/149_2.png) [@aron.helser](https://discourse.kitware.com/u/aron.helser)\
**Post date:** [March 5, 2020, 11:04pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/7 "2020-03-05T23:04:41Z")

</div>

David pointed out a blog that referenced the [faq](https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory) so I tried adding a custom target, and I think I have it working for one target. I guess I need to name custom targets with path names to keep them from conflicting.

---

<div class="post-metadata">

**Author:** ![aron.helser](https://discourse.kitware.com/user_avatar/discourse.kitware.com/aron.helser/32/149_2.png) [@aron.helser](https://discourse.kitware.com/u/aron.helser)\
**Post date:** [March 6, 2020, 2:48pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/8 "2020-03-06T14:48:08Z")

</div>

Added a [custom target](https://gitlab.kitware.com/aron.helser/smtk/-/blob/smtk_operation_xml_build_time/CMake/SMTKOperationXML.cmake#L65) based on the file path - whatdya think?

---

<div class="post-metadata">

**Author:** ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)\
**Post date:** [March 6, 2020, 5:44pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/9 "2020-03-06T17:44:12Z")

</div>

LGTM!

---

<div class="post-metadata">

**Author:** ![tj.corona](https://discourse.kitware.com/user_avatar/discourse.kitware.com/tj.corona/32/35_2.png) [@tj.corona](https://discourse.kitware.com/u/tj.corona)\
**Post date:** [March 6, 2020, 6:10pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/10 "2020-03-06T18:10:47Z")

</div>

This was a really annoying bug. Thanks @aron.helser for going after it!

---

<div class="post-metadata">

**Author:** ![aron.helser](https://discourse.kitware.com/user_avatar/discourse.kitware.com/aron.helser/32/149_2.png) [@aron.helser](https://discourse.kitware.com/u/aron.helser)\
**Post date:** [March 9, 2020, 8:35pm UTC](https://discourse.kitware.com/t/sbt-file-changes-and-rebuild/415/11 "2020-03-09T20:35:46Z")

</div>

[https://gitlab.kitware.com/cmb/smtk/-/merge\_requests/2017](https://gitlab.kitware.com/cmb/smtk/-/merge_requests/2017) has the final changes.
