macOS 开发

内容表

要求

Plugin development on macOS is only supported with Apple Xcode. The supported versions are:

  • Cinema 4D R23 SDK : Xcode 11.3 (or Xcode 12 for Universal Binaries)
  • Cinema 4D S22 SDK : Xcode 11.1
  • Cinema 4D R21 SDK : Xcode 10.3.1
  • Cinema 4D R20 SDK : Xcode 9
  • Cinema 4D R19 SDK : Xcode 8
  • Cinema 4D R18 SDK : Xcode 7
  • Cinema 4D R17 SDK : Xcode 6.0.1
  • Cinema 4D R16 SDK : Xcode 5.0.2
  • Cinema 4D R15 SDK : Xcode 4.6.3
  • Cinema 4D R14 SDK : Xcode 4.3.2
  • Cinema 4D R13 SDK : Xcode 3.2.6

(*) It is recommended to enable the legacy build system under "File" / "Project Settings" / "Section Shared Project Settings/Build System" / "Legacy Build System"

环境

No special configuration of the development environment is necessary.

最佳实践

macOS 特定代码

macOS specific code can be guarded with the macro MAXON_TARGET_MACOS:

#ifdef MAXON_TARGET_MACOS

#endif

通用二进制

Since Cinema 4D R23 Service Pack 1, it's possible to build plugins as 通用二进制 to run them both on Intel-based and ARM-based hardware.

To build 通用二进制 the following development environment is required:

Aside from regenerating the project using the Project Tool, if the plugin's code is fully relying on Cinema 4D APIs, no changes are needed and rebuilding the project will suffice to generate universal binaries running on both platforms.

In case one of the two architectures is not required you can deactivate it by:

第 3 方库支持

If your plugin makes use of 3rd-party libraries, it's recommended to port the library on Apple Silicon - as recommended here - before attempting to build the whole Cinema 4D plugin to streamline the porting process.

运行插件

It is possible to start Cinema 4D from Xcode to run and debug a plugin:

调试

The 控制台 displays messages printed with DiagnosticOutput() 。见 Debug and Output Functions .

For general information on debugging see 调试 .

自动化流程

The execution of the Project Tool can easily be automated using bash scripts.

This bash script executes the Project Tool on the given location of the SDK and starts Xcode to open the solution file:

# build SDK

# run project tool /Volumes/development/projecttool/kernel_app.app/Contents/MacOS/kernel_app g_updateproject=/Volumes/development/sdk_extracted
# open xcode open -a "/Applications/Xcode 9.app/Contents/MacOS/Xcode" /Volumes/development/sdk_extracted/plugins/project/plugins.xcodeproj

This bash script starts Cinema 4D with the location of the plugins:

# run C4D open -a "/Volumes/development/cinema_4d/CINEMA 4D.app/Contents/MacOS/CINEMA 4D" --args -g_additionalModulePath=/Volumes/development/sdk_extracted/plugins

Additionally one can set the command line argument g_runUnitTests to automatically execute custom unit tests.

Cinema 4D can be informed on the type of license model to use - which can be helpful in certain automated tasks - by using:

DYLIBs

DYLIBs needed by a plugin can be placed in myplugin\res\libs\osx .

部署

The final plugin build for deployment should be created using the "Release" build target.

公证

Since macOS Catalina 10.15, all Mac software distributed outside the Mac App Store must be notarized by Apple in order to run by default.

The notarization process beside involving Mac applications, also applies to plugins that are supposed to run in notarized applications.

The notarization process is different depending on the type of file to be notarized (an app or a plugin) or on the final archiving strategy used to deploy the plugin. The notary service accepts disk images (UDIF format), signed flat installer packages, and ZIP archives.

Requirements:

预备步骤

Notarization requires Xcode 10 or later. Building a new app for notarization requires macOS 10.13.6 or later.

Apple's notary service requires you to adopt the following protections:

Apple 开发者程序

Before the Apple notary service process a binary, it's mandatory to have the binary signed with a valid Apple Developer ID certificate. In case of signing applications or plugins signing the binary requires a Developer ID Application certificate. Such a certificate can be obtained once enrolled to the Apple Developer Program either as individual or as an organization.

The Apple Developer Program is not free and an yearly fee is due to get full membership and generate the Developer ID signing certificates. See Apple 开发者程序 for further details.

注意
It's important that the Apple ID used to sign-in in the Apple 开发者程序 has the two-factor authentication turned on. This authentication mechanism can allow the user to create application password which are used to invoke the command line executable responsible to execute the notarization procedure. This application password is later on referred as YourAppPassword .
At least one Apple ID registered to the Apple Developer Program should be used in Xcode and listed among the available Accounts

Upon adding an Apple ID owning developer credentials you can add a certificate by clicking on Manage Certificates

the clicking on +

and finally selecting Developer ID Application

Xcode 中的代码签名

Signing a binary in Xcode is required to successfully complete the notarization process as described in 预备步骤 .

To prepare a project to undergo the notarization process the signing options needs to be specified for the project responsible to generate the binary to be notarized.

Given such a project, select the Targets settings and filter for the string "Signing"

change the values for the following parameters:

Upon settings up the signing parameters a 发行 binary of the plugin must be generated by clicking on Product -> Build For -> Profiling .

包含 ZIP 的插件公证

After the creation of the release binary, a ZIP archive should be created containing the plugin and all the other needed files. Considering the case of the cinema4dsdk plugin, upon moving the cinema4dsdk.xlib res folder in a proper folder, to create a zip archive of the files, from a Terminal window, execute:

% cd <parent folder of cinema4dsdk> % /usr/bin/ditto -c -k --keepParent "<YourPluginFolder>" "<YourZipPluginArchive>"

Later on in the process it's requested to provide the value for the ASC-provider:to retrieve the list of allowed providers, from a Terminal window, execute:

% xcrun altool --list-providers -u <YourAppleID> -p <YourAppPassword>

and, if successfully executed, the tool should return

ProviderName ProviderShortname WWDRTeamID ------------------- ----------------- ---------- <your account name> XXXXXXXXXX XXXXXXXXXX

To submit the zip-archive to Apple to complete the notarization process, from a Terminal window, execute:

% xcrun altool --notarize-app --primary-bundle-id <YourBundleID> --username <YourAppleID> --password <YourAppPassword> --asc-provider <YourASCProvider> --file <YourZipPluginArchive>

and, if successfully executed, the tool should return

No errors uploading '<YourZipPluginArchive>' . RequestUUID = <YourRequestUUID>
注意
The RequestUUID represents the notarization request unique identifier and must be used when further details are queried from Apple about the state of the process.

Within a certain amount of time, Apple Notary Service notifies the user about the notarization process being finished by sending an email to the address bound to the registered Apple ID.

Finally it's possible at anytime to check the notarization queue executing

% xcrun altool --notarization-history 0 -u <YourAppleID> -p <YourAppPassword>

and, if successfully executed, the tool should return something like

Notarization History - page 0 Date RequestUUID Status Status Code Status Message ------------------------- ------------------------------------ ------- ----------- ---------------- 2019-11-28 16:39:40 +0000 <YourRequestUUID> success 0 Package Approved Next page value: 1574959180000
注意
Upon the package is approved, it can be safely deployed to customers, since, from that moment on, macOS can be acknowledged by Apple to be allowed to run the binary(-ies).
警告
The notarization process must be repeated everytime the binaries in the archive are changed.

延伸阅读