From d6bdaf9f1371a4c5a4e88dff89855aee47e49096 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 6 Apr 2009 11:11:33 -0400 Subject: [PATCH] ENH: Test transitive link to subdir-imported lib This tests linking to an imported target that is not visible but is a transitive dependency of a target that is visible. See issue #8843. --- Tests/ExportImport/Import/A/CMakeLists.txt | 69 +++++++++++++++++ Tests/ExportImport/Import/A/imp_lib1.c | 6 ++ Tests/ExportImport/Import/{ => A}/imp_mod1.c | 0 .../Import/{ => A}/imp_testExe1.c | 0 Tests/ExportImport/Import/CMakeLists.txt | 74 ++++--------------- Tests/ExportImport/Import/imp_testTransExe1.c | 6 ++ 6 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 Tests/ExportImport/Import/A/CMakeLists.txt create mode 100644 Tests/ExportImport/Import/A/imp_lib1.c rename Tests/ExportImport/Import/{ => A}/imp_mod1.c (100%) rename Tests/ExportImport/Import/{ => A}/imp_testExe1.c (100%) create mode 100644 Tests/ExportImport/Import/imp_testTransExe1.c diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt new file mode 100644 index 000000000..16cff2df2 --- /dev/null +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -0,0 +1,69 @@ +# 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) + +# 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) + +# 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 library to be linked by another directory in this project +# to test transitive linking to otherwise invisible imported targets. +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) diff --git a/Tests/ExportImport/Import/A/imp_lib1.c b/Tests/ExportImport/Import/A/imp_lib1.c new file mode 100644 index 000000000..d8c66e63f --- /dev/null +++ b/Tests/ExportImport/Import/A/imp_lib1.c @@ -0,0 +1,6 @@ +extern int testLib2(void); + +int imp_lib1(void) +{ + return testLib2(); +} diff --git a/Tests/ExportImport/Import/imp_mod1.c b/Tests/ExportImport/Import/A/imp_mod1.c similarity index 100% rename from Tests/ExportImport/Import/imp_mod1.c rename to Tests/ExportImport/Import/A/imp_mod1.c diff --git a/Tests/ExportImport/Import/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c similarity index 100% rename from Tests/ExportImport/Import/imp_testExe1.c rename to Tests/ExportImport/Import/A/imp_testExe1.c diff --git a/Tests/ExportImport/Import/CMakeLists.txt b/Tests/ExportImport/Import/CMakeLists.txt index 27f291028..00bf3063d 100644 --- a/Tests/ExportImport/Import/CMakeLists.txt +++ b/Tests/ExportImport/Import/CMakeLists.txt @@ -6,65 +6,19 @@ 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 everything in a subdirectory. +add_subdirectory(A) -# Import targets from the exported install tree. -include(${CMAKE_INSTALL_PREFIX}/lib/exp/exp.cmake) +# 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() -# 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) - -# 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) - -# 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) +# 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(); +}