CMakeLists.txt 4.6 KB

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