
INTERFACE libraries were created with the intention of collecting usage requirements for use by other targets via `target_link_libraries`. Therefore they were not allowed to have SOURCES and were not included in the generated buildsystem. In practice, this has become limiting: * Header-only libraries do have sources, they just do not compile. Developers should be able to edit those sources (the header files) in their IDE. * Header-only libraries may need to generate some of their header files via custom commands. Some projects work around these limitations by pairing each interface library with an `add_custom_target` that makes the header files and custom commands appear in the generated buildsystem and in IDEs. Lift such limitations by allowing INTERFACE libraries to have SOURCES. For those with sources, add a corresponding build target to the generated buildsystem. Fixes: #19145
21 lines
635 B
CMake
21 lines
635 B
CMake
cmake_policy(SET CMP0076 NEW)
|
|
enable_language(C)
|
|
|
|
# Test that an interface library can have PUBLIC sources.
|
|
# This causes the target to appear in the build system
|
|
# *and* causes consumers to use the source.
|
|
add_library(iface INTERFACE)
|
|
target_sources(iface
|
|
PUBLIC iface.c
|
|
# Private sources do not compile here or propagate.
|
|
PRIVATE iface_broken.c
|
|
)
|
|
|
|
# Test that an intermediate interface library does not get the
|
|
# sources and does not appear in the build system.
|
|
add_library(iface2 INTERFACE)
|
|
target_link_libraries(iface2 INTERFACE iface)
|
|
|
|
add_executable(use_iface use_iface.c)
|
|
target_link_libraries(use_iface PRIVATE iface2)
|