Skip to content
Open
Show file tree
Hide file tree
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 May 14, 2026
0caddb8
fix: Building a universal macOS binary should work with generators ot…
atteneder May 14, 2026
9bf4fb0
fix: Don't apply BasisU x86_64 SSE 4.1 patch on non-macOS systems.
atteneder May 14, 2026
89c6040
feat: Explicitly deny CMAKE_OSX_ARCHITECTURES value `$(ARCHS_STANDARD…
atteneder May 14, 2026
4de37d0
doc: Updated building documentation.
atteneder May 14, 2026
100305f
fix: Conditional option `BASISU_SSE` is shown for macOS universal bui…
atteneder May 14, 2026
a86c3bf
chore: Removed out-dated arch detection code in `set_target_processor…
atteneder May 14, 2026
13569f3
feat: CMake option `LIBKTX_FEATURE_BASISU_SSE` allows enabling/disabl…
atteneder May 14, 2026
3ba2c2e
refactor: Renamed variables to match style and applied CMake best pra…
atteneder May 15, 2026
5ad855f
fix: Set `APPLE_MAC_OS` to `ON` when targeting macOS only.
atteneder May 15, 2026
6d90108
fix: Enable x86 (32-bit) builds for Android only.
atteneder May 15, 2026
74d0c8b
fix: Propagate all ASTC encoder dependency.
atteneder May 15, 2026
96cc11f
doc: Added pointer to macOS CMAKE_OSX_ARCHITECTURES handling from `cp…
atteneder May 23, 2026
b0e7fd5
fix: `CMAKE_SYSTEM_NAME` might not be set, so assume macOS as default…
atteneder May 23, 2026
1c87c65
fix: Don't reject $(ARCHS_STANDARD) literal as macOS architecture set…
atteneder May 23, 2026
7a67f3d
fix: Don't link ASTC encoders into `ktx_read`
atteneder May 23, 2026
946421a
Revert "fix: Don't link ASTC encoders into `ktx_read`"
atteneder May 24, 2026
c51e808
fix: Moved special handling of macOS architecture "$(ARCHS_STANDARD)"…
atteneder May 26, 2026
4cd7732
chore: Removed obsolete armv8 iOS architecture setting.
atteneder May 26, 2026
9dc7a3b
Revert "doc: Updated building documentation."
atteneder May 26, 2026
aab5417
doc: Removed outdated warning
atteneder May 26, 2026
2b0cdfa
refactor: Centralized where macOS architecture is handled for `libktx`.
atteneder May 26, 2026
2982ebb
fix: Reversed renaming of ASTCENC_UNIVERSAL_BUILD to ASTCENC_APPLE_MA…
atteneder May 26, 2026
52697f5
fix: Prepare code eventual change of which architecture(s) Xcode's `$…
atteneder May 26, 2026
8c266a4
chore: Removed outdated compile option `-msse4.1`.
atteneder May 26, 2026
1be79ba
refactor: `BASISU_SSE` is `FALSE` on non-x86_64 architecture anyways,…
atteneder May 29, 2026
0ad1fc3
fix: Typo
atteneder May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ cmake --build build/mac
```
##### Apple Silicon and Universal Binaries

Macs are either based on Intel or the newer Apple Silicon architecture. By default CMake configures to build for your host's platform, whichever it is. If you want to cross compile universal binaries (that support both platforms), add the parameter `-DCMAKE_OSX_ARCHITECTURES="\$(ARCHS_STANDARD)"` to cmake.
Macs are either based on Intel or the newer Apple Silicon architecture. By default CMake configures to build for your host's platform, whichever it is. If you want to cross compile universal binaries (that support both platforms), add the parameter `-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"` to cmake.

> **Known limitations:**
> - Intel Macs have support for SSE, but if you're building universal binaries,

Copy link
Copy Markdown
Collaborator

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.

Expand All @@ -258,7 +258,7 @@ Example how to build universal binaries

```bash
# Configure universal binaries and disable SSE
cmake -G Xcode -B build-macos-universal -D CMAKE_OSX_ARCHITECTURES="\$(ARCHS_STANDARD)" -D BASISU_SUPPORT_SSE=OFF
cmake -G Xcode -B build-macos-universal -D CMAKE_OSX_ARCHITECTURES="arm64;x86_64" -D BASISU_SUPPORT_SSE=OFF
# Build
cmake --build build-macos-universal
# Easy way to check if the resulting binaries are universal
Expand Down
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,28 @@ endif()
if(APPLE)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "visionOS")
set( APPLE_LOCKED_OS ON )
else()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set( APPLE_MAC_OS ON )
endif()

# Reject CMAKE_OSX_ARCHITECTURES containing the literal $(ARCHS_STANDARD)
# Xcode build setting. CMake stores the unexpanded string and embeds it into
# $<TARGET_OBJECTS:...> paths; at build time Xcode expands it to a
# space-separated arch list (e.g. "arm64 x86_64") which is not a real
# Objects-normal/<arch> directory, so dependent objects (basisu_encoder,
# dfdutils) silently drop out of any libktx*.a using the OBJECT-embedding
# variant of add_lib_dependencies, and the link of consumers like ktxdiff
# fails with undefined symbols. Auto-rewriting to a hardcoded list would not
# track future Xcode changes to ARCHS_STANDARD, so require the caller to
# spell out the architectures they actually want.
if(CMAKE_OSX_ARCHITECTURES MATCHES "\\$\\(ARCHS_STANDARD\\)")
message(FATAL_ERROR
"CMAKE_OSX_ARCHITECTURES must not contain the Xcode build setting "
"\"\$(ARCHS_STANDARD)\" -- CMake does not expand it and the literal "
"ends up in object-file paths, breaking universal static-lib builds. "
"Pass an explicit semicolon-separated list instead, e.g. "
"-DCMAKE_OSX_ARCHITECTURES=\"arm64;x86_64\".")
endif()
endif()

include(CMakeDependentOption)
Expand Down Expand Up @@ -131,7 +150,7 @@ include(GNUInstallDirs) # Must be after project.
include(CTest) # "

set_target_processor_type(CPU_ARCHITECTURE) # Must be after project.
if (CPU_ARCHITECTURE STREQUAL x86)
if (CPU_ARCHITECTURE STREQUAL x86 AND NOT ANDROID)
message(FATAL_ERROR "This project cannot be built for x86 cpu.")
endif()

Expand Down
58 changes: 23 additions & 35 deletions cmake/cputypetest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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)
Expand Down
13 changes: 13 additions & 0 deletions cmake/macros.cmake
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()
Loading
Loading