summaryrefslogtreecommitdiff
path: root/Tests/CMakeCommands/target_link_libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/CMakeCommands/target_link_libraries')
-rw-r--r--Tests/CMakeCommands/target_link_libraries/CMakeLists.txt58
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depB.cpp6
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depD.cpp13
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depD.h11
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depG.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depG.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/empty.cpp1
-rw-r--r--Tests/CMakeCommands/target_link_libraries/libgenex.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/libgenex.h12
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt5
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h12
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetA.cpp11
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetB.cpp10
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetC.cpp16
17 files changed, 194 insertions, 3 deletions
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
index 1faa88848..388164455 100644
--- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@ -34,6 +34,13 @@ generate_export_header(depB)
target_link_libraries(depB LINK_PRIVATE depA)
+add_library(libgenex SHARED libgenex.cpp)
+generate_export_header(libgenex)
+
+set_property(TARGET depB APPEND PROPERTY
+ LINK_LIBRARIES $<1:libgenex>
+)
+
add_library(depC SHARED depC.cpp)
generate_export_header(depC)
@@ -53,6 +60,57 @@ set_target_properties(targetA PROPERTIES LINK_INTERFACE_LIBRARIES "")
assert_property(targetA LINK_INTERFACE_LIBRARIES "")
+add_subdirectory(subdir)
+target_link_libraries(targetA subdirlib)
+
target_link_libraries(targetA depB depC)
assert_property(targetA LINK_INTERFACE_LIBRARIES "")
+
+# Exclude depIfaceOnly from ALL so that it will only be built if something
+# depends on it. As it is in the link interface of depB, targetA
+# will depend on it. That dependency is what is being tested here.
+add_library(depIfaceOnly SHARED EXCLUDE_FROM_ALL depIfaceOnly.cpp)
+generate_export_header(depIfaceOnly)
+set_property(TARGET depB APPEND PROPERTY LINK_INTERFACE_LIBRARIES depIfaceOnly)
+
+add_library(depD SHARED depD.cpp)
+generate_export_header(depD)
+set_property(TARGET depD APPEND PROPERTY
+ LINK_INTERFACE_LIBRARIES
+ $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:depA>
+)
+
+add_executable(targetB targetB.cpp)
+target_link_libraries(targetB depD)
+
+macro(create_header _name)
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_name}")
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_name}/${_name}.h" "//${_name}.h\n")
+endmacro()
+
+create_header(foo)
+create_header(bar)
+
+add_library(depG SHARED depG.cpp)
+generate_export_header(depG)
+target_include_directories(depG INTERFACE
+ "${CMAKE_CURRENT_BINARY_DIR}/foo"
+ "${CMAKE_CURRENT_BINARY_DIR}/bar"
+)
+target_compile_definitions(depG INTERFACE
+ TEST_DEF
+)
+
+
+add_executable(targetC targetC.cpp)
+if(NOT BORLAND AND NOT WATCOM)
+ # Linking to a target containing a + should be non-fatal, though it does
+ # not work at all on Borland or watcom
+ add_library(wrapc++ empty.cpp)
+ target_link_libraries(targetC wrapc++)
+endif()
+# The TARGET_PROPERTY expression is duplicated below to test that there is no
+# shortcutting of the evaluation by returning an empty string.
+set(_exe_test $<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>)
+target_link_libraries(targetC $<$<AND:${_exe_test},${_exe_test}>:depG>)
diff --git a/Tests/CMakeCommands/target_link_libraries/depB.cpp b/Tests/CMakeCommands/target_link_libraries/depB.cpp
index 97e5be274..4f46552d7 100644
--- a/Tests/CMakeCommands/target_link_libraries/depB.cpp
+++ b/Tests/CMakeCommands/target_link_libraries/depB.cpp
@@ -3,9 +3,13 @@
#include "depA.h"
+#include "libgenex.h"
+
int DepB::foo()
{
DepA a;
- return 0;
+ LibGenex lg;
+
+ return a.foo() + lg.foo();
}
diff --git a/Tests/CMakeCommands/target_link_libraries/depD.cpp b/Tests/CMakeCommands/target_link_libraries/depD.cpp
new file mode 100644
index 000000000..b02c76cf3
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depD.cpp
@@ -0,0 +1,13 @@
+
+#include "depD.h"
+
+int DepD::foo()
+{
+ return 0;
+}
+
+DepA DepD::getA()
+{
+ DepA a;
+ return a;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depD.h b/Tests/CMakeCommands/target_link_libraries/depD.h
new file mode 100644
index 000000000..d24ff5f7c
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depD.h
@@ -0,0 +1,11 @@
+
+#include "depd_export.h"
+
+#include "depA.h"
+
+struct DEPD_EXPORT DepD
+{
+ int foo();
+
+ DepA getA();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depG.cpp b/Tests/CMakeCommands/target_link_libraries/depG.cpp
new file mode 100644
index 000000000..65b9655c5
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depG.cpp
@@ -0,0 +1,7 @@
+
+#include "depG.h"
+
+int DepG::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depG.h b/Tests/CMakeCommands/target_link_libraries/depG.h
new file mode 100644
index 000000000..1a3658914
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depG.h
@@ -0,0 +1,7 @@
+
+#include "depg_export.h"
+
+struct DEPG_EXPORT DepG
+{
+ int foo();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp
new file mode 100644
index 000000000..3b90af008
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.cpp
@@ -0,0 +1,7 @@
+
+#include "depIfaceOnly.h"
+
+int DepIfaceOnly::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h
new file mode 100644
index 000000000..dddf6a5e4
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/depIfaceOnly.h
@@ -0,0 +1,7 @@
+
+#include "depifaceonly_export.h"
+
+struct DEPIFACEONLY_EXPORT DepIfaceOnly
+{
+ int foo();
+};
diff --git a/Tests/CMakeCommands/target_link_libraries/empty.cpp b/Tests/CMakeCommands/target_link_libraries/empty.cpp
new file mode 100644
index 000000000..ab32cf6c8
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/empty.cpp
@@ -0,0 +1 @@
+// No content
diff --git a/Tests/CMakeCommands/target_link_libraries/libgenex.cpp b/Tests/CMakeCommands/target_link_libraries/libgenex.cpp
new file mode 100644
index 000000000..c925c0821
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/libgenex.cpp
@@ -0,0 +1,7 @@
+
+#include "libgenex.h"
+
+int LibGenex::foo()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/libgenex.h b/Tests/CMakeCommands/target_link_libraries/libgenex.h
new file mode 100644
index 000000000..733f9b6df
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/libgenex.h
@@ -0,0 +1,12 @@
+
+#include "libgenex_export.h"
+
+#ifndef LIBGENEX_H
+#define LIBGENEX_H
+
+struct LIBGENEX_EXPORT LibGenex
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt
new file mode 100644
index 000000000..9d7fa6cb8
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
+
+add_library(subdirlib SHARED subdirlib.cpp)
+generate_export_header(subdirlib)
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp
new file mode 100644
index 000000000..cd2f1a23a
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp
@@ -0,0 +1,7 @@
+
+#include "subdirlib.h"
+
+int SubDirLibObject::foo() const
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h
new file mode 100644
index 000000000..e386f87b2
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h
@@ -0,0 +1,12 @@
+
+#ifndef SUBDIRLIB_H
+#define SUBDIRLIB_H
+
+#include "subdirlib_export.h"
+
+struct SUBDIRLIB_EXPORT SubDirLibObject
+{
+ int foo() const;
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_link_libraries/targetA.cpp b/Tests/CMakeCommands/target_link_libraries/targetA.cpp
index 3c6472e9a..d1321a15f 100644
--- a/Tests/CMakeCommands/target_link_libraries/targetA.cpp
+++ b/Tests/CMakeCommands/target_link_libraries/targetA.cpp
@@ -1,12 +1,19 @@
#include "depB.h"
#include "depC.h"
+#include "depIfaceOnly.h"
-int main(int argc, char **argv)
+#include "subdirlib.h"
+
+int main(int, char **)
{
DepA a;
DepB b;
DepC c;
- return a.foo() + b.foo() + c.foo();
+ DepIfaceOnly iface_only;
+
+ SubDirLibObject sd;
+
+ return a.foo() + b.foo() + c.foo() + iface_only.foo() + sd.foo();
}
diff --git a/Tests/CMakeCommands/target_link_libraries/targetB.cpp b/Tests/CMakeCommands/target_link_libraries/targetB.cpp
new file mode 100644
index 000000000..0913a57b0
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/targetB.cpp
@@ -0,0 +1,10 @@
+
+#include "depD.h"
+
+int main(int, char **)
+{
+ DepD d;
+ DepA a = d.getA();
+
+ return d.foo() + a.foo();
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/targetC.cpp b/Tests/CMakeCommands/target_link_libraries/targetC.cpp
new file mode 100644
index 000000000..a4ef6369d
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/targetC.cpp
@@ -0,0 +1,16 @@
+
+#include "depG.h"
+
+#include "foo.h"
+#include "bar.h"
+
+#ifndef TEST_DEF
+#error Expected TEST_DEF definition
+#endif
+
+int main(int, char **)
+{
+ DepG g;
+
+ return g.foo();
+}