summaryrefslogtreecommitdiff
path: root/Tests/BundleTest
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/BundleTest')
-rw-r--r--Tests/BundleTest/BundleLib.cxx70
-rw-r--r--Tests/BundleTest/BundleSubDir/CMakeLists.txt36
-rw-r--r--Tests/BundleTest/BundleTest.cxx20
-rw-r--r--Tests/BundleTest/CMakeLists.txt104
-rw-r--r--Tests/BundleTest/SomeRandomFile.txt0
-rw-r--r--Tests/BundleTest/randomResourceFile.plist.in9
6 files changed, 239 insertions, 0 deletions
diff --git a/Tests/BundleTest/BundleLib.cxx b/Tests/BundleTest/BundleLib.cxx
new file mode 100644
index 000000000..b68ee25dd
--- /dev/null
+++ b/Tests/BundleTest/BundleLib.cxx
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+int fileExists(char* filename)
+{
+#ifndef R_OK
+# define R_OK 04
+#endif
+ if ( access(filename, R_OK) != 0 )
+ {
+ printf("Cannot find file: %s\n", filename);
+ return 0;
+ }
+ return 1;
+}
+
+int findBundleFile(char* exec, const char* file)
+{
+ int res;
+ char* nexec = strdup(exec);
+ char* fpath = (char*)malloc(strlen(exec) + 100);
+ int cc;
+ int cnt = 0;
+ printf("Process executable name: %s\n", exec);
+
+ // Remove the executable name and directory name
+ for ( cc = strlen(nexec)-1; cc > 0; cc -- )
+ {
+ if ( nexec[cc] == '/' )
+ {
+ nexec[cc] = 0;
+ if ( cnt == 1 )
+ {
+ break;
+ }
+ cnt ++;
+ }
+ }
+ printf("Process executable path: %s\n", nexec);
+ sprintf(fpath, "%s/%s", nexec, file);
+ printf("Check for file: %s\n", fpath);
+ res = fileExists(fpath);
+ free(nexec);
+ free(fpath);
+ return res;
+}
+
+int foo(char *exec)
+{
+ // Call a CoreFoundation function...
+ //
+ CFBundleRef br = CFBundleGetMainBundle();
+ (void) br;
+
+ int res1 = findBundleFile(exec, "Resources/randomResourceFile.plist");
+ int res2 = findBundleFile(exec, "MacOS/SomeRandomFile.txt");
+ int res3 = findBundleFile(exec, "MacOS/ChangeLog.txt");
+ if ( !res1 ||
+ !res2 ||
+ !res3 )
+ {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/Tests/BundleTest/BundleSubDir/CMakeLists.txt b/Tests/BundleTest/BundleSubDir/CMakeLists.txt
new file mode 100644
index 000000000..322b2a7d2
--- /dev/null
+++ b/Tests/BundleTest/BundleSubDir/CMakeLists.txt
@@ -0,0 +1,36 @@
+ADD_CUSTOM_COMMAND(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ COMMAND /bin/cp
+ ARGS "${BundleTest_SOURCE_DIR}/randomResourceFile.plist.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
+
+SET_SOURCE_FILES_PROPERTIES(
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources
+ )
+
+SET_SOURCE_FILES_PROPERTIES(
+ "${BundleTest_SOURCE_DIR}/SomeRandomFile.txt"
+ "${BundleTest_SOURCE_DIR}/../../ChangeLog.txt"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION MacOS
+ )
+
+ADD_EXECUTABLE(SecondBundle
+ MACOSX_BUNDLE
+ "${BundleTest_SOURCE_DIR}/BundleTest.cxx"
+ "${BundleTest_SOURCE_DIR}/SomeRandomFile.txt"
+ "${BundleTest_SOURCE_DIR}/../../ChangeLog.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ )
+TARGET_LINK_LIBRARIES(SecondBundle BundleTestLib)
+
+# Test bundle installation.
+INSTALL(TARGETS SecondBundle DESTINATION Applications)
+
+# Test whether bundles respect the output name. Since the library is
+# installed into a location that uses this output name this will fail if the
+# bundle does not respect the name. Also the executable will not be found by
+# the test driver if this does not work.
+SET_TARGET_PROPERTIES(SecondBundle PROPERTIES OUTPUT_NAME SecondBundleExe)
diff --git a/Tests/BundleTest/BundleTest.cxx b/Tests/BundleTest/BundleTest.cxx
new file mode 100644
index 000000000..a66d601d3
--- /dev/null
+++ b/Tests/BundleTest/BundleTest.cxx
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+extern int foo(char* exec);
+
+int main(int argc, char* argv[])
+{
+ printf("Started with: %d arguments\n", argc);
+
+ // Call a CoreFoundation function... but pull in the link dependency on "-framework
+ // CoreFoundation" via CMake's dependency chaining mechanism. This code exists to
+ // verify that the chaining mechanism works with "-framework blah" style
+ // link dependencies.
+ //
+ CFBundleRef br = CFBundleGetMainBundle();
+ (void) br;
+
+ return foo(argv[0]);
+}
diff --git a/Tests/BundleTest/CMakeLists.txt b/Tests/BundleTest/CMakeLists.txt
new file mode 100644
index 000000000..5342f49bd
--- /dev/null
+++ b/Tests/BundleTest/CMakeLists.txt
@@ -0,0 +1,104 @@
+cmake_minimum_required (VERSION 2.6)
+PROJECT(BundleTest)
+SET(MACOSX_BUNDLE_INFO_STRING "bundle_info_string")
+SET(CMAKE_MacOSX_Content_COMPILE_OBJECT "\"${CMAKE_COMMAND}\" -E copy_if_different <SOURCE> <OBJECT>")
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ COMMAND /bin/cp
+ ARGS "${CMAKE_CURRENT_SOURCE_DIR}/randomResourceFile.plist.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
+
+SET_SOURCE_FILES_PROPERTIES(
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources
+ )
+
+SET_SOURCE_FILES_PROPERTIES(
+ SomeRandomFile.txt
+ "${BundleTest_SOURCE_DIR}/../../ChangeLog.txt"
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION MacOS
+ )
+
+SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/foobar")
+
+# Test building a bundle linking to a shared library where the
+# shared library links to CoreFoundation, but the executable does not
+# explicitly link to CoreFoundation, but the executable does *depend*
+# on CoreFoundation. There should be a link failure for the executable
+# if CMake's dependency chaining for libraries with "-framework
+# blah" style dependencies gets broken...
+#
+ADD_LIBRARY(BundleTestLib SHARED BundleLib.cxx)
+TARGET_LINK_LIBRARIES(BundleTestLib "-framework CoreFoundation")
+
+ADD_EXECUTABLE(BundleTest
+ MACOSX_BUNDLE
+ BundleTest.cxx
+ SomeRandomFile.txt
+ "${BundleTest_SOURCE_DIR}/../../ChangeLog.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
+ )
+TARGET_LINK_LIBRARIES(BundleTest BundleTestLib)
+#
+# DO NOT: TARGET_LINK_LIBRARIES(BundleTest "-framework CoreFoundation")
+# (see above comments about CoreFoundation)
+#
+
+# Test bundle installation.
+#INSTALL(TARGETS BundleTestLib DESTINATION Applications/BundleTestExe.app/Contents/Plugins)
+INSTALL(TARGETS BundleTestLib DESTINATION Applications/SecondBundleExe.app/Contents/Plugins)
+INSTALL(TARGETS BundleTest DESTINATION Applications)
+
+# Test whether bundles respect the output name. Since the library is
+# installed into a location that uses this output name this will fail if the
+# bundle does not respect the name. Also the executable will not be found by
+# the test driver if this does not work.
+SET_TARGET_PROPERTIES(BundleTest PROPERTIES OUTPUT_NAME BundleTestExe)
+
+# Test executable versioning if it is supported.
+IF(NOT XCODE)
+ SET_TARGET_PROPERTIES(BundleTest PROPERTIES VERSION 1)
+ENDIF(NOT XCODE)
+
+# Make sure the executable can find its installed library.
+SET_TARGET_PROPERTIES(BundleTestLib PROPERTIES
+ INSTALL_NAME_DIR "@executable_path/../Plugins")
+
+INCLUDE(CPack)
+
+# test the framework find stuff
+IF(EXISTS /usr/lib/libtcl.dylib
+ AND EXISTS /System/Library/Frameworks/Tcl.framework)
+ SET(TCL NOTFOUND)
+ FIND_LIBRARY(TCL tcl)
+ MESSAGE("frame: ${TCL}")
+ IF(NOT "${TCL}" MATCHES .framework)
+ MESSAGE(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
+ ENDIF(NOT "${TCL}" MATCHES .framework)
+ SET(TCL NOTFOUND)
+ SET(CMAKE_FIND_FRAMEWORK LAST)
+ FIND_LIBRARY(TCL tcl)
+ IF("${TCL}" MATCHES .framework)
+ MESSAGE(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
+ ENDIF("${TCL}" MATCHES .framework)
+ SET(TCL NOTFOUND)
+ SET(CMAKE_FIND_FRAMEWORK NEVER)
+ FIND_LIBRARY(TCL tcl)
+ IF("${TCL}" MATCHES .framework)
+ MESSAGE(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
+ ENDIF("${TCL}" MATCHES .framework)
+ MESSAGE("not frame: ${TCL}")
+ SET(TCL NOTFOUND)
+ SET(CMAKE_FIND_FRAMEWORK FIRST)
+ FIND_LIBRARY(TCL tcl)
+ IF(NOT "${TCL}" MATCHES .framework)
+ MESSAGE(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
+ ENDIF(NOT "${TCL}" MATCHES .framework)
+ MESSAGE("frame: ${TCL}")
+ENDIF(EXISTS /usr/lib/libtcl.dylib
+ AND EXISTS /System/Library/Frameworks/Tcl.framework)
+
+SUBDIRS(BundleSubDir)
diff --git a/Tests/BundleTest/SomeRandomFile.txt b/Tests/BundleTest/SomeRandomFile.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Tests/BundleTest/SomeRandomFile.txt
diff --git a/Tests/BundleTest/randomResourceFile.plist.in b/Tests/BundleTest/randomResourceFile.plist.in
new file mode 100644
index 000000000..cfe3222b6
--- /dev/null
+++ b/Tests/BundleTest/randomResourceFile.plist.in
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Package</key>
+ <string>CMake</string>
+</dict>
+</plist>
+