summaryrefslogtreecommitdiff
path: root/Tests/ExportImport
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/ExportImport')
-rw-r--r--Tests/ExportImport/CMakeLists.txt75
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt145
-rw-r--r--Tests/ExportImport/Export/testExe1.c26
-rw-r--r--Tests/ExportImport/Export/testExe1lib.c1
-rw-r--r--Tests/ExportImport/Export/testExe2.c12
-rw-r--r--Tests/ExportImport/Export/testExe2lib.c10
-rw-r--r--Tests/ExportImport/Export/testExe2libImp.c7
-rw-r--r--Tests/ExportImport/Export/testExe3.c24
-rw-r--r--Tests/ExportImport/Export/testLib1.c1
-rw-r--r--Tests/ExportImport/Export/testLib2.c4
-rw-r--r--Tests/ExportImport/Export/testLib3.c10
-rw-r--r--Tests/ExportImport/Export/testLib3Imp.c10
-rw-r--r--Tests/ExportImport/Export/testLib3ImpDep.c7
-rw-r--r--Tests/ExportImport/Export/testLib4.c7
-rw-r--r--Tests/ExportImport/Export/testLib4lib.c4
-rw-r--r--Tests/ExportImport/Export/testLib4libdbg.c14
-rw-r--r--Tests/ExportImport/Export/testLib4libdbg1.c1
-rw-r--r--Tests/ExportImport/Export/testLib4libopt.c14
-rw-r--r--Tests/ExportImport/Export/testLib4libopt1.c1
-rw-r--r--Tests/ExportImport/Export/testLib5.c7
-rw-r--r--Tests/ExportImport/Export/testLib6.cxx6
-rw-r--r--Tests/ExportImport/Export/testLib6c.c5
-rw-r--r--Tests/ExportImport/Export/testLibCycleA1.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleA2.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleA3.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleB1.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleB2.c2
-rw-r--r--Tests/ExportImport/Export/testLibCycleB3.c1
-rw-r--r--Tests/ExportImport/Import/A/CMakeLists.txt150
-rw-r--r--Tests/ExportImport/Import/A/imp_lib1.c6
-rw-r--r--Tests/ExportImport/Import/A/imp_mod1.c13
-rw-r--r--Tests/ExportImport/Import/A/imp_testExe1.c25
-rw-r--r--Tests/ExportImport/Import/CMakeLists.txt19
-rw-r--r--Tests/ExportImport/Import/imp_testTransExe1.c6
-rw-r--r--Tests/ExportImport/InitialCache.cmake.in15
-rw-r--r--Tests/ExportImport/main.c4
36 files changed, 640 insertions, 0 deletions
diff --git a/Tests/ExportImport/CMakeLists.txt b/Tests/ExportImport/CMakeLists.txt
new file mode 100644
index 000000000..ccfb8940c
--- /dev/null
+++ b/Tests/ExportImport/CMakeLists.txt
@@ -0,0 +1,75 @@
+cmake_minimum_required (VERSION 2.7.20090711)
+project(ExportImport C CXX)
+
+# Wipe out the install tree to make sure the exporter works.
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/CleanupProject
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${ExportImport_BINARY_DIR}/Root
+ )
+add_custom_target(CleanupTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/CleanupProject)
+set_property(
+ SOURCE ${ExportImport_BINARY_DIR}/CleanupProject
+ PROPERTY SYMBOLIC 1
+ )
+
+if(CMAKE_CONFIGURATION_TYPES)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+else(CMAKE_CONFIGURATION_TYPES)
+ if(CMAKE_BUILD_TYPE)
+ set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}")
+ else(CMAKE_BUILD_TYPE)
+ set(NESTED_CONFIG_TYPE)
+ endif(CMAKE_BUILD_TYPE)
+endif(CMAKE_CONFIGURATION_TYPES)
+
+if(MINGW OR MSYS)
+ # Test CMAKE_GNUtoMS whether we have VS or not.
+ set(ExportImport_GNUtoMS 1)
+endif()
+
+configure_file(${ExportImport_SOURCE_DIR}/InitialCache.cmake.in
+ ${ExportImport_BINARY_DIR}/InitialCache.cmake @ONLY)
+
+# Build and install the exporter.
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/ExportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${ExportImport_SOURCE_DIR}/Export
+ ${ExportImport_BINARY_DIR}/Export
+ --build-noclean
+ --build-project Export
+ --build-target install
+ --build-generator ${CMAKE_GENERATOR}
+ --build-makeprogram ${CMAKE_MAKE_PROGRAM}
+ --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
+ )
+add_custom_target(ExportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ExportProject)
+add_dependencies(ExportTarget CleanupTarget)
+set_property(
+ SOURCE ${ExportImport_BINARY_DIR}/ExportProject
+ PROPERTY SYMBOLIC 1
+ )
+
+# Build and install the importer.
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/ImportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
+ --build-and-test
+ ${ExportImport_SOURCE_DIR}/Import
+ ${ExportImport_BINARY_DIR}/Import
+ --build-noclean
+ --build-project Import
+ --build-generator ${CMAKE_GENERATOR}
+ --build-makeprogram ${CMAKE_MAKE_PROGRAM}
+ --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
+ )
+add_custom_target(ImportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ImportProject)
+add_dependencies(ImportTarget ExportTarget)
+set_property(
+ SOURCE ${ExportImport_BINARY_DIR}/ImportProject
+ PROPERTY SYMBOLIC 1
+ )
+
+add_executable(ExportImport main.c)
+add_dependencies(ExportImport ImportTarget)
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
new file mode 100644
index 000000000..f06a4659f
--- /dev/null
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -0,0 +1,145 @@
+cmake_minimum_required (VERSION 2.7.20090711)
+project(Export C CXX)
+
+# Pretend that RelWithDebInfo should link to debug libraries to test
+# the DEBUG_CONFIGURATIONS property.
+set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug RelWithDebInfo)
+
+add_library(testExe1lib STATIC testExe1lib.c) # not exported
+add_executable(testExe1 testExe1.c)
+target_link_libraries(testExe1 testExe1lib)
+set_property(TARGET testExe1 PROPERTY VERSION 4)
+
+add_library(testExe2libImp SHARED testExe2libImp.c)
+set_property(TARGET testExe2libImp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
+add_library(testExe2lib SHARED testExe2lib.c)
+target_link_libraries(testExe2lib testExe2libImp)
+set_property(TARGET testExe2lib PROPERTY LINK_INTERFACE_LIBRARIES "")
+add_executable(testExe2 testExe2.c)
+set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
+set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
+
+add_library(testLib1 STATIC testLib1.c)
+add_library(testLib2 STATIC testLib2.c)
+target_link_libraries(testLib2 testLib1)
+
+# Test library with empty link interface. Link it to an implementation
+# dependency that itself links to dependencies publicly.
+add_library(testLib3ImpDep SHARED testLib3ImpDep.c)
+set_property(TARGET testLib3ImpDep PROPERTY LIBRARY_OUTPUT_DIRECTORY impl/dep)
+add_library(testLib3Imp SHARED testLib3Imp.c)
+set_property(TARGET testLib3Imp PROPERTY LIBRARY_OUTPUT_DIRECTORY impl)
+target_link_libraries(testLib3Imp testLib3ImpDep)
+add_library(testLib3 SHARED testLib3.c)
+target_link_libraries(testLib3 testLib3Imp)
+set_property(TARGET testLib3 PROPERTY LINK_INTERFACE_LIBRARIES "")
+set_property(TARGET testLib3 PROPERTY VERSION 1.2)
+set_property(TARGET testLib3 PROPERTY SOVERSION 3)
+
+# Test <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME[_<CONFIG>] properties.
+set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_DEBUG testLib3dll-d)
+set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME_RELEASE testLib3dll-r)
+set_property(TARGET testLib3 PROPERTY RUNTIME_OUTPUT_NAME testLib3dll)
+set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_DEBUG testLib3lib-d)
+set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME_RELEASE testLib3lib-r)
+set_property(TARGET testLib3 PROPERTY LIBRARY_OUTPUT_NAME testLib3lib)
+set_property(TARGET testLib3 PROPERTY ARCHIVE_OUTPUT_NAME testLib3import)
+
+add_library(testLib4 SHARED testLib4.c)
+set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)
+
+add_library(testLib5 SHARED testLib5.c)
+
+add_library(testLib6 STATIC testLib6.cxx testLib6c.c)
+
+# Work-around: Visual Studio 6 does not support per-target object files.
+set(VS6)
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+ set(VS6 1)
+endif("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
+
+# Test using the target_link_libraries command to set the
+# LINK_INTERFACE_LIBRARIES* properties. We construct two libraries
+# providing the same two symbols. In each library one of the symbols
+# will work and the other one will fail to link. The import part of
+# this test will try to use the symbol corresponding to the
+# configuration in which it is built. If the proper library is not
+# used via the link interface the import test will fail to link.
+add_library(testLib4lib STATIC testLib4lib.c)
+add_library(testLib4libdbg STATIC testLib4libopt.c testLib4libdbg${VS6}.c)
+add_library(testLib4libopt STATIC testLib4libdbg.c testLib4libopt${VS6}.c)
+set_property(TARGET testLib4libdbg PROPERTY COMPILE_DEFINITIONS LIB_DBG)
+set_property(TARGET testLib4libopt PROPERTY COMPILE_DEFINITIONS LIB_OPT)
+target_link_libraries(testLib4
+ LINK_INTERFACE_LIBRARIES
+ testLib4lib debug testLib4libdbg optimized testLib4libopt
+ )
+
+add_executable(testExe3 testExe3.c)
+set_property(TARGET testExe3 PROPERTY MACOSX_BUNDLE 1)
+
+# Test cyclic dependencies.
+add_library(testLibCycleA STATIC
+ testLibCycleA1.c testLibCycleA2.c testLibCycleA3.c)
+add_library(testLibCycleB STATIC
+ testLibCycleB1.c testLibCycleB2.c testLibCycleB3.c)
+target_link_libraries(testLibCycleA testLibCycleB)
+target_link_libraries(testLibCycleB testLibCycleA)
+set_property(TARGET testLibCycleA PROPERTY LINK_INTERFACE_MULTIPLICITY 3)
+
+# Install and export from install tree.
+install(
+ TARGETS
+ testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
+ testExe2lib testLib4lib testLib4libdbg testLib4libopt
+ testLib6
+ testLibCycleA testLibCycleB
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib NAMELINK_SKIP
+ ARCHIVE DESTINATION lib
+ FRAMEWORK DESTINATION Frameworks
+ BUNDLE DESTINATION Applications
+ )
+install(
+ TARGETS
+ testExe2libImp testLib3Imp
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib/impl
+ ARCHIVE DESTINATION lib/impl
+ )
+install(
+ TARGETS
+ testLib3ImpDep
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib/impl/dep
+ ARCHIVE DESTINATION lib/impl/dep
+ )
+install(
+ TARGETS testLib5
+ EXPORT exp
+ # Leave out RUNTIME DESTINATION to test implib-only export.
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ )
+install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
+
+# Install testLib5.dll outside the export.
+if(WIN32)
+ install(TARGETS testLib5 RUNTIME DESTINATION bin)
+endif(WIN32)
+
+# Export from build tree.
+export(TARGETS testExe1 testLib1 testLib2 testLib3
+ testExe2libImp testLib3Imp testLib3ImpDep
+ NAMESPACE bld_
+ FILE ExportBuildTree.cmake
+ )
+export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib
+ testLib4lib testLib4libdbg testLib4libopt
+ testLibCycleA testLibCycleB
+ NAMESPACE bld_
+ APPEND FILE ExportBuildTree.cmake
+ )
diff --git a/Tests/ExportImport/Export/testExe1.c b/Tests/ExportImport/Export/testExe1.c
new file mode 100644
index 000000000..e00fac74f
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe1.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+extern int testExe1lib(void);
+
+int main(int argc, const char* argv[])
+{
+ if(argc < 2)
+ {
+ fprintf(stderr, "Must specify output file.\n");
+ return 1;
+ }
+ {
+ FILE* f = fopen(argv[1], "w");
+ if(f)
+ {
+ fprintf(f, "int generated_by_testExe1() { return 0; }\n");
+ fclose(f);
+ }
+ else
+ {
+ fprintf(stderr, "Error writing to %s\n", argv[1]);
+ return 1;
+ }
+ }
+ return testExe1lib();
+}
diff --git a/Tests/ExportImport/Export/testExe1lib.c b/Tests/ExportImport/Export/testExe1lib.c
new file mode 100644
index 000000000..7ad48a392
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe1lib.c
@@ -0,0 +1 @@
+int testExe1lib(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testExe2.c b/Tests/ExportImport/Export/testExe2.c
new file mode 100644
index 000000000..f7d93453a
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe2.c
@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2_EXPORT __declspec(dllexport)
+#else
+# define testExe2_EXPORT
+#endif
+
+testExe2_EXPORT int testExe2Func(void) { return 123; }
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testExe2lib.c b/Tests/ExportImport/Export/testExe2lib.c
new file mode 100644
index 000000000..199143900
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe2lib.c
@@ -0,0 +1,10 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2lib_EXPORT __declspec(dllexport)
+# define testExe2libImp_IMPORT __declspec(dllimport)
+#else
+# define testExe2lib_EXPORT
+# define testExe2libImp_IMPORT
+#endif
+
+testExe2libImp_IMPORT int testExe2libImp(void);
+testExe2lib_EXPORT int testExe2lib(void) { return testExe2libImp(); }
diff --git a/Tests/ExportImport/Export/testExe2libImp.c b/Tests/ExportImport/Export/testExe2libImp.c
new file mode 100644
index 000000000..f5a23af55
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe2libImp.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2libImp_EXPORT __declspec(dllexport)
+#else
+# define testExe2libImp_EXPORT
+#endif
+
+testExe2libImp_EXPORT int testExe2libImp(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testExe3.c b/Tests/ExportImport/Export/testExe3.c
new file mode 100644
index 000000000..895e2fc2d
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe3.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int main(int argc, const char* argv[])
+{
+ if(argc < 2)
+ {
+ fprintf(stderr, "Must specify output file.\n");
+ return 1;
+ }
+ {
+ FILE* f = fopen(argv[1], "w");
+ if(f)
+ {
+ fprintf(f, "int generated_by_testExe3() { return 0; }\n");
+ fclose(f);
+ }
+ else
+ {
+ fprintf(stderr, "Error writing to %s\n", argv[1]);
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testLib1.c b/Tests/ExportImport/Export/testLib1.c
new file mode 100644
index 000000000..35bb1e5db
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib1.c
@@ -0,0 +1 @@
+int testLib1(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib2.c b/Tests/ExportImport/Export/testLib2.c
new file mode 100644
index 000000000..aabc0d30f
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib2.c
@@ -0,0 +1,4 @@
+
+extern int testLib1(void);
+
+int testLib2(void) { return testLib1(); }
diff --git a/Tests/ExportImport/Export/testLib3.c b/Tests/ExportImport/Export/testLib3.c
new file mode 100644
index 000000000..31cec9435
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3.c
@@ -0,0 +1,10 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3_EXPORT __declspec(dllexport)
+# define testLib3Imp_IMPORT __declspec(dllimport)
+#else
+# define testLib3_EXPORT
+# define testLib3Imp_IMPORT
+#endif
+
+testLib3Imp_IMPORT int testLib3Imp(void);
+testLib3_EXPORT int testLib3(void) { return testLib3Imp(); }
diff --git a/Tests/ExportImport/Export/testLib3Imp.c b/Tests/ExportImport/Export/testLib3Imp.c
new file mode 100644
index 000000000..c27bccd40
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3Imp.c
@@ -0,0 +1,10 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3Imp_EXPORT __declspec(dllexport)
+# define testLib3ImpDep_IMPORT __declspec(dllimport)
+#else
+# define testLib3Imp_EXPORT
+# define testLib3ImpDep_IMPORT
+#endif
+
+testLib3ImpDep_IMPORT int testLib3ImpDep(void);
+testLib3Imp_EXPORT int testLib3Imp(void) { return testLib3ImpDep(); }
diff --git a/Tests/ExportImport/Export/testLib3ImpDep.c b/Tests/ExportImport/Export/testLib3ImpDep.c
new file mode 100644
index 000000000..578ac30ef
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3ImpDep.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3ImpDep_EXPORT __declspec(dllexport)
+#else
+# define testLib3ImpDep_EXPORT
+#endif
+
+testLib3ImpDep_EXPORT int testLib3ImpDep(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib4.c b/Tests/ExportImport/Export/testLib4.c
new file mode 100644
index 000000000..846b4389b
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib4_EXPORT __declspec(dllexport)
+#else
+# define testLib4_EXPORT
+#endif
+
+testLib4_EXPORT int testLib4(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib4lib.c b/Tests/ExportImport/Export/testLib4lib.c
new file mode 100644
index 000000000..bf3c11ec6
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4lib.c
@@ -0,0 +1,4 @@
+int testLib4lib(void)
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testLib4libdbg.c b/Tests/ExportImport/Export/testLib4libdbg.c
new file mode 100644
index 000000000..453f26282
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libdbg.c
@@ -0,0 +1,14 @@
+#ifdef LIB_DBG
+/* We are building in testLib4libdbg. Provide the correct symbol. */
+int testLib4libdbg(void)
+{
+ return 0;
+}
+#else
+/* We are not building in testLib4libdbg. Poison the symbol. */
+extern int testLib4libdbg_noexist(void);
+int testLib4libdbg(void)
+{
+ return testLib4libdbg_noexist();
+}
+#endif
diff --git a/Tests/ExportImport/Export/testLib4libdbg1.c b/Tests/ExportImport/Export/testLib4libdbg1.c
new file mode 100644
index 000000000..cc56cf933
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libdbg1.c
@@ -0,0 +1 @@
+#include "testLib4libdbg.c"
diff --git a/Tests/ExportImport/Export/testLib4libopt.c b/Tests/ExportImport/Export/testLib4libopt.c
new file mode 100644
index 000000000..605edd05b
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libopt.c
@@ -0,0 +1,14 @@
+#ifdef LIB_OPT
+/* We are building in testLib4libopt. Provide the correct symbol. */
+int testLib4libopt(void)
+{
+ return 0;
+}
+#else
+/* We are not building in testLib4libopt. Poison the symbol. */
+extern int testLib4libopt_noexist(void);
+int testLib4libopt(void)
+{
+ return testLib4libopt_noexist();
+}
+#endif
diff --git a/Tests/ExportImport/Export/testLib4libopt1.c b/Tests/ExportImport/Export/testLib4libopt1.c
new file mode 100644
index 000000000..d9b55879d
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib4libopt1.c
@@ -0,0 +1 @@
+#include "testLib4libopt.c"
diff --git a/Tests/ExportImport/Export/testLib5.c b/Tests/ExportImport/Export/testLib5.c
new file mode 100644
index 000000000..20a821513
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib5.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib5_EXPORT __declspec(dllexport)
+#else
+# define testLib5_EXPORT
+#endif
+
+testLib5_EXPORT int testLib5(void) { return 0; }
diff --git a/Tests/ExportImport/Export/testLib6.cxx b/Tests/ExportImport/Export/testLib6.cxx
new file mode 100644
index 000000000..338e6399a
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib6.cxx
@@ -0,0 +1,6 @@
+extern "C" int testLib6cxx(void)
+{
+ // Reference C++ standard library symbols.
+ delete new int;
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/testLib6c.c b/Tests/ExportImport/Export/testLib6c.c
new file mode 100644
index 000000000..493ca070e
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib6c.c
@@ -0,0 +1,5 @@
+extern int testLib6cxx(void);
+int testLib6(void)
+{
+ return testLib6cxx();
+}
diff --git a/Tests/ExportImport/Export/testLibCycleA1.c b/Tests/ExportImport/Export/testLibCycleA1.c
new file mode 100644
index 000000000..3db9e5356
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleA1.c
@@ -0,0 +1,2 @@
+extern int testLibCycleB1(void);
+int testLibCycleA1(void) { return testLibCycleB1(); }
diff --git a/Tests/ExportImport/Export/testLibCycleA2.c b/Tests/ExportImport/Export/testLibCycleA2.c
new file mode 100644
index 000000000..29ad46d4e
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleA2.c
@@ -0,0 +1,2 @@
+extern int testLibCycleB2(void);
+int testLibCycleA2(void) { return testLibCycleB2(); }
diff --git a/Tests/ExportImport/Export/testLibCycleA3.c b/Tests/ExportImport/Export/testLibCycleA3.c
new file mode 100644
index 000000000..565447b21
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleA3.c
@@ -0,0 +1,2 @@
+extern int testLibCycleB3(void);
+int testLibCycleA3(void) { return testLibCycleB3(); }
diff --git a/Tests/ExportImport/Export/testLibCycleB1.c b/Tests/ExportImport/Export/testLibCycleB1.c
new file mode 100644
index 000000000..36cb7b0e9
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleB1.c
@@ -0,0 +1,2 @@
+extern int testLibCycleA2(void);
+int testLibCycleB1(void) { return testLibCycleA2(); }
diff --git a/Tests/ExportImport/Export/testLibCycleB2.c b/Tests/ExportImport/Export/testLibCycleB2.c
new file mode 100644
index 000000000..ff1209302
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleB2.c
@@ -0,0 +1,2 @@
+extern int testLibCycleA3(void);
+int testLibCycleB2(void) { return testLibCycleA3(); }
diff --git a/Tests/ExportImport/Export/testLibCycleB3.c b/Tests/ExportImport/Export/testLibCycleB3.c
new file mode 100644
index 000000000..ca8d47005
--- /dev/null
+++ b/Tests/ExportImport/Export/testLibCycleB3.c
@@ -0,0 +1 @@
+int testLibCycleB3(void) { return 0; }
diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt
new file mode 100644
index 000000000..a21e1b0f8
--- /dev/null
+++ b/Tests/ExportImport/Import/A/CMakeLists.txt
@@ -0,0 +1,150 @@
+# Import targets from the exported build tree.
+include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake)
+
+# Import targets from the exported install tree.
+include(${CMAKE_INSTALL_PREFIX}/lib/exp/exp.cmake)
+
+# Try referencing an executable imported from the install tree.
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/exp_generated.c
+ COMMAND exp_testExe1 ${Import_BINARY_DIR}/exp_generated.c
+ DEPENDS exp_testExe1
+ )
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/exp_generated3.c
+ COMMAND exp_testExe3 ${Import_BINARY_DIR}/exp_generated3.c
+ DEPENDS exp_testExe3
+ )
+
+add_executable(imp_testExe1
+ imp_testExe1.c
+ ${Import_BINARY_DIR}/exp_generated.c
+ ${Import_BINARY_DIR}/exp_generated3.c
+ )
+
+# Try linking to a library imported from the install tree.
+target_link_libraries(imp_testExe1
+ exp_testLib2
+ exp_testLib3
+ exp_testLib4
+ exp_testLib5
+ exp_testLib6
+ exp_testLibCycleA
+ )
+
+# Try building a plugin to an executable imported from the install tree.
+add_library(imp_mod1 MODULE imp_mod1.c)
+target_link_libraries(imp_mod1 exp_testExe2)
+
+# Try referencing an executable imported from the build tree.
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/bld_generated.c
+ COMMAND bld_testExe1 ${Import_BINARY_DIR}/bld_generated.c
+ DEPENDS bld_testExe1
+ )
+add_custom_command(
+ OUTPUT ${Import_BINARY_DIR}/bld_generated3.c
+ COMMAND bld_testExe3 ${Import_BINARY_DIR}/bld_generated3.c
+ DEPENDS bld_testExe3
+ )
+
+add_executable(imp_testExe1b
+ imp_testExe1.c
+ ${Import_BINARY_DIR}/bld_generated.c
+ ${Import_BINARY_DIR}/bld_generated3.c
+ )
+
+# Try linking to a library imported from the build tree.
+target_link_libraries(imp_testExe1b
+ bld_testLib2
+ bld_testLib3
+ bld_testLib4
+ bld_testLib5
+ bld_testLib6
+ bld_testLibCycleA
+ )
+
+# Try building a plugin to an executable imported from the build tree.
+add_library(imp_mod1b MODULE imp_mod1.c)
+target_link_libraries(imp_mod1b bld_testExe2)
+
+# Export/CMakeLists.txt pretends the RelWithDebInfo (as well as Debug)
+# configuration should link to debug libs.
+foreach(c DEBUG RELWITHDEBINFO)
+ set_property(TARGET imp_testExe1 PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
+ set_property(TARGET imp_testExe1b PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
+endforeach(c)
+
+#-----------------------------------------------------------------------------
+# Create a custom target to generate a header for the libraries below.
+# Drive the header generation through an indirect chain of imported
+# target dependencies.
+
+# testLib2tmp1.h
+add_custom_command(
+ OUTPUT testLib2tmp1.h
+ VERBATIM COMMAND
+ ${CMAKE_COMMAND} -E echo "extern int testLib2(void);" > testLib2tmp1.h
+ )
+
+# hdr_testLib2tmp1 needs testLib2tmp1.h
+add_custom_target(hdr_testLib2tmp1 DEPENDS testLib2tmp1.h)
+
+# exp_testExe2 needs hdr_testLib2tmp1
+add_dependencies(exp_testExe2 hdr_testLib2tmp1)
+
+# testLib2tmp.h needs exp_testExe2
+add_custom_command(
+ OUTPUT testLib2tmp.h
+ VERBATIM COMMAND exp_testExe2
+ COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp1.h testLib2tmp.h
+ )
+
+# hdr_testLib2tmp needs testLib2tmp.h
+add_custom_target(hdr_testLib2tmp DEPENDS testLib2tmp.h)
+
+add_library(dep_testLib2tmp UNKNOWN IMPORTED)
+set_property(TARGET dep_testLib2tmp PROPERTY
+ IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/testLib2tmp.h)
+
+# dep_testLib2tmp needs hdr_testLib2tmp
+add_dependencies(dep_testLib2tmp hdr_testLib2tmp)
+
+# testLib2.h needs dep_testLib2tmp
+add_custom_command(
+ OUTPUT testLib2.h
+ VERBATIM COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp.h testLib2.h
+ DEPENDS dep_testLib2tmp
+ )
+
+# hdr_testLib2 needs testLib2.h
+add_custom_target(hdr_testLib2 DEPENDS testLib2.h)
+
+add_library(dep_testLib2 UNKNOWN IMPORTED)
+
+# dep_testLib2 needs hdr_testLib2
+add_dependencies(dep_testLib2 hdr_testLib2)
+
+# exp_testLib2 and bld_testLib2 both need dep_testLib2
+add_dependencies(bld_testLib2 dep_testLib2)
+add_dependencies(exp_testLib2 dep_testLib2)
+
+#-----------------------------------------------------------------------------
+# Create a library to be linked by another directory in this project
+# to test transitive linking to otherwise invisible imported targets.
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_library(imp_lib1 STATIC imp_lib1.c)
+target_link_libraries(imp_lib1 exp_testLib2)
+add_library(imp_lib1b STATIC imp_lib1.c)
+target_link_libraries(imp_lib1b bld_testLib2)
+
+#-----------------------------------------------------------------------------
+# Test that handling imported targets, including transitive dependencies,
+# works in CheckFunctionExists (...and hopefully all other try_compile() checks
+include(CheckFunctionExists)
+unset(HAVE_TESTLIB1_FUNCTION CACHE)
+set(CMAKE_REQUIRED_LIBRARIES exp_testLib2)
+check_function_exists(testLib1 HAVE_TESTLIB1_FUNCTION)
+if (NOT HAVE_TESTLIB1_FUNCTION)
+ message(SEND_ERROR "Using imported target testLib2 in check_function_exists() failed !")
+endif()
diff --git a/Tests/ExportImport/Import/A/imp_lib1.c b/Tests/ExportImport/Import/A/imp_lib1.c
new file mode 100644
index 000000000..5b3215e99
--- /dev/null
+++ b/Tests/ExportImport/Import/A/imp_lib1.c
@@ -0,0 +1,6 @@
+#include "testLib2.h"
+
+int imp_lib1(void)
+{
+ return testLib2();
+}
diff --git a/Tests/ExportImport/Import/A/imp_mod1.c b/Tests/ExportImport/Import/A/imp_mod1.c
new file mode 100644
index 000000000..579d949c3
--- /dev/null
+++ b/Tests/ExportImport/Import/A/imp_mod1.c
@@ -0,0 +1,13 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2_IMPORT __declspec(dllimport)
+#else
+# define testExe2_IMPORT
+#endif
+
+testExe2_IMPORT int testExe2Func(void);
+testExe2_IMPORT int testExe2lib(void);
+
+int imp_mod1()
+{
+ return testExe2Func() + testExe2lib();
+}
diff --git a/Tests/ExportImport/Import/A/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c
new file mode 100644
index 000000000..451998ab7
--- /dev/null
+++ b/Tests/ExportImport/Import/A/imp_testExe1.c
@@ -0,0 +1,25 @@
+extern int generated_by_testExe1();
+extern int generated_by_testExe3();
+extern int testLib2();
+extern int testLib3();
+extern int testLib4();
+extern int testLib4lib();
+extern int testLib5();
+extern int testLib6();
+extern int testLibCycleA1();
+
+/* Switch a symbol between debug and optimized builds to make sure the
+ proper library is found from the testLib4 link interface. */
+#ifdef EXE_DBG
+# define testLib4libcfg testLib4libdbg
+#else
+# define testLib4libcfg testLib4libopt
+#endif
+extern testLib4libcfg(void);
+
+int main()
+{
+ return (testLib2() + generated_by_testExe1() + testLib3() + testLib4()
+ + testLib5() + testLib6() + testLibCycleA1()
+ + generated_by_testExe3() + testLib4lib() + testLib4libcfg());
+}
diff --git a/Tests/ExportImport/Import/CMakeLists.txt b/Tests/ExportImport/Import/CMakeLists.txt
new file mode 100644
index 000000000..3fc78a280
--- /dev/null
+++ b/Tests/ExportImport/Import/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required (VERSION 2.7.20090711)
+project(Import C CXX)
+
+# Import everything in a subdirectory.
+add_subdirectory(A)
+
+# Make sure the imported targets are scoped inside the subdirectory.
+if(TARGET exp_testLib2)
+ message(FATAL_ERROR "Imported target exp_testLib2 is not scoped in subdir!")
+endif()
+if(TARGET bld_testLib2)
+ message(FATAL_ERROR "Imported target bld_testLib2 is not scoped in subdir!")
+endif()
+
+# Test transitive linking to a target imported in the subdirectory.
+add_executable(imp_testTransExe1 imp_testTransExe1.c)
+target_link_libraries(imp_testTransExe1 imp_lib1)
+add_executable(imp_testTransExe1b imp_testTransExe1.c)
+target_link_libraries(imp_testTransExe1b imp_lib1b)
diff --git a/Tests/ExportImport/Import/imp_testTransExe1.c b/Tests/ExportImport/Import/imp_testTransExe1.c
new file mode 100644
index 000000000..360a112ac
--- /dev/null
+++ b/Tests/ExportImport/Import/imp_testTransExe1.c
@@ -0,0 +1,6 @@
+extern int imp_lib1(void);
+
+int main()
+{
+ return imp_lib1();
+}
diff --git a/Tests/ExportImport/InitialCache.cmake.in b/Tests/ExportImport/InitialCache.cmake.in
new file mode 100644
index 000000000..4893f7020
--- /dev/null
+++ b/Tests/ExportImport/InitialCache.cmake.in
@@ -0,0 +1,15 @@
+SET(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@" CACHE STRING "C Compiler")
+SET(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@" CACHE STRING "C Flags")
+SET(CMAKE_C_FLAGS_DEBUG "@CMAKE_C_FLAGS_DEBUG@" CACHE STRING "C Flags")
+SET(CMAKE_C_FLAGS_RELEASE "@CMAKE_C_FLAGS_RELEASE@" CACHE STRING "C Flags")
+SET(CMAKE_C_FLAGS_MINSIZEREL "@CMAKE_C_FLAGS_MINSIZEREL@" CACHE STRING "C Flags")
+SET(CMAKE_C_FLAGS_RELWITHDEBINFO "@CMAKE_C_FLAGS_RELWITHDEBINFO@" CACHE STRING "C Flags")
+SET(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@" CACHE STRING "C++ Compiler")
+SET(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@" CACHE STRING "C++ Flags")
+SET(CMAKE_CXX_FLAGS_DEBUG "@CMAKE_CXX_FLAGS_DEBUG@" CACHE STRING "C++ Flags")
+SET(CMAKE_CXX_FLAGS_RELEASE "@CMAKE_CXX_FLAGS_RELEASE@" CACHE STRING "C++ Flags")
+SET(CMAKE_CXX_FLAGS_MINSIZEREL "@CMAKE_CXX_FLAGS_MINSIZEREL@" CACHE STRING "C++ Flags")
+SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "@CMAKE_CXX_FLAGS_RELWITHDEBINFO@" CACHE STRING "C++ Flags")
+SET(CMAKE_INSTALL_PREFIX "@ExportImport_BINARY_DIR@/Root" CACHE STRING "Installation Prefix")
+SET(CMAKE_SKIP_RPATH ON CACHE BOOL "No RPATH")
+SET(CMAKE_GNUtoMS "@ExportImport_GNUtoMS@" CACHE BOOL "CMAKE_GNUtoMS")
diff --git a/Tests/ExportImport/main.c b/Tests/ExportImport/main.c
new file mode 100644
index 000000000..f8b643afb
--- /dev/null
+++ b/Tests/ExportImport/main.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}