summaryrefslogtreecommitdiff
path: root/Tests/InterfaceLibrary
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-07-20 13:19:26 -0400
committerBrad King <brad.king@kitware.com>2020-08-07 08:46:32 -0400
commit439191313363caea225a508634495c50d4cc60dd (patch)
treeeb1156c1fbf93b4a9ea23ec812ba49ef7a195846 /Tests/InterfaceLibrary
parentafb998704e67d3d3ce5b24c112cb06e770fca78d (diff)
downloadcmake-439191313363caea225a508634495c50d4cc60dd.tar.gz
Add INTERFACE libraries to generated buildsystem if they have SOURCES
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
Diffstat (limited to 'Tests/InterfaceLibrary')
-rw-r--r--Tests/InterfaceLibrary/CMakeLists.txt1
-rw-r--r--Tests/InterfaceLibrary/definetestexe.cpp6
-rw-r--r--Tests/InterfaceLibrary/headerdir/CMakeLists.txt9
-rw-r--r--Tests/InterfaceLibrary/headerdir/iface_genheader.h.in1
4 files changed, 17 insertions, 0 deletions
diff --git a/Tests/InterfaceLibrary/CMakeLists.txt b/Tests/InterfaceLibrary/CMakeLists.txt
index 311ca2a4e7..ec0a604050 100644
--- a/Tests/InterfaceLibrary/CMakeLists.txt
+++ b/Tests/InterfaceLibrary/CMakeLists.txt
@@ -44,6 +44,7 @@ add_executable(InterfaceLibrary definetestexe.cpp)
target_link_libraries(InterfaceLibrary
iface_nodepends
headeriface
+ iface_genheader
subiface
intermediate
diff --git a/Tests/InterfaceLibrary/definetestexe.cpp b/Tests/InterfaceLibrary/definetestexe.cpp
index 9156426cdb..6c538405e3 100644
--- a/Tests/InterfaceLibrary/definetestexe.cpp
+++ b/Tests/InterfaceLibrary/definetestexe.cpp
@@ -15,6 +15,12 @@
# error Expected IFACE_HEADER_BUILDDIR
#endif
+#include "iface_genheader.h"
+
+#ifndef IFACE_GENHEADER
+# error Expected IFACE_GENHEADER
+#endif
+
extern int obj();
extern int sub();
extern int item();
diff --git a/Tests/InterfaceLibrary/headerdir/CMakeLists.txt b/Tests/InterfaceLibrary/headerdir/CMakeLists.txt
index 826a9ed9c0..ae030d7516 100644
--- a/Tests/InterfaceLibrary/headerdir/CMakeLists.txt
+++ b/Tests/InterfaceLibrary/headerdir/CMakeLists.txt
@@ -11,3 +11,12 @@ add_custom_target(headeriface_gen
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)
diff --git a/Tests/InterfaceLibrary/headerdir/iface_genheader.h.in b/Tests/InterfaceLibrary/headerdir/iface_genheader.h.in
new file mode 100644
index 0000000000..0a21b62688
--- /dev/null
+++ b/Tests/InterfaceLibrary/headerdir/iface_genheader.h.in
@@ -0,0 +1 @@
+#define IFACE_GENHEADER