Preventing installing `FILE_SET` headers from a dependent static library target

I have some top-level static library foo which in turn depends on another static library foo-dep which is included in the build using FetchContent.

foo-dep needs to be installed as part of the installation of foo, except for the headers of foo-dep. I handle this in the CMakeLists.txt of foo-dep as follows:

if(PROJECT_IS_TOPLEVEL)
  install(
    TARGETS foo-dep-static
    FILE_SET HEADERS
  )
endif()

However, this results in the following CMake error when building the top-level foo project:

CMake Error at foo-dep/CMakeLists.txt (install):
  install TARGETS target foo-dep-static is exported but not all of its interface
  file sets are installed

I found some other topics requesting information on this problem, and it seems CMake does currently not support this use case (which I think is a problem). Assuming this is still a limitation, what would be an acceptable work-around such that the resulting CMake logic will be as idiomatic as possible?

Replying to my own topic :stuck_out_tongue:

It seems influencing the visibility of the FILE_SET depending on PROJECT_IS_TOPLEVEL may be a viable solution.