Using file sets for both public and private headers

Hi! I tried using file sets for my project and I’m not sure how to proceed. I have public headers that I have inside include/, and some private headers in src/. I tried using file sets to describe both like so:

target_sources(mylib1
PRIVATE
  src/a.cpp
  src/b.cpp

PRIVATE FILE_SET HEADERS
  BASE_DIRS src
  FILES
    src/a_impl.hpp
    src/b_impl.hpp

PUBLIC FILE_SET HEADERS
  BASE_DIRS include
  FILES
    include/mylib1/a.hpp
    include/mylib1/b.hpp
)

However, doing so generates an error:

target_sources Scope PUBLIC for file set "HEADERS" does not match original
  scope PRIVATE

What would be the proper way to do this? I’m planning to install those private headers alongside modules and modules partitions.

a FILE_SET can have only one scope type (i.e. PRIVATE, PUBLIC or INTERFACE). You have to give unique names to your different file sets. Try the following:

target_sources(mylib1
PRIVATE
  src/a.cpp
  src/b.cpp

PRIVATE FILE_SET private_headers TYPE HEADERS
  BASE_DIRS src
  FILES
    src/a_impl.hpp
    src/b_impl.hpp

PUBLIC FILE_SET public_headers TYPE HEADERS
  BASE_DIRS include
  FILES
    include/mylib1/a.hpp
    include/mylib1/b.hpp
)

It seems to work pretty well! To make them installable I have to put both file sets public, and install the two of them in (possibly) separate folder to let module units include them, but not make them visible in interface.