From 976b426b2d72f2987b5591bee241f9e2752437f5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 28 Jan 2008 08:40:21 -0500 Subject: [PATCH] ENH: Added ExportImport test to test new export/import features. --- Tests/CMakeLists.txt | 1 + Tests/ExportImport/CMakeLists.txt | 68 ++++++++++++++++++++++++ Tests/ExportImport/Export/CMakeLists.txt | 33 ++++++++++++ Tests/ExportImport/Export/testExe1.c | 24 +++++++++ Tests/ExportImport/Export/testExe2.c | 12 +++++ Tests/ExportImport/Export/testLib1.c | 1 + Tests/ExportImport/Export/testLib2.c | 4 ++ Tests/ExportImport/Export/testLib3.c | 7 +++ Tests/ExportImport/Import/CMakeLists.txt | 50 +++++++++++++++++ Tests/ExportImport/Import/imp_mod1.c | 12 +++++ Tests/ExportImport/Import/imp_testExe1.c | 8 +++ Tests/ExportImport/main.c | 4 ++ 12 files changed, 224 insertions(+) create mode 100644 Tests/ExportImport/CMakeLists.txt create mode 100644 Tests/ExportImport/Export/CMakeLists.txt create mode 100644 Tests/ExportImport/Export/testExe1.c create mode 100644 Tests/ExportImport/Export/testExe2.c create mode 100644 Tests/ExportImport/Export/testLib1.c create mode 100644 Tests/ExportImport/Export/testLib2.c create mode 100644 Tests/ExportImport/Export/testLib3.c create mode 100644 Tests/ExportImport/Import/CMakeLists.txt create mode 100644 Tests/ExportImport/Import/imp_mod1.c create mode 100644 Tests/ExportImport/Import/imp_testExe1.c create mode 100644 Tests/ExportImport/main.c diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index d4281ffca..09c62e172 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 000000000..53012aea3 --- /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 000000000..eef146ac8 --- /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 000000000..39177d02b --- /dev/null +++ b/Tests/ExportImport/Export/testExe1.c @@ -0,0 +1,24 @@ +#include + +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 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/testLib1.c b/Tests/ExportImport/Export/testLib1.c new file mode 100644 index 000000000..5491bf960 --- /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 000000000..5feb83daf --- /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 000000000..bfff187d3 --- /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 000000000..4c198190d --- /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 000000000..d276631c6 --- /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 000000000..da51ddc61 --- /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 000000000..f8b643afb --- /dev/null +++ b/Tests/ExportImport/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +}