-
Notifications
You must be signed in to change notification settings - Fork 312
fix: macOS universal build #1171
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
Open
atteneder
wants to merge
27
commits into
KhronosGroup:main
Choose a base branch
from
atteneder:fix/macOS-universal-5.0.0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6fdd27b
fix: Restored ability to build universal macOS binaries.
atteneder 0caddb8
fix: Building a universal macOS binary should work with generators ot…
atteneder 9bf4fb0
fix: Don't apply BasisU x86_64 SSE 4.1 patch on non-macOS systems.
atteneder 89c6040
feat: Explicitly deny CMAKE_OSX_ARCHITECTURES value `$(ARCHS_STANDARD…
atteneder 4de37d0
doc: Updated building documentation.
atteneder 100305f
fix: Conditional option `BASISU_SSE` is shown for macOS universal bui…
atteneder a86c3bf
chore: Removed out-dated arch detection code in `set_target_processor…
atteneder 13569f3
feat: CMake option `LIBKTX_FEATURE_BASISU_SSE` allows enabling/disabl…
atteneder 3ba2c2e
refactor: Renamed variables to match style and applied CMake best pra…
atteneder 5ad855f
fix: Set `APPLE_MAC_OS` to `ON` when targeting macOS only.
atteneder 6d90108
fix: Enable x86 (32-bit) builds for Android only.
atteneder 74d0c8b
fix: Propagate all ASTC encoder dependency.
atteneder 96cc11f
doc: Added pointer to macOS CMAKE_OSX_ARCHITECTURES handling from `cp…
atteneder b0e7fd5
fix: `CMAKE_SYSTEM_NAME` might not be set, so assume macOS as default…
atteneder 1c87c65
fix: Don't reject $(ARCHS_STANDARD) literal as macOS architecture set…
atteneder 7a67f3d
fix: Don't link ASTC encoders into `ktx_read`
atteneder 946421a
Revert "fix: Don't link ASTC encoders into `ktx_read`"
atteneder c51e808
fix: Moved special handling of macOS architecture "$(ARCHS_STANDARD)"…
atteneder 4cd7732
chore: Removed obsolete armv8 iOS architecture setting.
atteneder 9dc7a3b
Revert "doc: Updated building documentation."
atteneder aab5417
doc: Removed outdated warning
atteneder 2b0cdfa
refactor: Centralized where macOS architecture is handled for `libktx`.
atteneder 2982ebb
fix: Reversed renaming of ASTCENC_UNIVERSAL_BUILD to ASTCENC_APPLE_MA…
atteneder 52697f5
fix: Prepare code eventual change of which architecture(s) Xcode's `$…
atteneder 8c266a4
chore: Removed outdated compile option `-msse4.1`.
atteneder 1be79ba
refactor: `BASISU_SSE` is `FALSE` on non-x86_64 architecture anyways,…
atteneder 0ad1fc3
fix: Typo
atteneder 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 |
|---|---|---|
|
|
@@ -109,51 +109,39 @@ function(set_target_processor_type out) | |
| else() | ||
| # Apple's clang is a single compiler whose target is determined by | ||
| # its -arch <architecture> or --target=<architecture> options | ||
| # defaulting to the processor of the Mac it is running on. CMake does | ||
| # not set this directly when generating for Xcode. (I don't know what | ||
| # it does when generating makefiles. Therefore, in the Xcode case, | ||
| # compiling cputypetest.c with CMAKE_{C,CXX}_COMPILER results in | ||
| # processor being set to x86_86 or arm64 depending on the Mac it is | ||
| # running on. | ||
| # defaulting to the processor of the Mac it is running on. CMake | ||
| # does not set this directly when generating for Xcode, so probing | ||
| # cputypetest.c with CMAKE_{C,CXX}_COMPILER yields the host arch | ||
| # (x86_64 or arm64). | ||
| # | ||
| # When building for iOS, only CMAKE_SYSTEN_NAME is specified during | ||
| # configuration. CMake leaves it up to Xcode or to the user passing | ||
| # a -sdk argument to xcbuild to make sure the correct <architecture> | ||
| # is set when calling the compiler. | ||
| # For iOS/tvOS/visionOS, CMake only sets CMAKE_SYSTEM_NAME during | ||
| # configuration. The actual ARM target is selected later by Xcode | ||
| # or by an -sdk argument to xcodebuild. | ||
| # | ||
| # When building for macOS (and possibly for iOS, not tested) the | ||
| # user can specify CMAKE_OSX_ARCHITECTURES if they want to compile | ||
| # for something different than the current processor. This could be | ||
| # set to $(ARCHS_STANDARD) an Xcode build setting whose value in | ||
| # recent Xcode versions is "x86_64 arm64" to create universal binaries. | ||
| # This is passed to Xcode which calls the compiler twice passing the | ||
| # same set of target_definitions each time so in this case we have | ||
| # to choose BASISU_SUPPORT_SSE=OFF or the arm64 compile will fail. | ||
| # For macOS the caller may set CMAKE_OSX_ARCHITECTURES to a single | ||
| # arch (e.g. "x86_64" or "arm64") or to a list ("arm64;x86_64") to | ||
| # request a universal build. The literal "$(ARCHS_STANDARD)" is | ||
| # rejected by the root CMakeLists.txt because CMake stores it | ||
| # unexpanded and breaks $<TARGET_OBJECTS:...> paths. | ||
|
MarkCallow marked this conversation as resolved.
Outdated
|
||
| # | ||
| # The following code reflects all this. | ||
| # Multi-arch (universal) note: CPU_ARCHITECTURE here is just one | ||
| # representative arch — the universal-aware code paths in | ||
| # lib/CMakeLists.txt key off `universal_build` and the per-arch | ||
| # `arch_arm64`/`arch_x86_64` flags instead. In particular, | ||
| # BASISU_SSE is forced off for universal builds and the x86_64 | ||
| # slice gets -msse4.1 re-enabled per-arch via -Xarch_x86_64. | ||
| if(APPLE AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") | ||
| # Building for iOS, iPadOS, etc. Since we don't care what | ||
| # type of ARM processor, arbitrarily set armv8. | ||
| # It should be arm64 but there is a check in tests/CMakeLists.txt | ||
| # that is dropping loadtests for Apple Silicon arm64. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should fix this and tests/CMakeLists.txt. I don't recall why it wants to drop loadtests for Apple Silicon arm64. |
||
| set(processor armv8) | ||
| elseif(APPLE AND CMAKE_OSX_ARCHITECTURES) | ||
| string(STRIP "${CMAKE_OSX_ARCHITECTURES}" architectures) | ||
| if("${architectures}" STREQUAL "$(ARCHS_STANDARD)") | ||
| # Choose arm64 so SSE support is disabled. | ||
| set(processor arm64) | ||
| elseif("${architectures}" MATCHES "[^ ]+[ ]+[^ ]+") | ||
| # Multiple words, choose arm64 so SSE support is disabled. | ||
| set(processor arm64) | ||
| elseif(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64") | ||
| set(processor x86_64) | ||
| elseif(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64") | ||
| set(processor arm64) | ||
| else() | ||
| # Choose arm64 so SSE support is disabled. | ||
| set(processor arm64) | ||
| endif() | ||
| unset(architectures) | ||
| # Single-arch builds use that arch directly. For multi-arch | ||
| # universal builds, just pick the first listed arch as a | ||
| # representative value (callers must not depend on it for | ||
| # arch-sensitive decisions; see the multi-arch note above). | ||
| list(GET CMAKE_OSX_ARCHITECTURES 0 processor) | ||
| else() | ||
| # This will distinguish between M1 and Intel Macs | ||
| set(C_PREPROCESS ${CMAKE_C_COMPILER} -E -P) | ||
|
|
||
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,13 @@ | ||
| # Copyright 2015-2026 The Khronos Group Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Useful macros | ||
|
|
||
| macro(list_contains list item result) | ||
| list(FIND ${list} ${item} tmp_list_index) | ||
| if(${tmp_list_index} GREATER_EQUAL 0) | ||
| set(${result} ON) | ||
| else() | ||
| set(${result} OFF) | ||
| endif() | ||
| endmacro() |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limitation is now outdated. Delete.