add_library(): Improvement proposal
install()
command has a nice feature to install public headers. Unfortunately, when adding sources to a library there is no way to set this property. And it's really hard not to repeat myself and trying to use modern CMake. I'm probably Ok to get target sources from the SOURCES
property and loop over filtered list... but unfortunately it is not possible to expand generator expressions, so this way is doomed by design. The only working way is to use variables (yeah, which are fragile) to manage a list of header files and use it for library definition and later to loop and set PUBLIC_HEADER
property.
Instead, I would prefer to have smth like this:
add_library(
foo
PUBLIC_HEADERS
# Sources below would be added to `PUBLIC_HEADERS` property of the target
foo.hh
subdir/bar.hh
SOURCES
# Ordinal sources
foo.cc
subdir/bar.cc
)
install(
TARGETS foo
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
I'd like to implement this as MR if nobody has any objections or better ideas...