CMakeLists.txt 4.4 KB

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