Development for macOS

Requirements

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

  • 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

Environment

No special configuration of the development environment is necessary.

Best Practice

macOS Specific Code

macOS specific code can be guarded with the macro MAXON_TARGET_MACOS:

#ifdef MAXON_TARGET_MACOS
#endif

Running Plugins

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

  • In the plugin project scheme set "Run"->"Run" "Info"->"Executable" to the location of a Cinema 4D executable.
  • Under "Arguments" add and set the command line argument g_additionalModulePath to make sure that this Cinema 4D executable will find and load the plugin.

Debugging

The Console displays messages printed with DiagnosticOutput(). See Debug and Output Functions.

For general information on debugging see Debugging.

Automating Processes

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.

DYLIBs

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

Note
DYLIBs make use of install name to inform where to find the library at runtime, it's mandatory to properly specify this value before building the dynamic library.

The install name can be set via the Installation Directory parameter in the "Build Settings" section of the DYLIB Xcode project or by manually specifying INSTALL_PATH=... in the "CBuildConfiguration section" of the related project.pbxproj file

Values for the install name can be:

  • @rpath: the plugin will use the path specified in its own project Runtime Search Path parameter to find the DYLIB;
  • @loader_path: the plugin will use the path assembled starting from its own position being the plugin itself responsible to load the DYLIB.

Compiled DYLIBs can be checked for their install name using:

otool -l <yourlib>.dylib

and finding the value in the "name" parameter inside the "Load command 2" section.

The "install name" of compiled DYLIBs can be changed using:

install_name_tool -id "<new install name>" <yourlib>.dylib

Deployment

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

Further Reading