CMake Nightly Date Stamp
[kiteware-cmake.git] / Tests / BundleTest / CMakeLists.txt
blobc63461a2c537984e144c25ffd8951b4db09281d8
1 cmake_minimum_required (VERSION 2.6)
2 project(BundleTest)
3 set(MACOSX_BUNDLE_INFO_STRING "bundle_info_string")
4 set(CMAKE_MacOSX_Content_COMPILE_OBJECT "\"${CMAKE_COMMAND}\" -E copy_if_different <SOURCE> <OBJECT>")
6 if(CMAKE_GENERATOR STREQUAL "Xcode" AND
7    "${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64")
8   # Tell Xcode to pretend the linker signed binaries so that
9   # editing with install_name_tool preserves ad-hoc signatures.
10   # See CMake Issue 21854.
11   # This option is supported by codesign on macOS 11 or higher.
12   set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed")
13 endif()
15 add_custom_command(
16   OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
17   COMMAND /bin/cp
18   ARGS "${CMAKE_CURRENT_SOURCE_DIR}/randomResourceFile.plist.in"
19   "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
21 set_source_files_properties(
22   "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
23   PROPERTIES
24   MACOSX_PACKAGE_LOCATION Resources
25   )
27 set_source_files_properties(
28   SomeRandomFile.txt
29   "${BundleTest_SOURCE_DIR}/../../README.rst"
30   PROPERTIES
31   MACOSX_PACKAGE_LOCATION Other
32   )
34 set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/foobar")
36 # Test building a bundle linking to a shared library where the
37 # shared library links to CoreFoundation, but the executable does not
38 # explicitly link to CoreFoundation, but the executable does *depend*
39 # on CoreFoundation. There should be a link failure for the executable
40 # if CMake's dependency chaining for libraries with "-framework
41 # blah" style dependencies gets broken...
43 add_library(BundleTestLib SHARED BundleLib.cxx)
44 target_link_libraries(BundleTestLib "-framework CoreFoundation")
46 add_executable(BundleTest
47   MACOSX_BUNDLE
48   BundleTest.cxx
49   SomeRandomFile.txt
50   "${BundleTest_SOURCE_DIR}/../../README.rst"
51   "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
52   )
53 target_link_libraries(BundleTest BundleTestLib)
55 # DO NOT: target_link_libraries(BundleTest "-framework CoreFoundation")
56 #   (see above comments about CoreFoundation)
59 # Test bundle installation.
60 #install(TARGETS BundleTestLib DESTINATION Applications/BundleTestExe.app/Contents/Plugins)
61 install(TARGETS BundleTestLib DESTINATION Applications/SecondBundleExe.app/Contents/Plugins)
62 install(TARGETS BundleTest DESTINATION Applications)
64 # Test whether bundles respect the output name.  Since the library is
65 # installed into a location that uses this output name this will fail if the
66 # bundle does not respect the name.  Also the executable will not be found by
67 # the test driver if this does not work.
68 set_target_properties(BundleTest PROPERTIES OUTPUT_NAME BundleTestExe)
70 # Test executable versioning if it is supported.
71 if(NOT XCODE)
72   set_target_properties(BundleTest PROPERTIES VERSION 1)
73 endif()
75 # Make sure the executable can find its installed library.
76 set_target_properties(BundleTestLib PROPERTIES
77   INSTALL_NAME_DIR "@executable_path/../Plugins")
79 include(CPack)
81 # test the framework find stuff
82 if(EXISTS /usr/lib/libtcl.dylib
83     AND EXISTS /System/Library/Frameworks/Tcl.framework)
84   set(TCL NOTFOUND)
85   find_library(TCL tcl)
86   message("frame: ${TCL}")
87   if(NOT "${TCL}" MATCHES .framework)
88     message(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
89   endif()
90   set(TCL NOTFOUND)
91   set(CMAKE_FIND_FRAMEWORK LAST)
92   find_library(TCL tcl)
93   if("${TCL}" MATCHES .framework)
94     message(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
95   endif()
96   set(TCL NOTFOUND)
97   set(CMAKE_FIND_FRAMEWORK NEVER)
98   find_library(TCL tcl)
99   if("${TCL}" MATCHES .framework)
100     message(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
101   endif()
102   message("not frame: ${TCL}")
103   set(TCL NOTFOUND)
104   set(CMAKE_FIND_FRAMEWORK FIRST)
105   find_library(TCL tcl)
106   if(NOT "${TCL}" MATCHES .framework)
107     message(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
108   endif()
109   message("frame: ${TCL}")
110 endif(EXISTS /usr/lib/libtcl.dylib
111   AND EXISTS /System/Library/Frameworks/Tcl.framework)
113 subdirs(BundleSubDir)