CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. cmake_minimum_required(VERSION 2.8)
  2. project(BundleUtilities)
  3. ###### the various types of dependencies we can have
  4. # a shared library
  5. add_library(shared SHARED shared.cpp shared.h)
  6. # another shared library
  7. add_library(shared2 SHARED shared2.cpp shared2.h)
  8. # a framework library
  9. add_library(framework SHARED framework.cpp framework.h)
  10. set_target_properties(framework PROPERTIES FRAMEWORK 1)
  11. # make sure rpaths are not helping BundleUtilities or the executables
  12. set_target_properties(shared shared2 framework PROPERTIES
  13. SKIP_BUILD_RPATH 1)
  14. ###### test a Bundle application using dependencies
  15. # a loadable module (depends on shared2)
  16. # testbundleutils1 will load this at runtime
  17. add_library(module1 MODULE module.cpp module.h)
  18. set_target_properties(module1 PROPERTIES PREFIX "")
  19. get_target_property(module_loc module1 LOCATION)
  20. target_link_libraries(module1 shared2)
  21. # a bundle application
  22. add_executable(testbundleutils1 MACOSX_BUNDLE testbundleutils1.cpp)
  23. target_link_libraries(testbundleutils1 shared framework ${CMAKE_DL_LIBS})
  24. get_target_property(loc testbundleutils1 LOCATION)
  25. set_target_properties(testbundleutils1 module1 PROPERTIES
  26. INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir1"
  27. BUILD_WITH_INSTALL_RPATH 1)
  28. # add custom target to install and test the app
  29. add_custom_target(testbundleutils1_test ALL
  30. COMMAND ${CMAKE_COMMAND}
  31. "-DINPUT=${loc}"
  32. "-DMODULE=${module_loc}"
  33. "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
  34. "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir1"
  35. -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
  36. DEPENDS testbundleutils1 module1
  37. )
  38. add_dependencies(testbundleutils1_test testbundleutils1)
  39. ###### test a non-Bundle application using dependencies
  40. # a loadable module (depends on shared2)
  41. # testbundleutils2 will load this at runtime
  42. add_library(module2 MODULE module.cpp module.h)
  43. set_target_properties(module2 PROPERTIES PREFIX "")
  44. get_target_property(module_loc module2 LOCATION)
  45. target_link_libraries(module2 shared2)
  46. # a non-bundle application
  47. add_executable(testbundleutils2 testbundleutils2.cpp)
  48. target_link_libraries(testbundleutils2 shared framework ${CMAKE_DL_LIBS})
  49. get_target_property(loc testbundleutils2 LOCATION)
  50. set_target_properties(testbundleutils2 module2 PROPERTIES
  51. INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir2"
  52. BUILD_WITH_INSTALL_RPATH 1)
  53. # add custom target to install and test the app
  54. add_custom_target(testbundleutils2_test ALL
  55. COMMAND ${CMAKE_COMMAND}
  56. "-DINPUT=${loc}"
  57. "-DMODULE=${module_loc}"
  58. "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
  59. "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir2"
  60. -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
  61. DEPENDS testbundleutils1 module2
  62. )
  63. add_dependencies(testbundleutils2_test testbundleutils2)
  64. if(APPLE AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 9.0)
  65. ###### Test a Bundle application using dependencies
  66. ###### and @rpaths on Mac OS X 10.5 or greater
  67. # a shared library
  68. add_library(shared-3 SHARED shared.cpp shared.h)
  69. # another shared library
  70. add_library(shared2-3 SHARED shared2.cpp shared2.h)
  71. # a framework library
  72. add_library(framework-3 SHARED framework.cpp framework.h)
  73. set_target_properties(framework-3 PROPERTIES FRAMEWORK 1)
  74. # build dependencies with @rpath install name
  75. set_target_properties(shared-3 shared2-3 framework-3 PROPERTIES
  76. INSTALL_NAME_DIR "@rpath"
  77. BUILD_WITH_INSTALL_RPATH 1)
  78. # a loadable module (depends on shared2)
  79. # testbundleutils1 will load this at runtime
  80. add_library(module3 MODULE module.cpp module.h)
  81. set_target_properties(module3 PROPERTIES PREFIX "" LINK_FLAGS "-Wl,-rpath,@loader_path/")
  82. get_target_property(module_loc module3 LOCATION)
  83. target_link_libraries(module3 shared2-3)
  84. # a non-bundle application
  85. add_executable(testbundleutils3 testbundleutils3.cpp)
  86. target_link_libraries(testbundleutils3 shared-3 framework-3 ${CMAKE_DL_LIBS})
  87. get_target_property(loc testbundleutils3 LOCATION)
  88. set_target_properties(testbundleutils3 module3 PROPERTIES
  89. LINK_FLAGS "-Wl,-rpath,@loader_path/")
  90. # add custom target to install and test the app
  91. add_custom_target(testbundleutils3_test ALL
  92. COMMAND ${CMAKE_COMMAND}
  93. "-DINPUT=${loc}"
  94. "-DMODULE=${module_loc}"
  95. "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
  96. "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir3"
  97. -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
  98. DEPENDS testbundleutils3 module3
  99. )
  100. add_dependencies(testbundleutils3_test testbundleutils3)
  101. endif()