# INTERFACE\_SOURCES not "triggering" dependent files

**URL:** https://discourse.cmake.org/t/interface-sources-not-triggering-dependent-files/6650
**Category:** Code
**Tags:** os:windows, gen:ninja
**Created:** [October 12, 2022, 6:40pm UTC](https://discourse.cmake.org/t/interface-sources-not-triggering-dependent-files/6650 "2022-10-12T18:40:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![marstaik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marstaik/32/2230_2.png) [@marstaik](https://discourse.cmake.org/u/marstaik)
#### Post date: [October 12, 2022, 6:40pm UTC](https://discourse.cmake.org/t/interface-sources-not-triggering-dependent-files/6650/1 "2022-10-12T18:40:23Z")

</div>

Im having an issue where I have an interface library `refl`, which has a bunch of header files such as `foo.h`, which have a custom command that produces `foo.h.refl.in` and `foo.h.refl.init.cpp`.

Example of the generation rules:  
`foo.h` → `foo.h.refl.in`, `foo.h.refl.init.cpp`  
`foo.cpp`  
`bar.h` → `bar.h.refl.in`, `bar.h.refl.init.cpp`

Example of the command:

```auto
add_custom_command(
      OUTPUT ${output_file} # .refl.in
                      ${static_init_outfile} # .refl.init.cpp
      COMMAND
        reflector -i ${input_file} -o ${output_file} #
        ${static_init_local_args} ${static_init_args} #
      DEPENDS reflector ${input_file}
      VERBATIM COMMAND_EXPAND_LISTS)

```

when `target_sources(refl INTERFACE foo.h.refl.in foo.h.refl.init.cpp)` is called, and then `refl` is added as a dependency to an executable, the generated files are not created, but there are build rules created for them, as seen by the CMAKE output:

```auto
[13/32] Building CXX object client\king_editor\CMakeFiles\gd_king_editor.dir\ __\__ \data\reflection\src\datapack_registration.cpp.refl.init.cpp.obj
FAILED: client/king_editor/CMakeFiles/gd_king_editor.dir/ __/__ /data/reflection/src/datapack_registration.cpp.refl.init.cpp.obj 
C:\PROGRA~1\LLVM\bin\clang-cl.exe /nologo -TP -DAPI_NAME=Vulkan -DDEBUG_ENABLED -DDISABLE_DEPRECATED -DDLL_SLIB_LIBRARY -DKN_WITH_EDITOR -DMSVC -DNOMINMAX -DREFLECT_STATIC_DISPATCH -DTOOLS_ENABLED -DTYPED_METHOD_BIND -DUSE_VOLK -DVK_USE_PLATFORM_WIN32_KHR -DVULKAN_ENABLED -DWASAPI_ENABLED -DWIN32 -DWIN64 -DWINDOWS_ENABLED -DWINMIDI_ENABLED -D_CRT_SECURE_NO_WARNINGS -D_WIN32_WINNT=0x0A00 -ID:\Projects\king\client -ID:\Projects\king\client\king_editor -ID:\Projects\king\client\platform\windows -ID:\Projects\king\client\thirdparty\volk -ID:\Projects\king\client\thirdparty\vulkan\include -ID:\Projects\king\client\thirdparty\vulkan -ID:\Projects\king\build\release_debug\client -ID:\Projects\king\slib\include -ID:\Projects\king\extern\concurrentqueue\include -ID:\Projects\king\extern\eigen\include -ID:\Projects\king\extern\asio\include -ID:\Projects\king\build\release_debug\include_gen\fbs\kn_messages -ID:\Projects\king\build\release_debug\include_gen\message_map -ID:\Projects\king\extern\flatbuffers\include -ID:\Projects\king\build\release_debug\include_gen\fbs\kn_fbs -ID:\Projects\king\data\include -ID:\Projects\king\build\release_debug\data\reflection\include -ID:\Projects\king\extern\reflection\refl\include -ID:\Projects\king\extern\boost_hana\include -imsvcD:\Projects\king\extern\libsodium\include -m64 /Zi /O2 /Ob1 /DNDEBUG -MD /EHsc -std:c++20 /showIncludes /Foclient\king_editor\CMakeFiles\gd_king_editor.dir\ __\__ \data\reflection\src\datapack_registration.cpp.refl.init.cpp.obj /Fdclient\king_editor\CMakeFiles\gd_king_editor.dir\gd_king_editor.pdb -c -- D:\Projects\king\build\release_debug\data\reflection\src\datapack_registration.cpp.refl.init.cpp
clang-cl: error: no such file or directory: 'D:\Projects\king\build\release_debug\data\reflection\src\datapack_registration.cpp.refl.init.cpp'
clang-cl: error: no input files

```

If I set the `*.refl.init.cpp` via target\_sources to `PRIVATE`, the files do get generated, but this is not the desired behavior (and it fails to link because of other reasons).

These files are meant to be injected directly into the final library that uses them for compilation, to inherit their defines and include paths (hence the INTERFACE library), as they have code that is executable-dependent due to defines, etc.

If I generate the files via setting them to `PRIVATE` and then switch back to `INTERFACE` after the files have been generated, compilation continues normally.

---

<div class="post-metadata">

### Author: ![marstaik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marstaik/32/2230_2.png) [@marstaik](https://discourse.cmake.org/u/marstaik)
#### Post date: [October 12, 2022, 7:13pm UTC](https://discourse.cmake.org/t/interface-sources-not-triggering-dependent-files/6650/2 "2022-10-12T19:13:41Z")

</div>

Setting the `.refl.init.cpp` files to be `PUBLIC` sources on the `INTERFACE` targets seems to work, but I’m not sure if this is giving me the behavior I expect, or if it just so happens to work.
