summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/XcFramework/RunCMakeTest.cmake
blob: fad088f6b3a5afc80cc6257f14f7d0ff9a8cb63d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
include(RunCMake)

function(create_library type platform system_name archs sysroot)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-${type}-${platform}-build)
  run_cmake_with_options(create-${type}-${platform} -DCMAKE_SYSTEM_NAME=${system_name} -DCMAKE_OSX_ARCHITECTURES=${archs} -DCMAKE_OSX_SYSROOT=${sysroot} -DCMAKE_INSTALL_PREFIX=${RunCMake_TEST_BINARY_DIR}/install)

  set(RunCMake_TEST_NO_CLEAN 1)
  run_cmake_command(create-${type}-${platform}-build ${CMAKE_COMMAND} --build . --config Release)
  run_cmake_command(create-${type}-${platform}-install ${CMAKE_COMMAND} --install . --config Release)
endfunction()

function(create_libraries type)
  create_library(${type} macos Darwin "${macos_archs_2}" macosx)
  create_library(${type} ios iOS "arm64" iphoneos)
  create_library(${type} tvos tvOS "arm64" appletvos)
  create_library(${type} watchos watchOS "armv7k\\\\;arm64_32" watchos)
  #FIXME(#25266): Xcode 15.0 does not have visionOS.  Improve this condition.
  #if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
  #  create_library(${type} visionos visionOS "arm64" xros)
  #endif()
  create_library(${type} ios-simulator iOS "${macos_archs_2}" iphonesimulator)
  create_library(${type} tvos-simulator tvOS "${macos_archs_2}" appletvsimulator)
  create_library(${type} watchos-simulator watchOS "${watch_sim_archs_2}" watchsimulator)
  #FIXME(#25266): Xcode 15.0 does not have visionOS.  Improve this condition.
  #if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
  #  create_library(${type} visionos-simulator visionOS "${macos_archs_2}" xrsimulator)
  #endif()
endfunction()

function(create_xcframework name type platforms)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-xcframework-${name}-build)
  if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
    # 'xcodebuild -create-xcframework' fails on symlinked paths.
    file(REAL_PATH "${RunCMake_SOURCE_DIR}" src_dir)
    file(REAL_PATH "${RunCMake_BINARY_DIR}" bld_dir)
  else()
    set(src_dir "${RunCMake_SOURCE_DIR}")
    set(bld_dir "${RunCMake_BINARY_DIR}")
  endif()
  set(args)
  foreach(platform IN LISTS platforms)
    set(lib_dir "${bld_dir}/create-${type}-${platform}-build/install/lib")
    if(type STREQUAL "framework")
      list(APPEND args -framework ${lib_dir}/mylib.framework)
    else()
      list(APPEND args -library ${lib_dir}/libmylib.a -headers ${src_dir}/mylib/include)
    endif()
  endforeach()
  run_cmake_command(create-xcframework-${name} xcodebuild -create-xcframework ${args} -output ${RunCMake_TEST_BINARY_DIR}/mylib.xcframework)
endfunction()

function(create_executable name xcfname system_name archs sysroot)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-executable-${name}-build)
  run_cmake_with_options(create-executable-${name} -DCMAKE_SYSTEM_NAME=${system_name} -DCMAKE_OSX_ARCHITECTURES=${archs} -DCMAKE_OSX_SYSROOT=${sysroot} -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-${xcfname}-build/mylib.xcframework)

  set(RunCMake_TEST_NO_CLEAN 1)
  run_cmake_command(create-executable-${name}-build ${CMAKE_COMMAND} --build . --config Release)
endfunction()

function(create_executables name type)
  create_executable(${name}-macos ${type} Darwin "${macos_archs_2}" macosx)
  create_executable(${name}-ios ${type} iOS "arm64" iphoneos)
  create_executable(${name}-tvos ${type} tvOS "arm64" appletvos)
  create_executable(${name}-watchos ${type} watchOS "armv7k\\\\;arm64_32" watchos)
  #FIXME(#25266): Xcode 15.0 does not have visionOS.  Improve this condition.
  #if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
  #  create_executable(${name}-visionos ${type} visionOS "arm64" xros)
  #endif()
  create_executable(${name}-ios-simulator ${type} iOS "${macos_archs_2}" iphonesimulator)
  create_executable(${name}-tvos-simulator ${type} tvOS "${macos_archs_2}" appletvsimulator)
  create_executable(${name}-watchos-simulator ${type} watchOS "${watch_sim_archs_2}" watchsimulator)
  #FIXME(#25266): Xcode 15.0 does not have visionOS.  Improve this condition.
  #if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
  #  create_executable(${name}-visionos-simulator ${type} visionOS "${macos_archs_2}" xrsimulator)
  #endif()
endfunction()

set(xcframework_platforms macos ios tvos watchos ios-simulator tvos-simulator watchos-simulator)
#FIXME(#25266): Xcode 15.0 does not have visionOS.  Improve this condition.
#if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
#  list(APPEND xcframework_platforms visionos visionos-simulator)
#endif()
if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 12)
  set(macos_archs_1 "x86_64\\;arm64")
  set(macos_archs_2 "x86_64\\\\;arm64")
  set(watch_sim_archs_2 "x86_64")
else()
  set(macos_archs_1 "x86_64")
  set(macos_archs_2 "x86_64")
  set(watch_sim_archs_2 "i386")
endif()

create_libraries(library)
create_libraries(framework)
create_xcframework(library library "${xcframework_platforms}")
create_xcframework(framework framework "${xcframework_platforms}")
create_xcframework(incomplete framework "tvos;watchos")
create_executables(library library)
create_executables(framework framework)
run_cmake_with_options(create-executable-incomplete -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
create_executables(target-library library)
create_executables(target-framework framework)
run_cmake_with_options(create-executable-target-incomplete -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
if(RunCMake_GENERATOR STREQUAL "Xcode" AND CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 12)
  create_executables(library-link-phase library)
  create_executables(framework-link-phase framework)
  run_cmake_with_options(create-executable-incomplete-link-phase -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
  create_executables(target-library-link-phase library)
  create_executables(target-framework-link-phase framework)
  run_cmake_with_options(create-executable-target-incomplete-link-phase -DCMAKE_SYSTEM_NAME=Darwin "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DMYLIB_LIBRARY=${RunCMake_BINARY_DIR}/create-xcframework-incomplete-build/mylib.xcframework)
endif()

# Ensure that .xcframework is found before .framework
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-xcframework-framework-build)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(copy-framework ${CMAKE_COMMAND} -E copy_directory ${RunCMake_BINARY_DIR}/create-framework-macos-build/install/lib/mylib.framework ${RunCMake_TEST_BINARY_DIR}/mylib.framework)
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

run_cmake(find-library)
run_cmake_command(find-library-script ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/find-library.cmake)

file(REMOVE_RECURSE ${RunCMake_BINARY_DIR}/export-install)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-macos-build)
run_cmake_with_options(export-macos -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/export-install)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(export-macos-build ${CMAKE_COMMAND} --build . ${_config_arg})
run_cmake_command(export-macos-install ${CMAKE_COMMAND} --install . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-ios-build)
run_cmake_with_options(export-ios -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos "-DCMAKE_OSX_ARCHITECTURES=arm64" -DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/export-install)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(export-ios-build ${CMAKE_COMMAND} --build . ${_config_arg})
run_cmake_command(export-ios-install ${CMAKE_COMMAND} --install . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-ios-simulator-build)
run_cmake_with_options(export-ios-simulator -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/export-install)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(export-ios-simulator-build ${CMAKE_COMMAND} --build . ${_config_arg})
run_cmake_command(export-ios-simulator-install ${CMAKE_COMMAND} --install . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-install-specific-no-xcframework-build)
run_cmake_with_options(import-macos-install-specific-no-xcframework -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-install/lib/macos/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
set(_config_dir)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
  set(_config_dir /Release)
endif()
run_cmake_command(import-macos-install-specific-no-xcframework-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_NO_CLEAN 1)
if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
  # 'xcodebuild -create-xcframework' fails on symlinked paths.
  file(REAL_PATH "${RunCMake_SOURCE_DIR}" src_dir)
  file(REAL_PATH "${RunCMake_BINARY_DIR}" bld_dir)
else()
  set(src_dir "${RunCMake_SOURCE_DIR}")
  set(bld_dir "${RunCMake_BINARY_DIR}")
endif()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-install)
run_cmake_command(export-install-xcframework xcodebuild -create-xcframework
  -output ${bld_dir}/export-install/lib/mylib.xcframework
  -library ${bld_dir}/export-install/lib/macos/libmylib.a
  -headers ${src_dir}/mylib/include
  -library ${bld_dir}/export-install/lib/ios/libmylib.a
  -headers ${src_dir}/mylib/include
  -library ${bld_dir}/export-install/lib/ios-simulator/libmylib.a
  -headers ${src_dir}/mylib/include
  )
run_cmake_command(export-install-xcframework-genex xcodebuild -create-xcframework
  -output ${bld_dir}/export-install/lib2/mylib-genex.xcframework
  -library ${bld_dir}/export-install/lib/macos/libmylib-genex.a
  -headers ${src_dir}/mylib/include
  -library ${bld_dir}/export-install/lib/ios/libmylib-genex.a
  -headers ${src_dir}/mylib/include
  -library ${bld_dir}/export-install/lib/ios-simulator/libmylib-genex.a
  -headers ${src_dir}/mylib/include
  )
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-macos-build)
run_cmake_command(export-build-macos-xcframework xcodebuild -create-xcframework
  -output ${bld_dir}/export-macos-build/lib/mylib.xcframework
  -library ${bld_dir}/export-macos-build/lib/macos${_config_dir}/libmylib.a
  -headers ${src_dir}/mylib/include
  )
run_cmake_command(export-build-macos-xcframework-genex xcodebuild -create-xcframework
  -output ${bld_dir}/export-macos-build/lib/mylib-genex.xcframework
  -library ${bld_dir}/export-macos-build/lib/macos${_config_dir}/libmylib-genex.a
  -headers ${src_dir}/mylib/include
  )
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-install-specific-build)
run_cmake_with_options(import-macos-install-specific -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-install/lib/macos/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-macos-install-specific-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-build-specific-build)
run_cmake_with_options(import-macos-build-specific -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-macos-build/lib/macos/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-macos-build-specific-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-install-specific-genex-build)
run_cmake_with_options(import-macos-install-specific-genex -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-install/lib/macos/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-macos-install-specific-genex-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-build-specific-genex-build)
run_cmake_with_options(import-macos-build-specific-genex -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-macos-build/lib/macos/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-macos-build-specific-genex-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-install-general-build)
run_cmake_with_options(import-macos-install-general -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-install/lib/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-macos-install-general-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-macos-build-general-build)
run_cmake_with_options(import-macos-build-general -DCMAKE_SYSTEM_NAME=Darwin -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-macos-build/lib/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-macos-build-general-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)

set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/import-ios-install-general-build)
run_cmake_with_options(import-ios-install-general -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64 -Dmylib_DIR=${RunCMake_BINARY_DIR}/export-install/lib/cmake/mylib)
set(RunCMake_TEST_NO_CLEAN 1)
set(_config_arg)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  set(_config_arg --config Release)
endif()
run_cmake_command(import-ios-install-general-build ${CMAKE_COMMAND} --build . ${_config_arg})
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_BINARY_DIR)