Skip to content

Commit 50f2977

Browse files
committed
Add opt-in option to prefix headers
1 parent 0729140 commit 50f2977

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,18 @@ Builds for Apple platforms may optionally build as a framework using the `--buil
182182
- Building a universal macOS framework is currently not supported. Please generate the arches separately and `lipo`
183183
them together after.
184184

185-
To add the Framework to your application, simply add `OpenUSD.framework` to your Xcode project.
185+
To add the Framework to your application, add `OpenUSD.framework` to your Xcode project.
186186
It is recommended to set it to `Embed and Sign`.
187187

188-
When including sources from the Framework, you must prefix the include with the framework name.
189-
However, you should note that these includes are not portable to non-framework builds.
190-
e.g `#include <OpenUSD/pxr/pxr.h>`
188+
To setup headers, you may then choose one of two routes:
191189

192-
Optionally, if you want to avoid prefixed includes for your cross platform code, you can manually add the search path
193-
by setting `SYSTEM_HEADER_SEARCH_PATHS` in your Xcode target to the Headers directory within the framework.
194-
For example, if your Framework folder is in your project, under a folder with the same name as your target, you would
195-
set it as `$(SRCROOT)/$(TARGET_NAME)/OpenUSD.framework/Headers`.
190+
1. Configure the Xcode `SYSTEM_HEADER_SEARCH_PATHS` to add the path to your headers. e.g
191+
`$(SRCROOT)/OpenUSD.framework/Headers` if the framework exists in your projects root. This is recommended
192+
if you intend to share source files with other platforms.
193+
194+
2. Build with `--prefix-framework-headers` (or `-DPXR_APPLE_PREFIX_FRAMEWORK_HEADERS=ON` if using CMake)
195+
to automatically process the frameworks headers. This requires no extra configuration in Xcode, but does require
196+
that all includes be prefixed with the name of the framework. e.g `#include <OpenUSD/pxr/pxr.h>`
196197

197198
OpenUSD also supports building a combined XCFramework as well of multiple targets.
198199
This command takes an optional list of targets to build, but will otherwise build all supported platforms.

build_scripts/build_usd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,7 @@ def InstallUSD(context, force, buildArgs):
18651865
extraArgs.append('-DCMAKE_CXX_FLAGS="/Zm150"')
18661866
if MacOS():
18671867
extraArgs.append(f"-DPXR_BUILD_APPLE_FRAMEWORK={'ON' if context.buildAppleFramework else 'OFF'}")
1868+
extraArgs.append(f"-DPXR_APPLE_PREFIX_FRAMEWORK_HEADERS={'ON' if context.prefixFrameworkHeaders else 'OFF'}")
18681869

18691870
# Make sure to use boost installed by the build script and not any
18701871
# system installed boost
@@ -1997,6 +1998,8 @@ def InstallUSD(context, force, buildArgs):
19971998
help="Build USD as an Apple Framework (Default if using build)")
19981999
subgroup.add_argument("--no-build-apple-framework", dest="no_build_apple_framework", action="store_true",
19992000
help="Do not build USD as an Apple Framework (Default if macOS)")
2001+
group.add_argument("--prefix-framework-headers", dest="prefix_framework_headers", action="store_true",
2002+
help="Add the Framework as a prefix to header includes so that they can automatically be included.")
20002003

20012004
if apple_utils.IsHostArm():
20022005
# Intel Homebrew stores packages in /usr/local which unfortunately can
@@ -2348,6 +2351,7 @@ def __init__(self, args):
23482351

23492352
self.buildAppleFramework = ((args.build_apple_framework or MacOSTargetEmbedded(self))
23502353
and not args.no_build_apple_framework)
2354+
self.prefixFrameworkHeaders = args.prefix_framework_headers and self.buildAppleFramework
23512355
if self.buildAppleFramework and not args.build_type:
23522356
self.buildShared = False
23532357
self.buildMonolithic = True

cmake/defaults/Options.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if(APPLE)
7070
endif ()
7171

7272
option(PXR_BUILD_APPLE_FRAMEWORK "Builds an Apple Framework." ${PXR_APPLE_EMBEDDED})
73-
option(PXR_APPLE_APPLY_HEADER_PREFIX "Prefix the headers in framework builds" ON )
73+
option(PXR_APPLE_PREFIX_FRAMEWORK_HEADERS "Prefix the headers in framework builds" OFF )
7474
set(PXR_APPLE_FRAMEWORK_NAME "OpenUSD" CACHE STRING "Name to provide Apple Framework build")
7575
set(PXR_APPLE_IDENTIFIER_DOMAIN "org.openusd" CACHE STRING "Name to provide Apple Framework build")
7676
if (${PXR_BUILD_APPLE_FRAMEWORK})

cmake/macros/Public.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ function(pxr_create_apple_framework)
14641464
set(EMBEDDED_BUILD "false")
14651465
endif()
14661466

1467-
if (PXR_APPLE_APPLY_HEADER_PREFIX)
1467+
if (PXR_APPLE_PREFIX_FRAMEWORK_HEADERS)
14681468
set(APPLY_HEADER_PREFIX "true")
14691469
else()
14701470
set(APPLY_HEADER_PREFIX "false")

0 commit comments

Comments
 (0)