mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 03:39:43 -06:00
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
23 lines
705 B
CMake
23 lines
705 B
CMake
|
|
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
|
|
|
|
add_library(headeriface INTERFACE)
|
|
|
|
add_custom_target(headeriface_gen
|
|
COMMENT "Generating iface_header_builddir.h"
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
${CMAKE_CURRENT_SOURCE_DIR}/iface_header_builddir.h.in
|
|
${CMAKE_CURRENT_BINARY_DIR}/iface_header_builddir.h
|
|
VERBATIM
|
|
)
|
|
add_dependencies(headeriface headeriface_gen)
|
|
|
|
add_custom_command(OUTPUT iface_genheader.h
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${CMAKE_CURRENT_SOURCE_DIR}/iface_genheader.h.in
|
|
${CMAKE_CURRENT_BINARY_DIR}/iface_genheader.h
|
|
DEPENDS
|
|
${CMAKE_CURRENT_SOURCE_DIR}/iface_genheader.h.in
|
|
VERBATIM)
|
|
add_library(iface_genheader INTERFACE iface_genheader.h)
|