Skip to content

cmake: allow overriding hardcoded libomp path on macOS#65

Open
natsukium wants to merge 1 commit intoTimoLassmann:mainfrom
natsukium:cmake/macos-openmp-config
Open

cmake: allow overriding hardcoded libomp path on macOS#65
natsukium wants to merge 1 commit intoTimoLassmann:mainfrom
natsukium:cmake/macos-openmp-config

Conversation

@natsukium
Copy link
Copy Markdown

Hi! I'm the maintainer of the kalign package in nixpkgs.

While updating the package to 3.5.1, I ran into a macOS build issue caused by a hardcoded libomp path in CMakeLists.txt, and wanted to propose a fix upstream.

Problem

On aarch64-darwin, the build fails outside of a Homebrew environment because the libomp path is hardcoded to /opt/homebrew:

make[2]: *** No rule to make target '/opt/homebrew/opt/libomp/lib/libomp.dylib', needed by 'lib/libkalign.3.5.1.dylib'.  Stop.

In Nix (and other custom build setups), libomp lives outside /opt/homebrew, so the hardcoded path breaks the build on Apple Silicon. See NixOS/nixpkgs#492312 for the downstream report.

Changes

  • Introduce a LIBOMP_ROOT CMake cache variable that defaults to /opt/homebrew/opt/libomp, so Homebrew users keep the current behavior while other environments can override it (e.g. -DLIBOMP_ROOT=/nix/store/.../libomp).
  • Scope the manual OpenMP override to AppleClang only. Other compilers (GCC, LLVM Clang) support OpenMP natively and should go through the normal find_package(OpenMP) path instead of being forced through the Apple Clang workaround.

The OpenMP workaround hardcoded /opt/homebrew/opt/libomp, which locked
out a custom build.
Introduce LIBOMP_ROOT (defaulting to Homebrew) so the prefix can be
overridden on the cmake command line.

While here, restrict the block to AppleClang. The flags inside are
AppleClang-specific (-Xpreprocessor -fopenmp, linking against the LLVM
libomp runtime) and were previously forced on any compiler targeting
Apple Silicon, silently breaking GCC and mis-configuring Homebrew LLVM
Clang builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant