-
Notifications
You must be signed in to change notification settings - Fork 419
Add support for Apple framework builds #2020
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
Merged
jstone-lucasfilm
merged 15 commits into
AcademySoftwareFoundation:main
from
dgovil:framework
Sep 25, 2024
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
73d06b0
Support building for non-iOS embedded platfoms like visionOS using st…
dgovil ea68dd1
Add support for building a framework (adapted from OpenUSD)
dgovil 07aef1e
Add lookup of framework resources path in MaterialX
dgovil fb5b456
Fix MaterialX build number conflict in CMake
dgovil f336b98
Make default search path additively add the framework search path
dgovil 81d2f35
Change iOS CI
dgovil 353d099
Default framework build to if shared libs is on or not
dgovil 21ddbdf
Add missing newline
jstone-lucasfilm 371ee29
Add missing newline
jstone-lucasfilm 179b7b7
Move the incrementing build version closer to where the Plist is gene…
dgovil 0dc1517
Minor updates to formatting
jstone-lucasfilm b557ad6
Use default constructor
jstone-lucasfilm d43c48b
Inline getSharedLibraryPath to the location its called within
dgovil c7c4ab0
Merge remote-tracking branch 'dhruv/framework' into framework
dgovil dda9d6d
Remove extra whitespace line
dgovil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/bin/zsh | ||
|
|
||
| # Creates an Apple framework for the given platform type | ||
| # documentation: https://developer.apple.com/documentation/bundleresources/placing_content_in_a_bundle | ||
| # https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html | ||
| echo "⌛️ Creating MaterialX.framework ..." | ||
|
|
||
| # Variables are substituted by CMake | ||
| CMAKE_INSTALL_PREFIX="@CMAKE_INSTALL_PREFIX@" | ||
| PROJECT_BINARY_DIR="@PROJECT_BINARY_DIR@" | ||
|
|
||
| FRAMEWORK_NAME="MaterialX" | ||
| FRAMEWORK_DIR="${CMAKE_INSTALL_PREFIX}/frameworks/${FRAMEWORK_NAME}.framework" | ||
| FRAMEWORK_LIBRARIES_DIR="${FRAMEWORK_DIR}/Libraries" | ||
| FRAMEWORK_ROOT_LIBRARY_NAME="libMaterialX.@MATERIALX_LIBRARY_VERSION@.dylib" | ||
| EMBEDDED_BUILD=@__embedded_build@ | ||
| FRAMEWORK_RESOURCES_DIR="${FRAMEWORK_DIR}" | ||
| MATERIALX_SOURCE_LIBRARIES="${CMAKE_INSTALL_PREFIX}/libraries/" | ||
| BUNDLE_IDENTIFIER="org.aswf.materialx" | ||
| CODESIGN_ID="@CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY@" | ||
| OLD_RC_PATH="${CMAKE_INSTALL_PREFIX}/lib" | ||
|
|
||
| function fix_linkage() { | ||
| readonly file=${1:?"A file path must be specified."} | ||
| readonly prepend="${FRAMEWORK_NAME}.framework/Libraries" | ||
| filename=$(basename ${file}) | ||
| # First, change the install name. This corresponds to LC_ID_DYLIB. | ||
| install_name_tool -id "@rpath/${prepend}/${filename}" ${file} | ||
|
|
||
| parts=("${(@f)$(otool -l ${file})}") | ||
| for line in ${parts}; do | ||
| dylib_name="" | ||
| [[ $line =~ ' *name @rpath/(.*\.dylib)' ]] && dylib_name=$match[1] | ||
| if [ -n "${dylib_name}" ]; then | ||
| install_name_tool -change "@rpath/${dylib_name}" "@rpath/${prepend}/${dylib_name}" "${file}" | ||
| fi | ||
| if [[ $line == *"${OLD_RC_PATH}"* ]]; then | ||
| install_name_tool -delete_rpath ${OLD_RC_PATH} ${file} | ||
| fi | ||
| done | ||
|
|
||
| codesign -f -s ${CODESIGN_ID} ${file} | ||
| } | ||
|
|
||
| # Remove the existing directory if it exists | ||
| if [ -d ${FRAMEWORK_DIR} ]; then | ||
| echo "Removing existing framework"; | ||
| rm -Rf ${FRAMEWORK_DIR}; | ||
| fi | ||
|
|
||
| # Create the parent directory | ||
| echo "Creating Framework Directory: ${FRAMEWORK_DIR}" | ||
| mkdir -p ${FRAMEWORK_DIR} | ||
|
|
||
| if [ "$EMBEDDED_BUILD" = true ];then | ||
| FRAMEWORK_RESOURCES_DIR="${FRAMEWORK_DIR}/Resources" | ||
| FRAMEWORK_PLIST_LOCATION="${FRAMEWORK_DIR}/Info.plist" | ||
| FRAMEWORK_HEADERS_DIR="${FRAMEWORK_DIR}/Headers" | ||
| FRAMEWORK_LIB_PATH=""${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"" | ||
| else | ||
| FRAMEWORK_RESOURCES_DIR="${FRAMEWORK_DIR}/Versions/A/Resources/" | ||
| FRAMEWORK_PLIST_LOCATION="${FRAMEWORK_DIR}/Versions/A/Resources/Info.plist" | ||
| FRAMEWORK_HEADERS_DIR="${FRAMEWORK_DIR}/Versions/A/Headers" | ||
| FRAMEWORK_LIB_PATH="${FRAMEWORK_DIR}/Versions/A/${FRAMEWORK_NAME}" | ||
| fi | ||
|
|
||
| echo "Creating Resources Root: ${FRAMEWORK_RESOURCES_DIR}" | ||
| mkdir -p ${FRAMEWORK_RESOURCES_DIR} | ||
|
|
||
| echo "Creating Headers Root: ${FRAMEWORK_HEADERS_DIR}" | ||
| mkdir -p ${FRAMEWORK_HEADERS_DIR} | ||
|
|
||
| # Copy the plist over | ||
| echo "Copying files into ${FRAMEWORK_DIR}" | ||
| ditto "${PROJECT_BINARY_DIR}/Info.plist" "${FRAMEWORK_PLIST_LOCATION}" | ||
|
|
||
| # Copy the primary directories over | ||
| ditto "${CMAKE_INSTALL_PREFIX}/include/" ${FRAMEWORK_HEADERS_DIR} | ||
| ditto "${CMAKE_INSTALL_PREFIX}/libraries/" "${FRAMEWORK_RESOURCES_DIR}/libraries" | ||
| ditto "${CMAKE_INSTALL_PREFIX}/resources" "${FRAMEWORK_RESOURCES_DIR}/render" | ||
|
|
||
| cp "${CMAKE_INSTALL_PREFIX}/lib/${FRAMEWORK_ROOT_LIBRARY_NAME}" "${FRAMEWORK_LIB_PATH}" | ||
|
|
||
| # Setup symlinks | ||
| if [ "$EMBEDDED_BUILD" = false ];then | ||
| (cd "${FRAMEWORK_DIR}/Versions" && ln -s "A" "Current") | ||
| (cd ${FRAMEWORK_DIR} && ln -s "Versions/Current/Resources" "Resources") | ||
| (cd ${FRAMEWORK_DIR} && ln -s "Versions/Current/Headers" "Headers") | ||
| (cd ${FRAMEWORK_DIR} && ln -s "Versions/Current/${FRAMEWORK_NAME}" ${FRAMEWORK_NAME}) | ||
| fi | ||
|
|
||
| # Fix the linkage on the primary dylib | ||
| fix_linkage "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}" | ||
| install_name_tool -id "@rpath/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}" | ||
| install_name_tool -change "@rpath/${FRAMEWORK_NAME}.framework/Libraries/${FRAMEWORK_NAME}" "@rpath/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}" | ||
|
|
||
| # Frameworks require all includes to use the framework name as the prefix for automatic discovery | ||
| echo "Modifying headers..." | ||
| HEADER_SET="" | ||
| for i in $(cd $FRAMEWORK_HEADERS_DIR && ls -d */ | cut -f1 -d'/');do | ||
| HEADER_SET+="${i}|" | ||
| done; | ||
| # Sed on macOS is POSIX compliant and so uses different args than GNU | ||
| # Things to be aware of are [[:<:]] and [[:>:]] are for word boundaries and spaces are explicit literals | ||
| INCLUDE_PATTERN="^# *include [\"|<]([[:<:]](${HEADER_SET::-1})[[:>:]].*)[\"|>].*$" | ||
| find ${FRAMEWORK_HEADERS_DIR} -type f -name "*.h*" -print0 | xargs -0 sed -i "" -E "s,${INCLUDE_PATTERN},#include <${FRAMEWORK_NAME}/\1>,g" | ||
|
|
||
| # Sign the final framework | ||
| echo "Codesigning the framework..." | ||
| set -e | ||
| codesign --force --sign ${CODESIGN_ID} --generate-entitlement-der --identifier ${BUNDLE_IDENTIFIER} --verbose ${FRAMEWORK_DIR} | ||
|
|
||
| echo "✅ Finished creating framework at ${FRAMEWORK_DIR}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>en</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>MaterialX</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>org.aswf.materialx</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>MaterialX</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>FMWK</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>@MATERIALX_LIBRARY_VERSION@</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>@CFBUNDLEVERSION@</string> | ||
| <key>CSResourcesFileMapped</key> | ||
| <true /> | ||
| </dict> | ||
| </plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.