summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-01-28 13:40:21 (GMT)
committerBrad King <brad.king@kitware.com>2008-01-28 13:40:21 (GMT)
commit976b426b2d72f2987b5591bee241f9e2752437f5 (patch)
tree78d58dfc762fc79235f826297f15897db5c5fa29
parent1332b557941e461b6651efdda895f55a778dd644 (diff)
downloadCMake-976b426b2d72f2987b5591bee241f9e2752437f5.zip
CMake-976b426b2d72f2987b5591bee241f9e2752437f5.tar.gz
CMake-976b426b2d72f2987b5591bee241f9e2752437f5.tar.bz2
ENH: Added ExportImport test to test new export/import features.
-rw-r--r--Tests/CMakeLists.txt1
-rw-r--r--Tests/ExportImport/CMakeLists.txt68
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt33
-rw-r--r--Tests/ExportImport/Export/testExe1.c24
-rw-r--r--Tests/ExportImport/Export/testExe2.c12
-rw-r--r--Tests/ExportImport/Export/testLib1.c1
-rw-r--r--Tests/ExportImport/Export/testLib2.c4
-rw-r--r--Tests/ExportImport/Export/testLib3.c7
-rw-r--r--Tests/ExportImport/Import/CMakeLists.txt50
-rw-r--r--Tests/ExportImport/Import/imp_mod1.c12
-rw-r--r--Tests/ExportImport/Import/imp_testExe1.c8
-rw-r--r--Tests/ExportImport/main.c4
12 files changed, 224 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index d4281ff..09c62e1 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -51,6 +51,7 @@ IF(BUILD_TESTING)
ADD_TEST_MACRO(Assembler HelloAsm)
ADD_TEST_MACRO(SourceGroups SourceGroups)
ADD_TEST_MACRO(Preprocess Preprocess)
+ ADD_TEST_MACRO(ExportImport ExportImport)
IF (CMAKE_STRICT)
ADD_TEST_MACRO(DocTest DocTest)
diff --git a/Tests/ExportImport/CMakeLists.txt b/Tests/ExportImport/CMakeLists.txt
new file mode 100644
index 0000000..53012ae
--- /dev/null
+++ b/Tests/ExportImport/CMakeLists.txt
@@ -0,0 +1,68 @@
+project(ExportImport C)
+
+# 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)
+
+# Build and install the exporter.
+if(CMAKE_CONFIGURATION_TYPES)
+ set(Export_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+else(CMAKE_CONFIGURATION_TYPES)
+ set(Export_CONFIG_TYPE)
+endif(CMAKE_CONFIGURATION_TYPES)
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/ExportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${Export_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
+ -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
+ -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
+ -DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
+ -DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
+ -DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
+ -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
+ -DCMAKE_INSTALL_PREFIX=${ExportImport_BINARY_DIR}/Root
+ )
+add_custom_target(ExportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ExportProject)
+add_dependencies(ExportTarget CleanupTarget)
+
+# Build and install the importer.
+if(CMAKE_CONFIGURATION_TYPES)
+ set(Import_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
+else(CMAKE_CONFIGURATION_TYPES)
+ set(Import_CONFIG_TYPE)
+endif(CMAKE_CONFIGURATION_TYPES)
+add_custom_command(
+ OUTPUT ${ExportImport_BINARY_DIR}/ImportProject
+ COMMAND ${CMAKE_CTEST_COMMAND} ${Import_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
+ -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
+ -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
+ -DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
+ -DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
+ -DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
+ -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
+ -DCMAKE_INSTALL_PREFIX=${ExportImport_BINARY_DIR}/Root
+ )
+add_custom_target(ImportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ImportProject)
+add_dependencies(ImportTarget ExportTarget)
+
+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 0000000..eef146a
--- /dev/null
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -0,0 +1,33 @@
+project(Export C)
+
+# We need ansi C support.
+if(CMAKE_ANSI_CFLAGS)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
+endif(CMAKE_ANSI_CFLAGS)
+
+add_executable(testExe1 testExe1.c)
+
+add_executable(testExe2 testExe2.c)
+set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
+
+add_library(testLib1 STATIC testLib1.c)
+add_library(testLib2 STATIC testLib2.c)
+target_link_libraries(testLib2 testLib1)
+
+add_library(testLib3 SHARED testLib3.c)
+
+# Install and export from install tree.
+install(
+ TARGETS testExe1 testLib1 testLib2 testExe2 testLib3
+ EXPORT exp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ )
+install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
+
+# Export from build tree.
+export(TARGETS testExe1 testLib1 testLib2 testExe2 testLib3
+ NAMESPACE bld_
+ FILE ExportBuildTree.cmake
+ )
diff --git a/Tests/ExportImport/Export/testExe1.c b/Tests/ExportImport/Export/testExe1.c
new file mode 100644
index 0000000..39177d0
--- /dev/null
+++ b/Tests/ExportImport/Export/testExe1.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_testExe1() { 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/testExe2.c b/Tests/ExportImport/Export/testExe2.c
new file mode 100644
index 0000000..f7d9345
--- /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/testLib1.c b/Tests/ExportImport/Export/testLib1.c
new file mode 100644
index 0000000..5491bf9
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib1.c
@@ -0,0 +1 @@
+int testLib1() { return 0; }
diff --git a/Tests/ExportImport/Export/testLib2.c b/Tests/ExportImport/Export/testLib2.c
new file mode 100644
index 0000000..5feb83d
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib2.c
@@ -0,0 +1,4 @@
+
+extern int testLib1();
+
+int testLib2() { return testLib1(); }
diff --git a/Tests/ExportImport/Export/testLib3.c b/Tests/ExportImport/Export/testLib3.c
new file mode 100644
index 0000000..bfff187
--- /dev/null
+++ b/Tests/ExportImport/Export/testLib3.c
@@ -0,0 +1,7 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testLib3_EXPORT __declspec(dllexport)
+#else
+# define testLib3_EXPORT
+#endif
+
+testLib3_EXPORT int testLib3(void) { return 0; }
diff --git a/Tests/ExportImport/Import/CMakeLists.txt b/Tests/ExportImport/Import/CMakeLists.txt
new file mode 100644
index 0000000..4c19819
--- /dev/null
+++ b/Tests/ExportImport/Import/CMakeLists.txt
@@ -0,0 +1,50 @@
+project(Import C)
+
+# We need ansi C support.
+if(CMAKE_ANSI_CFLAGS)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
+endif(CMAKE_ANSI_CFLAGS)
+
+# 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_executable(imp_testExe1
+ imp_testExe1.c
+ ${Import_BINARY_DIR}/exp_generated.c
+ )
+
+# Try linking to a library imported from the install tree.
+target_link_libraries(imp_testExe1 exp_testLib2 exp_testLib3)
+
+# 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_executable(imp_testExe1b
+ imp_testExe1.c
+ ${Import_BINARY_DIR}/bld_generated.c
+ )
+
+# Try linking to a library imported from the build tree.
+target_link_libraries(imp_testExe1b bld_testLib2 bld_testLib3)
+
+# 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)
diff --git a/Tests/ExportImport/Import/imp_mod1.c b/Tests/ExportImport/Import/imp_mod1.c
new file mode 100644
index 0000000..d276631
--- /dev/null
+++ b/Tests/ExportImport/Import/imp_mod1.c
@@ -0,0 +1,12 @@
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define testExe2_IMPORT __declspec(dllimport)
+#else
+# define testExe2_IMPORT
+#endif
+
+testExe2_IMPORT int testExe2Func(void);
+
+int imp_mod1()
+{
+ return testExe2Func();
+}
diff --git a/Tests/ExportImport/Import/imp_testExe1.c b/Tests/ExportImport/Import/imp_testExe1.c
new file mode 100644
index 0000000..da51ddc
--- /dev/null
+++ b/Tests/ExportImport/Import/imp_testExe1.c
@@ -0,0 +1,8 @@
+extern int generated_by_testExe1();
+extern int testLib2();
+extern int testLib3();
+
+int main()
+{
+ return testLib2() + generated_by_testExe1() + testLib3();
+}
diff --git a/Tests/ExportImport/main.c b/Tests/ExportImport/main.c
new file mode 100644
index 0000000..f8b643a
--- /dev/null
+++ b/Tests/ExportImport/main.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}