1
0

XcodeBundles.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # check if Xcode and CMake have the same understanding of Bundle layout
  2. cmake_minimum_required(VERSION 3.3)
  3. enable_language(C)
  4. if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  5. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
  6. set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
  7. endif()
  8. if(CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS")
  9. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
  10. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
  11. set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
  12. endif()
  13. # App Bundle
  14. add_executable(AppBundle MACOSX_BUNDLE main.m)
  15. add_custom_target(AppBundleTest ALL
  16. COMMAND ${CMAKE_COMMAND} -E copy
  17. "$<TARGET_FILE:AppBundle>" "$<TARGET_FILE:AppBundle>.old")
  18. add_dependencies(AppBundleTest AppBundle)
  19. # with custom extension
  20. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  21. add_executable(AppBundleExt MACOSX_BUNDLE main.m)
  22. set_target_properties(AppBundleExt PROPERTIES BUNDLE_EXTENSION "foo")
  23. install(TARGETS AppBundleExt BUNDLE DESTINATION FooExtension)
  24. add_custom_target(AppBundleExtTest ALL
  25. COMMAND ${CMAKE_COMMAND} -E copy
  26. "$<TARGET_FILE:AppBundleExt>" "$<TARGET_FILE:AppBundleExt>.old")
  27. add_dependencies(AppBundleExtTest AppBundleExt)
  28. endif()
  29. # Shared Framework (not supported for iOS on Xcode < 6)
  30. if(NOT CMAKE_SYSTEM_NAME STREQUAL "iOS" OR NOT XCODE_VERSION VERSION_LESS 6)
  31. add_library(SharedFramework SHARED main.c)
  32. set_target_properties(SharedFramework PROPERTIES FRAMEWORK TRUE)
  33. add_custom_target(SharedFrameworkTest ALL
  34. COMMAND ${CMAKE_COMMAND} -E copy
  35. "$<TARGET_BUNDLE_DIR:SharedFramework>" "$<TARGET_BUNDLE_DIR:SharedFramework>.old"
  36. COMMAND ${CMAKE_COMMAND} -E copy
  37. "$<TARGET_BUNDLE_CONTENT_DIR:SharedFramework>" "$<TARGET_BUNDLE_CONTENT_DIR:SharedFramework>.old"
  38. COMMAND ${CMAKE_COMMAND} -E copy
  39. "$<TARGET_FILE:SharedFramework>" "$<TARGET_FILE:SharedFramework>.old")
  40. add_dependencies(SharedFrameworkTest SharedFramework)
  41. # with custom extension
  42. add_library(SharedFrameworkExt SHARED main.c)
  43. set_target_properties(SharedFrameworkExt PROPERTIES FRAMEWORK TRUE)
  44. set_target_properties(SharedFrameworkExt PROPERTIES BUNDLE_EXTENSION "foo")
  45. install(TARGETS SharedFrameworkExt FRAMEWORK DESTINATION FooExtension)
  46. add_custom_target(SharedFrameworkExtTest ALL
  47. COMMAND ${CMAKE_COMMAND} -E copy
  48. "$<TARGET_BUNDLE_DIR:SharedFrameworkExt>" "$<TARGET_BUNDLE_DIR:SharedFrameworkExt>.old"
  49. COMMAND ${CMAKE_COMMAND} -E copy
  50. "$<TARGET_BUNDLE_CONTENT_DIR:SharedFrameworkExt>" "$<TARGET_BUNDLE_CONTENT_DIR:SharedFrameworkExt>.old"
  51. COMMAND ${CMAKE_COMMAND} -E copy
  52. "$<TARGET_FILE:SharedFrameworkExt>" "$<TARGET_FILE:SharedFrameworkExt>.old")
  53. add_dependencies(SharedFrameworkExtTest SharedFrameworkExt)
  54. endif()
  55. # Static Framework (not supported for Xcode < 6)
  56. if(NOT XCODE_VERSION VERSION_LESS 6)
  57. add_library(StaticFramework STATIC main.c)
  58. set_target_properties(StaticFramework PROPERTIES FRAMEWORK TRUE)
  59. add_custom_target(StaticFrameworkTest ALL
  60. COMMAND ${CMAKE_COMMAND} -E copy
  61. "$<TARGET_BUNDLE_DIR:StaticFramework>" "$<TARGET_BUNDLE_DIR:StaticFramework>.old"
  62. COMMAND ${CMAKE_COMMAND} -E copy
  63. "$<TARGET_BUNDLE_CONTENT_DIR:StaticFramework>" "$<TARGET_BUNDLE_CONTENT_DIR:StaticFramework>.old"
  64. COMMAND ${CMAKE_COMMAND} -E copy
  65. "$<TARGET_FILE:StaticFramework>" "$<TARGET_FILE:StaticFramework>.old")
  66. add_dependencies(StaticFrameworkTest StaticFramework)
  67. # with custom extension
  68. add_library(StaticFrameworkExt STATIC main.c)
  69. set_target_properties(StaticFrameworkExt PROPERTIES FRAMEWORK TRUE)
  70. set_target_properties(StaticFrameworkExt PROPERTIES BUNDLE_EXTENSION "foo")
  71. install(TARGETS StaticFrameworkExt FRAMEWORK DESTINATION StaticFooExtension)
  72. add_custom_target(StaticFrameworkExtTest ALL
  73. COMMAND ${CMAKE_COMMAND} -E copy
  74. "$<TARGET_BUNDLE_DIR:StaticFrameworkExt>" "$<TARGET_BUNDLE_DIR:StaticFrameworkExt>.old"
  75. COMMAND ${CMAKE_COMMAND} -E copy
  76. "$<TARGET_BUNDLE_CONTENT_DIR:StaticFrameworkExt>" "$<TARGET_BUNDLE_CONTENT_DIR:StaticFrameworkExt>.old"
  77. COMMAND ${CMAKE_COMMAND} -E copy
  78. "$<TARGET_FILE:StaticFrameworkExt>" "$<TARGET_FILE:StaticFrameworkExt>.old")
  79. add_dependencies(StaticFrameworkExtTest StaticFrameworkExt)
  80. endif()
  81. # Bundle
  82. if(NOT CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE)
  83. add_library(Bundle MODULE main.c)
  84. set_target_properties(Bundle PROPERTIES BUNDLE TRUE)
  85. add_custom_target(BundleTest ALL
  86. COMMAND ${CMAKE_COMMAND} -E copy
  87. "$<TARGET_BUNDLE_DIR:Bundle>" "$<TARGET_BUNDLE_DIR:Bundle>.old"
  88. COMMAND ${CMAKE_COMMAND} -E copy
  89. "$<TARGET_BUNDLE_CONTENT_DIR:Bundle>" "$<TARGET_BUNDLE_CONTENT_DIR:Bundle>.old"
  90. COMMAND ${CMAKE_COMMAND} -E copy
  91. "$<TARGET_FILE:Bundle>" "$<TARGET_FILE:Bundle>.old")
  92. add_dependencies(BundleTest Bundle)
  93. # with custom extension
  94. add_library(BundleExt MODULE main.c)
  95. set_target_properties(BundleExt PROPERTIES BUNDLE TRUE)
  96. set_target_properties(BundleExt PROPERTIES BUNDLE_EXTENSION "foo")
  97. install(TARGETS BundleExt LIBRARY DESTINATION FooExtension)
  98. add_custom_target(BundleExtTest ALL
  99. COMMAND ${CMAKE_COMMAND} -E copy
  100. "$<TARGET_BUNDLE_DIR:BundleExt>" "$<TARGET_BUNDLE_DIR:BundleExt>.old"
  101. COMMAND ${CMAKE_COMMAND} -E copy
  102. "$<TARGET_BUNDLE_CONTENT_DIR:BundleExt>" "$<TARGET_BUNDLE_CONTENT_DIR:BundleExt>.old"
  103. COMMAND ${CMAKE_COMMAND} -E copy
  104. "$<TARGET_FILE:BundleExt>" "$<TARGET_FILE:BundleExt>.old")
  105. add_dependencies(BundleExtTest BundleExt)
  106. endif()