CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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>")
  5. add_custom_command(
  6. OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
  7. COMMAND /bin/cp
  8. ARGS "${CMAKE_CURRENT_SOURCE_DIR}/randomResourceFile.plist.in"
  9. "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
  10. set_source_files_properties(
  11. "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
  12. PROPERTIES
  13. MACOSX_PACKAGE_LOCATION Resources
  14. )
  15. set_source_files_properties(
  16. SomeRandomFile.txt
  17. "${BundleTest_SOURCE_DIR}/../../README.rst"
  18. PROPERTIES
  19. MACOSX_PACKAGE_LOCATION MacOS
  20. )
  21. set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/foobar")
  22. # Test building a bundle linking to a shared library where the
  23. # shared library links to CoreFoundation, but the executable does not
  24. # explicitly link to CoreFoundation, but the executable does *depend*
  25. # on CoreFoundation. There should be a link failure for the executable
  26. # if CMake's dependency chaining for libraries with "-framework
  27. # blah" style dependencies gets broken...
  28. #
  29. add_library(BundleTestLib SHARED BundleLib.cxx)
  30. target_link_libraries(BundleTestLib "-framework CoreFoundation")
  31. add_executable(BundleTest
  32. MACOSX_BUNDLE
  33. BundleTest.cxx
  34. SomeRandomFile.txt
  35. "${BundleTest_SOURCE_DIR}/../../README.rst"
  36. "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
  37. )
  38. target_link_libraries(BundleTest BundleTestLib)
  39. #
  40. # DO NOT: target_link_libraries(BundleTest "-framework CoreFoundation")
  41. # (see above comments about CoreFoundation)
  42. #
  43. # Test bundle installation.
  44. #install(TARGETS BundleTestLib DESTINATION Applications/BundleTestExe.app/Contents/Plugins)
  45. install(TARGETS BundleTestLib DESTINATION Applications/SecondBundleExe.app/Contents/Plugins)
  46. install(TARGETS BundleTest DESTINATION Applications)
  47. # Test whether bundles respect the output name. Since the library is
  48. # installed into a location that uses this output name this will fail if the
  49. # bundle does not respect the name. Also the executable will not be found by
  50. # the test driver if this does not work.
  51. set_target_properties(BundleTest PROPERTIES OUTPUT_NAME BundleTestExe)
  52. # Test executable versioning if it is supported.
  53. if(NOT XCODE)
  54. set_target_properties(BundleTest PROPERTIES VERSION 1)
  55. endif()
  56. # Make sure the executable can find its installed library.
  57. set_target_properties(BundleTestLib PROPERTIES
  58. INSTALL_NAME_DIR "@executable_path/../Plugins")
  59. include(CPack)
  60. # test the framework find stuff
  61. if(EXISTS /usr/lib/libtcl.dylib
  62. AND EXISTS /System/Library/Frameworks/Tcl.framework)
  63. set(TCL NOTFOUND)
  64. find_library(TCL tcl)
  65. message("frame: ${TCL}")
  66. if(NOT "${TCL}" MATCHES .framework)
  67. message(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
  68. endif()
  69. set(TCL NOTFOUND)
  70. set(CMAKE_FIND_FRAMEWORK LAST)
  71. find_library(TCL tcl)
  72. if("${TCL}" MATCHES .framework)
  73. message(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
  74. endif()
  75. set(TCL NOTFOUND)
  76. set(CMAKE_FIND_FRAMEWORK NEVER)
  77. find_library(TCL tcl)
  78. if("${TCL}" MATCHES .framework)
  79. message(FATAL_ERROR "Found framework and should have found dylib ${TCL}")
  80. endif()
  81. message("not frame: ${TCL}")
  82. set(TCL NOTFOUND)
  83. set(CMAKE_FIND_FRAMEWORK FIRST)
  84. find_library(TCL tcl)
  85. if(NOT "${TCL}" MATCHES .framework)
  86. message(FATAL_ERROR "Could not find tcl framework, found ${TCL}")
  87. endif()
  88. message("frame: ${TCL}")
  89. endif(EXISTS /usr/lib/libtcl.dylib
  90. AND EXISTS /System/Library/Frameworks/Tcl.framework)
  91. subdirs(BundleSubDir)