From 556b1257ac5e961a5fbc652f51acf157f157bed8 Mon Sep 17 00:00:00 2001
From: Alexander Neundorf <neundorf@kde.org>
Date: Mon, 27 Aug 2007 15:15:26 -0400
Subject: COMP: add a test for exporting and importing targets

Alex
---
 Tests/SimpleInstall/CMakeLists.txt   | 18 +++++++++++++++++-
 Tests/SimpleInstallS2/CMakeLists.txt | 18 +++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/Tests/SimpleInstall/CMakeLists.txt b/Tests/SimpleInstall/CMakeLists.txt
index bb1634f..2dc1412 100644
--- a/Tests/SimpleInstall/CMakeLists.txt
+++ b/Tests/SimpleInstall/CMakeLists.txt
@@ -134,6 +134,15 @@ IF(STAGE2)
     INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
 
   INSTALL_TARGETS(/MyTest/bin SimpleInstallS2)
+
+# try to import the exported targets again
+  SET(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+  FIND_PACKAGE(SimpleInstallS1 REQUIRED)
+  GET_TARGET_PROPERTY(simpleInstallLocation S1_SimpleInstall LOCATION)
+  IF(NOT simpleInstallLocation)
+    MESSAGE(FATAL_ERROR "Target S1_SimpleInstall could not be imported, location: ${simpleInstallLocation}")
+  ENDIF(NOT simpleInstallLocation)
+
 ELSE(STAGE2)
   # Wipe out the install directory to do a fresh test.
   FILE(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
@@ -164,11 +173,12 @@ ELSE(STAGE2)
   ADD_DEPENDENCIES(test2 test3)
   ADD_DEPENDENCIES(test4 test2)
 
-  INSTALL(TARGETS SimpleInstall test1 test2 test3
+  INSTALL(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
     RUNTIME DESTINATION MyTest/bin        COMPONENT Runtime     # .exe, .dll
     LIBRARY DESTINATION MyTest/lib        COMPONENT Runtime     # .so, mod.dll
     ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
     )
+
   INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
     RUNTIME DESTINATION MyTest/bin
     LIBRARY DESTINATION MyTest/lib
@@ -191,6 +201,12 @@ ELSE(STAGE2)
     scripts/sample_script scripts/sample_script.bat)
   INSTALL_PROGRAMS(/MyTest/share/old2
     scripts/sample_script scripts/sample_script.bat)
+
+# "export" the targets collected in "SimpleInstallS1"
+  INSTALL(EXPORT SimpleInstallS1 FILENAME SimpleInstallS1Config.cmake 
+                                 DESTINATION MyTest/lib 
+                                 PREFIX S1_ )
+
   ADD_SUBDIRECTORY(scripts)
 
   # Test optional installation.
diff --git a/Tests/SimpleInstallS2/CMakeLists.txt b/Tests/SimpleInstallS2/CMakeLists.txt
index bb1634f..2dc1412 100644
--- a/Tests/SimpleInstallS2/CMakeLists.txt
+++ b/Tests/SimpleInstallS2/CMakeLists.txt
@@ -134,6 +134,15 @@ IF(STAGE2)
     INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
 
   INSTALL_TARGETS(/MyTest/bin SimpleInstallS2)
+
+# try to import the exported targets again
+  SET(SimpleInstallS1_DIR ${CMAKE_INSTALL_PREFIX}/MyTest/lib)
+  FIND_PACKAGE(SimpleInstallS1 REQUIRED)
+  GET_TARGET_PROPERTY(simpleInstallLocation S1_SimpleInstall LOCATION)
+  IF(NOT simpleInstallLocation)
+    MESSAGE(FATAL_ERROR "Target S1_SimpleInstall could not be imported, location: ${simpleInstallLocation}")
+  ENDIF(NOT simpleInstallLocation)
+
 ELSE(STAGE2)
   # Wipe out the install directory to do a fresh test.
   FILE(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/MyTest)
@@ -164,11 +173,12 @@ ELSE(STAGE2)
   ADD_DEPENDENCIES(test2 test3)
   ADD_DEPENDENCIES(test4 test2)
 
-  INSTALL(TARGETS SimpleInstall test1 test2 test3
+  INSTALL(TARGETS SimpleInstall test1 test2 test3 EXPORT SimpleInstallS1
     RUNTIME DESTINATION MyTest/bin        COMPONENT Runtime     # .exe, .dll
     LIBRARY DESTINATION MyTest/lib        COMPONENT Runtime     # .so, mod.dll
     ARCHIVE DESTINATION MyTest/lib/static COMPONENT Development # .a, .lib
     )
+
   INSTALL(TARGETS test4 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
     RUNTIME DESTINATION MyTest/bin
     LIBRARY DESTINATION MyTest/lib
@@ -191,6 +201,12 @@ ELSE(STAGE2)
     scripts/sample_script scripts/sample_script.bat)
   INSTALL_PROGRAMS(/MyTest/share/old2
     scripts/sample_script scripts/sample_script.bat)
+
+# "export" the targets collected in "SimpleInstallS1"
+  INSTALL(EXPORT SimpleInstallS1 FILENAME SimpleInstallS1Config.cmake 
+                                 DESTINATION MyTest/lib 
+                                 PREFIX S1_ )
+
   ADD_SUBDIRECTORY(scripts)
 
   # Test optional installation.
-- 
cgit v0.12