Skip to content

[cmake] Fix standalone configuration of examples project - #6079

Open
zaveshaa wants to merge 1 commit into
raysan5:masterfrom
zaveshaa:fix/examples-standalone-cmake
Open

[cmake] Fix standalone configuration of examples project#6079
zaveshaa wants to merge 1 commit into
raysan5:masterfrom
zaveshaa:fix/examples-standalone-cmake

Conversation

@zaveshaa

Copy link
Copy Markdown

Problem

Configuring the examples as a standalone project currently fails:

cd examples && mkdir build && cd build && cmake ..
-- Configuring incomplete, errors occurred!
CMake Error at CMakeLists.txt:37 (add_if_flag_compiles):
  Unknown CMake command "add_if_flag_compiles".

Two causes:

  1. add_if_flag_compiles() is defined in cmake/AddIfFlagCompiles.cmake, which is only included by the root project — never when examples are configured on their own
  2. No cmake_minimum_required() in this file, which is a hard error on CMake 4.x

Fix

  • Add cmake_minimum_required(VERSION 3.22), matching the root project
  • Add ../cmake to CMAKE_MODULE_PATH and include AddIfFlagCompiles, so the pthread/c11 flag checks work standalone
  • Default PLATFORM to Desktop when it isn't inherited from a parent raylib build

Verification (macOS 15, Intel, Apple clang 14)

  • Before: cmake .. fails with Unknown CMake command "add_if_flag_compiles"
  • After: standalone configure completes and generates build files for all examples
  • Normal path unaffected: root project with -DBUILD_EXAMPLES=ON still configures and builds examples correctly

Note: after this fix, standalone configure succeeds but linking against an installed static raylib fails on macOS because the installed CMake package only propagates OpenGL.framework (Cocoa/IOKit are missing). That looks like a separate pre-existing issue — happy to file/fix it next if confirmed.

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
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