Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple: Build as framework, and support visionOS #2020

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

dgovil
Copy link
Contributor

@dgovil dgovil commented Sep 17, 2024

This PR makes a few changes that have been derived from a corresponding PR to USD PixarAnimationStudios/OpenUSD#2969

The changes are:

  1. Deprecates MATERIALX_BUILD_IOS in favor of using CMAKE_SYSTEM_NAME. This allows for better support for iPhone derived targets like visionOS. Earlier this would force it to iOS which can cause subtle issues when compiled against other SDKs. See https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-visionos-or-watchos

  2. Changes TARGET_OS_IOS define to TARGET_OS_IPHONE which is more correct to support iPhone derivatives. See https://chaosinmotion.com/2021/08/02/things-to-remember-compiler-conditionals-for-macos-ios-etc/ . But the gist is TARGET_OS_IOS refers specifically to the modern iOS/iPadOS SDK, whereas TARGET_OS_IPHONE refers to all Apple SDKs that derived from the original iPhone.

  3. Add support for building as a Framework. This creates a special directory structure that streamlines embedding of MaterialX within Apps on Apple platforms to just dragging the project into the app in Xcode. No other linker and compiler configuration is necessary. See Framework notes below.

  4. Adds a new getSharedLibraryPath function on Apple platforms that finds the path that contains the dylib, instead of just the executable that is ultimately linking to the dylib. I didn't implement this for Windows/Linux since there's only one the one need for it right now. This is derived from USD's method to do the same.

  5. Additionally, I've added a MATERIALX_BUILD_IDENTIFIER that mirrors how USD generates a single integer build number for its namespace. I only use this within the Plist for the framework since it requires the identifier version to be an incrementing integer.

Framework notes

I have opted to use a zsh to keep this consistent with the PR for USD, rather than use CMake's built in Framework generation. This is also because, either way, I need to do some processing to the headers (see below) , fixing of linkage etc so it's simpler to just do it all in one spot.

Zsh is always guaranteed to exist on any macOS in the last several years.

The zsh script also modifies the Headers because Clang will automatically add frameworks to the include search path, as long as the include starts with the frameworks name. This means that #include <MaterialXCore/Document.h> now needs to be #include <MaterialX/MaterialXCore/Document.h>. However if your code requires the unprefixed version, you can still manually add the Header directory in the framework and it'll work as it normally would.

One other advantage to using the Zsh script as a post process is that you still get a standard build of the libraries too in case you want to use them otherwise, and you also can fix issues in the Framework without doing a full rebuild.

…andard CMake directives.

Also remove TARGET_OS_IOS in favor of the more correct TARGET_OS_IPHONE

Signed-off-by: Dhruv Govil <dgovil2@apple.com>
Signed-off-by: Dhruv Govil <dgovil2@apple.com>
Signed-off-by: Dhruv Govil <dgovil2@apple.com>
Signed-off-by: Dhruv Govil <dgovil2@apple.com>
Signed-off-by: Dhruv Govil <dgovil2@apple.com>
@jstone-lucasfilm
Copy link
Member

@dgovil Should this changelist include corresponding updates to our GitHub CI, so that the new, recommended pattern for iOS builds is validated for current and future commits?

https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/.github/workflows/main.yml#L94

Signed-off-by: Dhruv Govil <dgovil2@apple.com>
@dgovil
Copy link
Contributor Author

dgovil commented Sep 17, 2024

Ah good catch, I'd missed that hidden folder.
Changed it over.

Signed-off-by: Dhruv Govil <dgovil2@apple.com>
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
CMakeLists.txt Outdated Show resolved Hide resolved
…rated.

Signed-off-by: Dhruv Govil <dgovil2@apple.com>
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks @dgovil! I'm CC'ing @ld-kerley in case he has additional thoughts and recommendations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants