Skip to content

COMP: Pass macOS architecture settings to external projects#1346

Merged
lassoan merged 1 commit intocommontk:masterfrom
vacaslistradas:fix-osx-architectures-external-projects
Mar 30, 2026
Merged

COMP: Pass macOS architecture settings to external projects#1346
lassoan merged 1 commit intocommontk:masterfrom
vacaslistradas:fix-osx-architectures-external-projects

Conversation

@vacaslistradas
Copy link
Copy Markdown

Summary

  • Adds CMAKE_OSX_ARCHITECTURES, CMAKE_OSX_DEPLOYMENT_TARGET, and CMAKE_OSX_SYSROOT to ep_common_cache_args
  • Fixes native ARM64 builds on Apple Silicon Macs

Problem

When building CTK with -DCMAKE_OSX_ARCHITECTURES=arm64 on a Mac with ARM64 Qt5, PythonQtGenerator fails to link:

ld: warning: ignoring file 'QtCore': found architecture 'arm64', required architecture 'x86_64'
ld: symbol(s) not found for architecture x86_64

Root Cause

The ep_common_cache_args variable (used by external projects like PythonQt and PythonQtGenerator) doesn't include macOS architecture settings, so nested projects default to x86_64 while trying to link against ARM64 Qt libraries.

Test Plan

  • Built CTK with -DCMAKE_OSX_ARCHITECTURES=arm64 on macOS Tahoe (M4)
  • PythonQtGenerator now builds successfully for ARM64
  • Full CTK build completes without architecture mismatch errors

vacaslistradas pushed a commit to vacaslistradas/Slicer that referenced this pull request Jan 26, 2026
When building Slicer for a specific macOS architecture (e.g., arm64),
the CMAKE_OSX_ARCHITECTURES, CMAKE_OSX_DEPLOYMENT_TARGET, and
CMAKE_OSX_SYSROOT variables need to be explicitly passed to the CTK
external project.

This is work towards Slicer#6811 and Slicer#5944.

Note: This change requires commontk/CTK#1346 to fully resolve native
ARM64 builds, as CTK also needs to propagate these settings to its
nested external projects (PythonQt, PythonQtGenerator).
Copy link
Copy Markdown
Contributor

@jamesobutler jamesobutler left a comment

Choose a reason for hiding this comment

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

You successfully built Qt5 from source for the arm64 platform? I don't believe Qt provides Qt5 arm64 binaries. And then you successfully built PythonQt for arm64 using that Qt5 build?

@vacaslistradas
Copy link
Copy Markdown
Author

I didn't build Qt5 myself, Homebrew provides Qt5 5.15.16 pre-built for ARM64.
And yes, with this fix applied, PythonQt and PythonQtGenerator both build successfully for ARM64. The problem was that without passing CMAKE_OSX_ARCHITECTURES down to the external projects, the generator was building for x86_64 while trying to link against my ARM64 Qt5 libraries.

vacaslistradas pushed a commit to vacaslistradas/Slicer that referenced this pull request Mar 14, 2026
When building Slicer for a specific macOS architecture (e.g., arm64),
the CMAKE_OSX_ARCHITECTURES, CMAKE_OSX_DEPLOYMENT_TARGET, and
CMAKE_OSX_SYSROOT variables need to be explicitly passed to the CTK
external project.

This is work towards Slicer#6811 and Slicer#5944.

Note: This change requires commontk/CTK#1346 to fully resolve native
ARM64 builds, as CTK also needs to propagate these settings to its
nested external projects (PythonQt, PythonQtGenerator).
@hjmjohnson
Copy link
Copy Markdown
Contributor

@jamesobutler This request seems reasonable, the solution looks good to me.

@jamesobutler
Copy link
Copy Markdown
Contributor

@hjmjohnson As @pieper mentioned in Slicer/Slicer#9003 (comment), he seemed to not need any additional code changes in the context of Slicer and CTK to pass things down as his ARM64 build has already been successful without it.

@hjmjohnson
Copy link
Copy Markdown
Contributor

@jamesobutler When environmental defaults are configured in a compatible way, there are no issues (i.e. when. the defaults are guessed correctly). I think this is a case of "not required when guesses are consistent, required when guesses are wrong".

Explicitly setting these variables is the safest and most robust approach. Let's make propagating these items more robust and only propagate them if they are set to non-null values.

I am a fan of being explicit when all the builds MUST use the same compilation environments/tools. Explicitly setting those values is often not needed in default builds, but it makes custom builds (i.e., old compilers/static analyzers/etc.) much easier to implement.

My hypothesis is that one of the environmental variables that changes the default behavior was set. I.e., they were trying to compile the following outdated slicer build instructions that changed defaults to x86_64, then started a new build, but forgot to unset the environmental variable. Then the Outer superbuild was set to arm64, but the inner build had to guess and used the environmental variable as the default.

I'm fine with this being ignored or incorporated, but I'd like a final decision.

When building CTK for a specific macOS architecture (e.g., arm64),
the CMAKE_OSX_ARCHITECTURES, CMAKE_OSX_DEPLOYMENT_TARGET, and
CMAKE_OSX_SYSROOT variables need to be passed to nested external
projects like PythonQt and PythonQtGenerator.

Without this fix, building CTK with -DCMAKE_OSX_ARCHITECTURES=arm64
while using ARM64 Qt5 causes PythonQtGenerator to build for the
wrong architecture (defaulting to x86_64), resulting in linker
errors like:

  ld: warning: ignoring file 'QtCore': found architecture 'arm64',
      required architecture 'x86_64'
  ld: symbol(s) not found for architecture x86_64

This change adds the macOS architecture variables to ep_common_cache_args
so they are consistently passed to all external projects.
@lassoan lassoan force-pushed the fix-osx-architectures-external-projects branch from 9640069 to 4b260e1 Compare March 30, 2026 14:57
Copy link
Copy Markdown
Member

@lassoan lassoan 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. Probably explicit propagation of these variables is not necessary in most cases, but it should not do any harm and it can be useful in some cases.

@lassoan lassoan enabled auto-merge (rebase) March 30, 2026 15:03
@lassoan lassoan merged commit eeab4a2 into commontk:master Mar 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants