Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/BundleUtilities/CMakeLists.txt
3150 views
1
cmake_minimum_required(VERSION 3.10)
2
project(BundleUtilities)
3
4
if(CMAKE_GENERATOR STREQUAL "Xcode" AND
5
"${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64")
6
# Tell Xcode to pretend the linker signed binaries so that
7
# editing with install_name_tool preserves ad-hoc signatures.
8
# See CMake Issue 21854.
9
# This option is supported by codesign on macOS 11 or higher.
10
set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed")
11
endif()
12
13
###### the various types of dependencies we can have
14
15
# a shared library
16
add_library(shared SHARED shared.cpp shared.h)
17
18
# another shared library
19
add_library(shared2 SHARED shared2.cpp shared2.h)
20
21
22
# a framework library
23
add_library(framework SHARED framework.cpp framework.h)
24
set_target_properties(framework PROPERTIES FRAMEWORK 1)
25
26
# make sure rpaths are not helping BundleUtilities or the executables
27
set_target_properties(shared shared2 framework PROPERTIES
28
SKIP_BUILD_RPATH 1)
29
30
31
###### test a Bundle application using dependencies
32
33
# a loadable module (depends on shared2)
34
# testbundleutils1 will load this at runtime
35
add_library(module1 MODULE module.cpp module.h)
36
set_target_properties(module1 PROPERTIES PREFIX "")
37
target_link_libraries(module1 shared2)
38
39
# a bundle application
40
add_executable(testbundleutils1 MACOSX_BUNDLE testbundleutils1.cpp)
41
target_link_libraries(testbundleutils1 shared framework ${CMAKE_DL_LIBS})
42
43
set_target_properties(testbundleutils1 module1 PROPERTIES
44
INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir1"
45
BUILD_WITH_INSTALL_RPATH 1)
46
47
# add custom target to install and test the app
48
add_custom_target(testbundleutils1_test ALL
49
COMMAND ${CMAKE_COMMAND}
50
"-DINPUT=$<TARGET_FILE:testbundleutils1>"
51
"-DMODULE=$<TARGET_FILE:module1>"
52
"-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
53
"-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir1"
54
-P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
55
DEPENDS testbundleutils1 module1
56
)
57
58
add_dependencies(testbundleutils1_test testbundleutils1)
59
60
61
62
###### test a non-Bundle application using dependencies
63
64
# a loadable module (depends on shared2)
65
# testbundleutils2 will load this at runtime
66
add_library(module2 MODULE module.cpp module.h)
67
set_target_properties(module2 PROPERTIES PREFIX "")
68
target_link_libraries(module2 shared2)
69
70
# a non-bundle application
71
add_executable(testbundleutils2 testbundleutils2.cpp)
72
target_link_libraries(testbundleutils2 shared framework ${CMAKE_DL_LIBS})
73
74
set_target_properties(testbundleutils2 module2 PROPERTIES
75
INSTALL_RPATH "${CMAKE_CURRENT_BINARY_DIR}/testdir2"
76
BUILD_WITH_INSTALL_RPATH 1)
77
78
# add custom target to install and test the app
79
add_custom_target(testbundleutils2_test ALL
80
COMMAND ${CMAKE_COMMAND}
81
"-DINPUT=$<TARGET_FILE:testbundleutils2>"
82
"-DMODULE=$<TARGET_FILE:module2>"
83
"-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
84
"-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir2"
85
-P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
86
DEPENDS testbundleutils1 module2
87
)
88
add_dependencies(testbundleutils2_test testbundleutils2)
89
90
91
if(APPLE AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 9.0)
92
###### Test a Bundle application using dependencies
93
###### and @rpaths on Mac OS X 10.5 or greater
94
95
# a shared library
96
add_library(shared-3 SHARED shared.cpp shared.h)
97
98
# another shared library
99
add_library(shared2-3 SHARED shared2.cpp shared2.h)
100
101
# a framework library
102
add_library(framework-3 SHARED framework.cpp framework.h)
103
set_target_properties(framework-3 PROPERTIES FRAMEWORK 1)
104
105
# build dependencies with @rpath install name
106
set_target_properties(shared-3 shared2-3 framework-3 PROPERTIES
107
INSTALL_NAME_DIR "@rpath"
108
BUILD_WITH_INSTALL_RPATH 1)
109
110
# a loadable module (depends on shared2)
111
# testbundleutils1 will load this at runtime
112
add_library(module3 MODULE module.cpp module.h)
113
set_target_properties(module3 PROPERTIES PREFIX "" LINK_FLAGS "-Wl,-rpath,@loader_path/")
114
target_link_libraries(module3 shared2-3)
115
116
# a non-bundle application
117
add_executable(testbundleutils3 testbundleutils3.cpp)
118
target_link_libraries(testbundleutils3 shared-3 framework-3 ${CMAKE_DL_LIBS})
119
120
set_target_properties(testbundleutils3 module3 PROPERTIES
121
LINK_FLAGS "-Wl,-rpath,@loader_path/"
122
BUILD_WITH_INSTALL_RPATH 1)
123
124
# add custom target to install and test the app
125
add_custom_target(testbundleutils3_test ALL
126
COMMAND ${CMAKE_COMMAND}
127
"-DINPUT=$<TARGET_FILE:testbundleutils3>"
128
"-DMODULE=$<TARGET_FILE:module3>"
129
"-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
130
"-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir3"
131
-P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake"
132
DEPENDS testbundleutils3 module3
133
)
134
135
add_dependencies(testbundleutils3_test testbundleutils3)
136
endif()
137
138