-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvamp-plugin-packager.cmake
417 lines (356 loc) · 23.2 KB
/
vamp-plugin-packager.cmake
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
set(VPP_NAME "${CMAKE_PROJECT_NAME}" CACHE PATH "The name of the project")
set(VPP_COMPANY "MyCompany" CACHE PATH "The name of the company")
set(VPP_URL "www.vamp-plugins.org" CACHE PATH "The URL of the project")
set(VPP_APPID "00000000-0000-0000-0000-000000000000" CACHE PATH "The unique ID of the project")
set(VPP_BUILD_TAG "${CMAKE_PROJECT_VERSION}" CACHE STRING "The current tag of the project")
set(VPP_ABOUT_FILE "" CACHE PATH "The about file to add to the distribution")
set(VPP_CHANGELOG_FILE "" CACHE PATH "The changelog file to add to the distribution")
set(VPP_ICON_FILE "" CACHE PATH "The icon file to add to the distribution")
set(VPP_DIR ${CMAKE_CURRENT_BINARY_DIR}/Package CACHE PATH "The directory of the package")
set(VPP_CODESIGN_WINDOWS_KEYFILE "" CACHE PATH "The Windows (.pfx) certificate file")
set(VPP_CODESIGN_WINDOWS_KEYPASSWORD "" CACHE STRING "The password of the Windows (.pfx) certificate file")
set(VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT "Developer ID Application" CACHE STRING "The Apple Developer ID Application certificate")
set(VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT "Developer ID Installer" CACHE STRING "The Apple Developer ID Installer certificate")
set(VPP_CODESIGN_APPLE_KEYCHAIN_PROFILE_INSTALLER "notary-installer" CACHE STRING "The Apple keychain profile for installer")
set(VPP_CODESIGN_ENTITLEMENTS "${CMAKE_CURRENT_LIST_DIR}/vamp-plugins.entitlements")
option(VPP_NOTARIZE OFF)
# Check if the notarization can be performed
if(WIN32 AND VPP_NOTARIZE)
if(EXISTS ${VPP_CODESIGN_WINDOWS_KEYFILE})
message(STATUS "Windows notarization with ${VPP_CODESIGN_WINDOWS_KEYFILE} certificate is available")
set(VPP_NOTARIZE ON)
elseif(NOT VPP_CODESIGN_WINDOWS_KEYFILE STREQUAL "")
message(WARNING "Windows notarization with ${VPP_CODESIGN_WINDOWS_KEYFILE} certificate is not available")
set(VPP_NOTARIZE OFF)
else()
set(VPP_NOTARIZE OFF)
endif()
elseif(APPLE AND VPP_NOTARIZE)
execute_process(COMMAND security find-certificate -c ${VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT} OUTPUT_VARIABLE CERTIFICATE_RESULT ERROR_VARIABLE CERTIFICATE_ERROR)
if(CERTIFICATE_RESULT)
message(STATUS "Apple notarization with ${VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT} certificate is available")
set(VPP_NOTARIZE ON)
else()
message(WARNING "Apple notarization with ${VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT} certificate is not available")
set(VPP_NOTARIZE OFF)
endif()
execute_process(COMMAND security find-certificate -c ${VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT} OUTPUT_VARIABLE CERTIFICATE_RESULT ERROR_VARIABLE CERTIFICATE_ERROR)
if(CERTIFICATE_RESULT)
message(STATUS "Apple notarization with ${VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT} certificate is available")
set(VPP_NOTARIZE ON)
else(VPP_NOTARIZE)
message(WARNING "Apple notarization with ${VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT} certificate is not available")
set(VPP_NOTARIZE OFF)
endif()
endif()
# Generations
if(WIN32) # WINDOWS
set(VPP_PACKAGE "${VPP_DIR}/${VPP_NAME}-Windows.exe")
set(VPP_TEMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/PkgTemp")
cmake_path(NATIVE_PATH VPP_TEMP_DIR VPP_TEMP_DIR_NAT)
set(VPP_ISS_FILE "${VPP_TEMP_DIR}/package.iss")
set(VPP_SCRIPT "${VPP_TEMP_DIR}/package.bat")
file(WRITE ${VPP_ISS_FILE} "#define MyAppName \"${VPP_NAME}\"\n")
file(APPEND ${VPP_ISS_FILE} "\n")
file(APPEND ${VPP_ISS_FILE} "[Setup]\n")
file(APPEND ${VPP_ISS_FILE} "AppId={{${VPP_APPID}}}\n")
file(APPEND ${VPP_ISS_FILE} "AppName=\"${VPP_NAME}\"\n")
file(APPEND ${VPP_ISS_FILE} "AppVerName={#MyAppVerName}\n")
file(APPEND ${VPP_ISS_FILE} "AppPublisher=\"${VPP_COMPANY}\"\n")
file(APPEND ${VPP_ISS_FILE} "AppPublisherURL=\"${VPP_URL}\"\n")
file(APPEND ${VPP_ISS_FILE} "AppSupportURL=\"${VPP_URL}\"\n")
file(APPEND ${VPP_ISS_FILE} "AppUpdatesURL=\"${VPP_URL}\"\n")
file(APPEND ${VPP_ISS_FILE} "DefaultDirName=\"{commonpf64}\\Vamp Plugins\"\n")
file(APPEND ${VPP_ISS_FILE} "DisableProgramGroupPage=yes\n")
file(APPEND ${VPP_ISS_FILE} "DisableDirPage=no\n")
file(APPEND ${VPP_ISS_FILE} "OutputDir=..\\build\n")
file(APPEND ${VPP_ISS_FILE} "InfoBeforeFile=${VPP_ABOUT_FILE}\n")
file(APPEND ${VPP_ISS_FILE} "OutputBaseFilename=${VPP_NAME}-Windows\n")
file(APPEND ${VPP_ISS_FILE} "Compression=lzma\n")
file(APPEND ${VPP_ISS_FILE} "SolidCompression=yes\n")
file(APPEND ${VPP_ISS_FILE} "WizardStyle=modern\n")
file(APPEND ${VPP_ISS_FILE} "ChangesEnvironment=yes\n")
file(APPEND ${VPP_ISS_FILE} "Uninstallable=no\n")
file(APPEND ${VPP_ISS_FILE} "\n")
file(APPEND ${VPP_ISS_FILE} "[Languages]\n")
file(APPEND ${VPP_ISS_FILE} "Name: \"english\"; MessagesFile: \"compiler:Default.isl\"\n")
file(APPEND ${VPP_ISS_FILE} "\n")
file(APPEND ${VPP_ISS_FILE} "[Files]\n")
function(vpp_add_file file destination)
get_filename_component(file_name ${file} NAME)
get_filename_component(file_name_we ${file} NAME_WE)
string(REPLACE " " "_" file_name_we ${file_name_we})
file(APPEND ${VPP_ISS_FILE} " Source: \"${VPP_TEMP_DIR_NAT}\\${file_name}\"; DestDir: \"${destination}\"; Flags: ignoreversion\n")
add_custom_target(${file_name_we}_package COMMAND ${CMAKE_COMMAND} -E copy ${file} ${VPP_TEMP_DIR})
add_dependencies(${VPP_NAME}_package ${file_name_we}_package)
endfunction()
function(vpp_add_plugin target catfile)
get_target_property(PLUGIN_NAME ${target} LIBRARY_OUTPUT_NAME)
if(NOT PLUGIN_NAME)
set(PLUGIN_NAME "${target}")
endif()
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${catfile} $<TARGET_FILE_DIR:${target}>/${PLUGIN_NAME}.cat)
file(APPEND ${VPP_ISS_FILE} " Source: \"${VPP_TEMP_DIR_NAT}\\${PLUGIN_NAME}.dll\"; DestDir: \"{app}\"; Flags: ignoreversion\n")
file(APPEND ${VPP_ISS_FILE} " Source: \"${VPP_TEMP_DIR_NAT}\\${PLUGIN_NAME}.cat\"; DestDir: \"{app}\"; Flags: ignoreversion\n")
add_custom_target(${target}_package
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target}> ${VPP_TEMP_DIR}/${PLUGIN_NAME}.dll
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE_DIR:${target}>/${PLUGIN_NAME}.cat ${VPP_TEMP_DIR}/${PLUGIN_NAME}.cat
)
add_dependencies(${target}_package ${target})
add_dependencies(${VPP_NAME}_package ${target}_package)
endfunction(vpp_add_plugin)
find_program(ISCC_EXE "iscc" HINTS "C:/Program Files (x86)/Inno Setup 6" REQUIRED)
cmake_path(NATIVE_PATH ISCC_EXE ISCC_EXE_NAT)
cmake_path(NATIVE_PATH VPP_DIR VPP_DIR_NAT)
cmake_path(NATIVE_PATH VPP_ISS_FILE VPP_ISS_FILE_NAT)
file(WRITE ${VPP_SCRIPT} "\"${ISCC_EXE_NAT}\" /DMyAppVerName=\"${VPP_BUILD_TAG}\" /O\"${VPP_DIR_NAT}\" \"${VPP_ISS_FILE_NAT}\"\n")
if(VPP_NOTARIZE)
find_program(SIGNTOOL_EXE "signtool" HINTS "C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x64" REQUIRED)
cmake_path(NATIVE_PATH SIGNTOOL_EXE SIGNTOOL_EXE_NAT)
cmake_path(NATIVE_PATH VPP_PACKAGE VPP_PACKAGE_NAT)
cmake_path(NATIVE_PATH VPP_CODESIGN_WINDOWS_KEYFILE VPP_CODESIGN_WINDOWS_KEYFILE_NAT)
file(APPEND ${VPP_SCRIPT} "\"${SIGNTOOL_EXE_NAT}\" sign /f \"${VPP_CODESIGN_WINDOWS_KEYFILE_NAT}\" /p \"${VPP_CODESIGN_WINDOWS_KEYPASSWORD}\" /fd SHA256 /td SHA256 /tr http://timestamp.sectigo.com \"${VPP_PACKAGE_NAT}\"\n")
file(APPEND ${VPP_SCRIPT} "\"${SIGNTOOL_EXE_NAT}\" verify /pa \"${VPP_PACKAGE_NAT}\"\n")
endif()
add_custom_target(${VPP_NAME}_package ALL COMMAND ${VPP_SCRIPT} COMMENT "Packaging the Vamp plug-ins")
elseif(APPLE) # APPLE
set(VPP_PACKAGE "${VPP_DIR}/${VPP_NAME}-MacOS.pkg")
file(MAKE_DIRECTORY ${VPP_DIR})
set(VPP_TEMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/PkgTemp")
set(VPP_PACKAGE_SCRIPT "${VPP_TEMP_DIR}/package.sh")
set(VPP_DISRIB_XML "${VPP_TEMP_DIR}/distribution.xml")
set(VPP_TEMP1 "${VPP_TEMP_DIR}/temp1.xml")
set(VPP_TEMP2 "${VPP_TEMP_DIR}/temp2.xml")
set(VPP_TEMP3 "${VPP_TEMP_DIR}/temp3.xml")
set(VPP_NOTARIZE_LOG "${VPP_TEMP_DIR}/notarize.log")
set(VPP_INFO_LOG "${VPP_TEMP_DIR}/info.log")
file(WRITE ${VPP_PACKAGE_SCRIPT} "#!/bin/sh\n\n")
file(CHMOD ${VPP_PACKAGE_SCRIPT} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
if(EXISTS ${VPP_CHANGELOG_FILE})
file(COPY ${VPP_CHANGELOG_FILE} DESTINATION ${VPP_TEMP_DIR})
endif()
if(DEFINED CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_OSX_ARCHITECTURES STREQUAL "")
if(CMAKE_OSX_ARCHITECTURES STREQUAL "$(ARCHS_STANDARD)")
set(HOST_ARCH "x86_64,arm64")
else()
set(HOST_ARCH "${CMAKE_OSX_ARCHITECTURES}")
endif()
else()
set(HOST_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
endif()
file(WRITE ${VPP_TEMP1} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
file(APPEND ${VPP_TEMP1} "<installer-gui-script minSpecVersion=\"1\">\n")
file(APPEND ${VPP_TEMP1} " <title>${VPP_NAME} v${VPP_BUILD_TAG}</title>\n")
if(EXISTS ${VPP_ABOUT_FILE})
file(APPEND ${VPP_TEMP1} " <readme file=\"${VPP_ABOUT_FILE}\"/>\n")
endif()
if(EXISTS ${VPP_ICON_FILE})
file(APPEND ${VPP_TEMP1} " <background file=\"${VPP_ICON_FILE}\"/>\n")
file(APPEND ${VPP_TEMP1} " <background alignment=\"bottomleft\"/>\n")
endif()
file(APPEND ${VPP_TEMP1} " <options require-scripts=\"false\" customize=\"always\" hostArchitectures=\"${HOST_ARCH}\" rootVolumeOnly=\"true\"/>\n")
file(WRITE ${VPP_TEMP2} " <choices-outline>\n")
file(WRITE ${VPP_TEMP3} " </choices-outline>\n")
function(vpp_add_file file destination)
get_filename_component(file_name ${file} NAME)
get_filename_component(file_name_we ${file} NAME_WE)
string(REPLACE " " "_" file_name_we ${file_name_we})
string(TOLOWER "com.${VPP_COMPANY}.${file_name}.vamp.pkg" VPP_PACKAGE_UID)
file(MAKE_DIRECTORY ${VPP_TEMP_DIR}/${file_name_we})
file(COPY ${file} DESTINATION ${VPP_TEMP_DIR}/${file_name_we})
file(APPEND ${VPP_TEMP1} " <pkg-ref id=\"${VPP_PACKAGE_UID}\"/>\n")
file(APPEND ${VPP_TEMP2} " <line choice=\"${VPP_PACKAGE_UID}\"/>\n")
file(APPEND ${VPP_TEMP3} " <choice id=\"${VPP_PACKAGE_UID}\" visible=\"true\" start_selected=\"true\" title=\"${file_name}\"><pkg-ref id=\"${VPP_PACKAGE_UID}\"/></choice><pkg-ref id=\"${VPP_PACKAGE_UID}\" version=\"${VPP_BUILD_TAG}\" onConclusion=\"none\">${file_name}.pkg</pkg-ref>\n")
if(VPP_NOTARIZE)
set(PLUGIN_PKG_SCRIPT "${VPP_TEMP_DIR}/${file_name_we}.sh")
file(WRITE ${PLUGIN_PKG_SCRIPT} "#!/bin/sh\n\n")
file(CHMOD ${PLUGIN_PKG_SCRIPT} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
file(APPEND ${PLUGIN_PKG_SCRIPT} "codesign --sign \"${VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT}\" --entitlements \"${VPP_CODESIGN_ENTITLEMENTS}\" -f -o runtime --timestamp \"${VPP_TEMP_DIR}/${file_name_we}/${file_name}\"\n")
file(APPEND ${PLUGIN_PKG_SCRIPT} "pkgbuild --sign \"${VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT}\" --timestamp --root \"${VPP_TEMP_DIR}/${file_name_we}\" --identifier \"${VPP_PACKAGE_UID}\" --version \"${VPP_BUILD_TAG}\" --install-location \"${destination}/\" \"${VPP_TEMP_DIR}/${file_name}.pkg\"\n")
file(APPEND ${PLUGIN_PKG_SCRIPT} "pkgutil --check-signature \"${VPP_TEMP_DIR}/${file_name}.pkg\"\n")
add_custom_target(${file_name_we}_package COMMAND ${PLUGIN_PKG_SCRIPT})
else()
add_custom_target(${file_name_we}_package COMMAND pkgbuild --root "${VPP_TEMP_DIR}/${file_name_we}" --identifier "${VPP_PACKAGE_UID}" --version "${VPP_BUILD_TAG}" --install-location "${destination}/" "${VPP_TEMP_DIR}/${file_name}.pkg")
endif()
add_dependencies(${VPP_NAME}_package ${file_name_we}_package)
endfunction()
function(vpp_add_plugin target catfile)
get_target_property(PLUGIN_NAME ${target} LIBRARY_OUTPUT_NAME)
if(NOT PLUGIN_NAME)
set(PLUGIN_NAME "${target}")
endif()
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${catfile} "$<TARGET_FILE_DIR:${target}>/${PLUGIN_NAME}.cat")
string(TOLOWER "com.${VPP_COMPANY}.${PLUGIN_NAME}.vamp.pkg" VPP_PACKAGE_UID)
file(APPEND ${VPP_TEMP1} " <pkg-ref id=\"${VPP_PACKAGE_UID}\"/>\n")
file(APPEND ${VPP_TEMP2} " <line choice=\"${VPP_PACKAGE_UID}\"/>\n")
file(APPEND ${VPP_TEMP3} " <choice id=\"${VPP_PACKAGE_UID}\" visible=\"true\" start_selected=\"true\" title=\"${PLUGIN_NAME}\"><pkg-ref id=\"${VPP_PACKAGE_UID}\"/></choice><pkg-ref id=\"${VPP_PACKAGE_UID}\" version=\"${VPP_BUILD_TAG}\" onConclusion=\"none\">${target}.pkg</pkg-ref>\n")
if(VPP_NOTARIZE)
set(PLUGIN_PKG_SCRIPT "${VPP_TEMP_DIR}/${target}.sh")
file(WRITE ${PLUGIN_PKG_SCRIPT} "#!/bin/sh\n\n")
file(CHMOD ${PLUGIN_PKG_SCRIPT} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
file(APPEND ${PLUGIN_PKG_SCRIPT} "codesign --sign \"${VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT}\" --entitlements \"${VPP_CODESIGN_ENTITLEMENTS}\" -f -o runtime --timestamp \"$1/${PLUGIN_NAME}.cat\"\n")
file(APPEND ${PLUGIN_PKG_SCRIPT} "codesign --sign \"${VPP_CODESIGN_APPLE_DEV_ID_APPLICATION_CERT}\" --entitlements \"${VPP_CODESIGN_ENTITLEMENTS}\" -f -o runtime --timestamp \"$1/${PLUGIN_NAME}.dylib\"\n")
file(APPEND ${PLUGIN_PKG_SCRIPT} "pkgbuild --sign \"${VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT}\" --timestamp --root \"$1\" --identifier \"${VPP_PACKAGE_UID}\" --version \"${VPP_BUILD_TAG}\" --install-location \"/Library/Audio/Plug-Ins/Vamp/\" \"${VPP_TEMP_DIR}/${target}.pkg\"\n")
file(APPEND ${PLUGIN_PKG_SCRIPT} "pkgutil --check-signature \"${VPP_TEMP_DIR}/${target}.pkg\"\n")
add_custom_target(${target}_package COMMAND ${PLUGIN_PKG_SCRIPT} $<TARGET_FILE_DIR:${target}>)
else()
add_custom_target(${target}_package COMMAND pkgbuild --root $<TARGET_FILE_DIR:${target}> --identifier "${VPP_PACKAGE_UID}" --version "${VPP_BUILD_TAG}" --install-location "/Library/Audio/Plug-Ins/Vamp/" "${VPP_TEMP_DIR}/${target}.pkg")
endif()
add_dependencies(${target}_package ${target})
add_dependencies(${VPP_NAME}_package ${target}_package)
endfunction(vpp_add_plugin)
file(APPEND ${VPP_PACKAGE_SCRIPT} "cat ${VPP_TEMP1} ${VPP_TEMP2} ${VPP_TEMP3} > \"${VPP_DISRIB_XML}\"\n")
file(APPEND ${VPP_PACKAGE_SCRIPT} "echo \"</installer-gui-script>\\n\" >> \"${VPP_DISRIB_XML}\"\n")
if(VPP_NOTARIZE)
file(APPEND ${VPP_PACKAGE_SCRIPT} "productbuild --sign \"${VPP_CODESIGN_APPLE_DEV_ID_INSTALLER_CERT}\" --timestamp --distribution \"${VPP_DISRIB_XML}\" --package-path \"${VPP_TEMP_DIR}\" \"${VPP_PACKAGE}\"\n")
file(APPEND ${VPP_PACKAGE_SCRIPT} "xcrun notarytool submit \"${VPP_PACKAGE}\" --keychain-profile \"${VPP_CODESIGN_APPLE_KEYCHAIN_PROFILE_INSTALLER}\" --wait > \"${VPP_NOTARIZE_LOG}\" 2>&1\n")
file(APPEND ${VPP_PACKAGE_SCRIPT} "notaryid=$(awk '/^ id:/{sub(/^ id:/, \"\"); print; exit}' \"${VPP_NOTARIZE_LOG}\")\n")
file(APPEND ${VPP_PACKAGE_SCRIPT} "xcrun notarytool log $notaryid --keychain-profile \"${VPP_CODESIGN_APPLE_KEYCHAIN_PROFILE_INSTALLER}\" > \"${VPP_INFO_LOG}\" 2>&1\n")
file(APPEND ${VPP_PACKAGE_SCRIPT} "xcrun stapler staple \"${VPP_PACKAGE}\"\n")
file(APPEND ${VPP_PACKAGE_SCRIPT} "spctl -a -vvv -t install \"${VPP_PACKAGE}\"\n")
else()
file(APPEND ${VPP_PACKAGE_SCRIPT} "productbuild --distribution \"${VPP_DISRIB_XML}\" --package-path \"${VPP_TEMP_DIR}\" \"${VPP_PACKAGE}\"\n")
endif()
add_custom_target(${VPP_NAME}_package ALL COMMAND ${VPP_PACKAGE_SCRIPT})
elseif(UNIX) # LINUX
set(VPP_PACKAGE "${VPP_DIR}/${VPP_NAME}-Linux.tar.gz")
file(MAKE_DIRECTORY ${VPP_DIR})
set(VPP_TEMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/${VPP_NAME}")
file(MAKE_DIRECTORY ${VPP_TEMP_DIR})
if(EXISTS ${VPP_ABOUT_FILE})
file(COPY ${VPP_ABOUT_FILE} DESTINATION ${VPP_TEMP_DIR})
endif()
if(EXISTS ${VPP_CHANGELOG_FILE})
file(COPY ${VPP_CHANGELOG_FILE} DESTINATION ${VPP_TEMP_DIR})
endif()
set(VPP_INSTALL_SCRIPT "${VPP_TEMP_DIR}/Install.sh")
file(WRITE ${VPP_INSTALL_SCRIPT} "#!/bin/sh\n\n")
file(APPEND ${VPP_INSTALL_SCRIPT} "ThisPath=\"$( cd -- \"$(dirname \"$0\")\" >/dev/null 2>&1 ; pwd -P )\"\n")
file(APPEND ${VPP_INSTALL_SCRIPT} "mkdir -p $HOME/vamp\n")
file(CHMOD ${VPP_INSTALL_SCRIPT} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
set(VPP_UNINSTALL_SCRIPT "${VPP_TEMP_DIR}/Uninstall.sh")
file(WRITE ${VPP_UNINSTALL_SCRIPT} "#!/bin/sh\n\n")
file(CHMOD ${VPP_UNINSTALL_SCRIPT} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
function(vpp_add_file file destination)
get_filename_component(file_name ${file} NAME)
get_filename_component(file_name_we ${file} NAME_WE)
string(REPLACE " " "_" file_name_we ${file_name_we})
file(APPEND ${VPP_INSTALL_SCRIPT} "cp -f $ThisPath/${file_name} ${destination}\n")
file(APPEND ${VPP_UNINSTALL_SCRIPT} "rm -f ${destination}/${file_name}\n")
add_custom_target(${file_name_we}_package COMMAND ${CMAKE_COMMAND} -E copy ${file} ${VPP_TEMP_DIR})
add_dependencies(${VPP_NAME}_package ${file_name_we}_package)
endfunction()
function(vpp_add_plugin target catfile)
get_target_property(PLUGIN_NAME ${target} LIBRARY_OUTPUT_NAME)
if(NOT PLUGIN_NAME)
set(PLUGIN_NAME "${target}")
endif()
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${catfile} "$<TARGET_FILE_DIR:${target}>/${PLUGIN_NAME}.cat")
file(APPEND ${VPP_INSTALL_SCRIPT} "cp -f $ThisPath/${PLUGIN_NAME}.so $HOME/vamp\n")
file(APPEND ${VPP_INSTALL_SCRIPT} "cp -f $ThisPath/${PLUGIN_NAME}.cat $HOME/vamp\n")
file(APPEND ${VPP_UNINSTALL_SCRIPT} "rm -f $HOME/vamp/${PLUGIN_NAME}.so\n")
file(APPEND ${VPP_UNINSTALL_SCRIPT} "rm -f $HOME/vamp/${PLUGIN_NAME}.cat\n")
add_custom_target(${target}_package
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target}> ${VPP_TEMP_DIR}/${PLUGIN_NAME}.so
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE_DIR:${target}>/${PLUGIN_NAME}.cat ${VPP_TEMP_DIR}/${PLUGIN_NAME}.cat
)
add_dependencies(${target}_package ${target})
add_dependencies(${VPP_NAME}_package ${target}_package)
endfunction(vpp_add_plugin)
add_custom_target(${VPP_NAME}_package ALL COMMAND ${CMAKE_COMMAND} -E tar czf ${VPP_PACKAGE} ${VPP_TEMP_DIR})
endif()
# Setup the install rules for a plugin target
function(vpp_set_plugin_install target)
function(vpp_set_install_imp target destination)
get_target_property(TARGET_OUTPUT_NAME ${target} LIBRARY_OUTPUT_NAME)
install(TARGETS ${target} RUNTIME LIBRARY DESTINATION ${destination} PERMISSIONS OWNER_WRITE)
install(FILES $<TARGET_FILE_DIR:${target}>/${PLUGIN_NAME}.cat DESTINATION ${destination})
endfunction(vpp_set_install_imp)
if(APPLE)
vpp_set_install_imp(${target} "/Library/Audio/Plug-Ins/Vamp/")
elseif(UNIX)
vpp_set_install_imp(${target} "~/vamp/")
elseif(WIN32)
vpp_set_install_imp(${target} "$ENV{PROGRAMFILES}/Vamp Plugins/")
endif()
endfunction(vpp_set_plugin_install)
# Setup the debug rules for a plugin target with the Partiels application
function(vpp_set_plugin_debug target file)
if(NOT PARTIELS_EXE)
set(PREVIOUS_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
set(CMAKE_FIND_APPBUNDLE "FIRST")
if(PARTIELS_EXE_HINT_PATH)
find_program(PARTIELS_EXE "Partiels" HINTS ${PARTIELS_EXE_HINT_PATH} NO_DEFAULT_PATH)
else()
find_program(PARTIELS_EXE "Partiels")
endif()
if(PARTIELS_EXE)
if(NOT IS_DIRECTORY ${PARTIELS_EXE})
cmake_path(GET PARTIELS_EXE PARENT_PATH PARTIELS_EXE_PARENT)
cmake_path(SET PARTIELS_EXE NORMALIZE "${PARTIELS_EXE_PARENT}/../../")
endif()
else()
message(WARNING "Partiels executable not found")
endif()
set(CMAKE_FIND_APPBUNDLE ${PREVIOUS_CMAKE_FIND_APPBUNDLE})
endif()
if(PARTIELS_EXE)
message(STATUS "Debugging ${target} with ${PARTIELS_EXE}")
set_target_properties(${target} PROPERTIES XCODE_SCHEME_EXECUTABLE ${PARTIELS_EXE})
set_target_properties(${target} PROPERTIES XCODE_SCHEME_ARGUMENTS ${file})
set_target_properties(${target} PROPERTIES XCODE_SCHEME_ENVIRONMENT "VAMP_PATH=${CMAKE_CURRENT_BINARY_DIR}/Debug")
endif()
endfunction(vpp_set_plugin_debug)
# Downloads the Vamp Plugin Tester and create a CMake test all
# the generated plugins located in the build directory
function(vpp_enable_vamp_plugin_tester)
if(APPLE)
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester/vamp-plugin-tester)
file(DOWNLOAD "https://github.com/pierreguillot/vamp-plugin-tester/releases/download/1.1/vamp-plugin-tester-1.1-osx-arm.zip" "${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester.tar.gz")
file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester.tar.gz" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
elseif(UNIX)
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester/vamp-plugin-tester)
file(DOWNLOAD "https://github.com/pierreguillot/vamp-plugin-tester/releases/download/1.1/vamp-plugin-tester-1.1-linux64.tar.gz" "${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester.tar.gz")
file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester.tar.gz" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
elseif(WIN32)
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester/vamp-plugin-tester.exe)
file(DOWNLOAD "https://github.com/pierreguillot/vamp-plugin-tester/releases/download/1.1/vamp-plugin-tester-1.1a-win64.zip" "${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester.zip")
file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester.zip" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()
add_test(NAME VampPluginTester COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vamp-plugin-tester/vamp-plugin-tester -a)
set_tests_properties(VampPluginTester PROPERTIES ENVIRONMENT "$<IF:$<CONFIG:Debug>,VAMP_PATH=${CMAKE_CURRENT_BINARY_DIR}/Debug,VAMP_PATH=${CMAKE_CURRENT_BINARY_DIR}/Release>")
endfunction(vpp_enable_vamp_plugin_tester)
# Creates clang-format targets to check and apply the format
# to the sources
function(vpp_create_clang_format_targets prefixname sources)
find_program(CLANG_FORMAT_EXE "clang-format" HINTS "C:/Program Files/LLVM/bin")
if(CLANG_FORMAT_EXE)
add_custom_target(${prefixname}_check_format ${CLANG_FORMAT_EXE} --Werror --dry-run --verbose -style=file ${sources})
add_custom_target(${prefixname}_apply_format ${CLANG_FORMAT_EXE} -i -style=file ${sources})
else()
message(STATUS "Clang Format targets cannot be generated because clang-format is not found")
endif()
endfunction(vpp_create_clang_format_targets)
# Creates a manual target that generates a PDF from a markdown file
# The mdpdf executable is required
# The string APPVERSION is replaced by the version of the project
# The relative paths are replaced by the absolute paths
function(vpp_create_manual_target prefixname source version)
set(VPP_MANUAL_DIR ${CMAKE_CURRENT_BINARY_DIR}/Manual)
file(MAKE_DIRECTORY ${VPP_MANUAL_DIR})
get_filename_component(file_name ${source} NAME_WE)
get_filename_component(file_directory ${source} DIRECTORY)
file(READ ${source} MANUAL_CONTENT)
string(REPLACE "APPVERSION" "${version}" MANUAL_CONTENT ${MANUAL_CONTENT})
string(REPLACE "src=\"../" "src=\"${file_directory}/" MANUAL_CONTENT ${MANUAL_CONTENT})
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${file_name}.md ${MANUAL_CONTENT})
find_program(MDPDF_EXE "mdpdf")
if(MDPDF_EXE)
add_custom_target(${prefixname}_manual COMMAND ${MDPDF_EXE} ${CMAKE_CURRENT_BINARY_DIR}/${file_name}.md ${VPP_MANUAL_DIR}/${file_name}.pdf VERBATIM)
else()
message(STATUS "Manual target cannot be generated because mdpdf is not found")
endif()
endfunction(vpp_create_manual_target)