Skip to content

[cmake] Propagate Cocoa backend frameworks to consumers of static raylib on macOS - #6086

Open
zaveshaa wants to merge 2 commits into
raysan5:masterfrom
zaveshaa:fix/static-install-macos-frameworks
Open

[cmake] Propagate Cocoa backend frameworks to consumers of static raylib on macOS#6086
zaveshaa wants to merge 2 commits into
raysan5:masterfrom
zaveshaa:fix/static-install-macos-frameworks

Conversation

@zaveshaa

Copy link
Copy Markdown

Closes #6080

Problem

When raylib is built as a static library and consumed via find_package(raylib) on macOS, linking fails with undefined Objective-C symbols:

  "_objc_retain", referenced from:
      __glfwCreateStandardCursorCocoa in libraylib.a(cocoa_window.m.o)
ld: symbol(s) not found for architecture x86_64

Root cause chain:

  1. Bundled GLFW links its Cocoa backend frameworks (Cocoa, IOKit, QuartzCore) as PRIVATE
  2. The static-install export block in src/CMakeLists.txt removes glfw from exported dependencies (correct — its symbols are inside the archive)
  3. But the frameworks GLFW needed are not re-exported either, so the installed package only carries OpenGL.framework

Fix

In the static-only export block, when the bundled GLFW is used on APPLE, append the same three frameworks GLFW's Cocoa backend declares, resolved via find_library(). Shared builds are untouched (the block is guarded by NOT BUILD_SHARED_LIBS).

Verification (macOS 15, Intel, Apple clang 14)

Full standalone flow, before → after:

Step Before After
cd examples && cmake .. -DCMAKE_PREFIX_PATH=<stage> configures (after #6079)
make core_basic_window ❌ ld: objc symbols not found ✅ links

Repro script:

cmake .. -DBUILD_SHARED_LIBS=OFF -DBUILD_EXAMPLES=OFF && make -j3
cmake --install . --prefix /tmp/raylib-stage
cd ../examples && cmake .. -DCMAKE_PREFIX_PATH=/tmp/raylib-stage && make core_basic_window

Note: this PR depends on #6079 for the examples to configure standalone; the library-side fix here is independent.

Configuring examples/ as a standalone project (cd examples && cmake .)
failed with 'Unknown CMake command add_if_flag_compiles' and a missing
cmake_minimum_required() error on CMake 4.x.

- Add cmake_minimum_required(VERSION 3.22), matching the root project
- Include raylib's AddIfFlagCompiles helper via ../cmake
- Default PLATFORM to Desktop when not inherited from the raylib build
…lib on macOS

Bundled GLFW links '-framework Cocoa/IOKit/QuartzCore' privately, and the
static-install export block removes glfw from the exported dependencies.
As a result the installed CMake package only carried OpenGL.framework,
and linking any consumer of libraylib.a failed with undefined Objective-C
symbols (_objc_retain etc.).

Append the three frameworks to the static install interface when the
bundled GLFW is used, so installed consumers get a complete link line.
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.

[cmake] Installed static raylib on macOS doesn't propagate Cocoa/IOKit frameworks to consumers

1 participant