Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Raspberry Pi detection in CMakeLists.txt #181

Closed
wants to merge 8 commits into from

Conversation

XQuestCode
Copy link
Contributor

Update Raspberry Pi detection in CMakeLists.txt

Issue

The current CMakeLists.txt file relies on the /opt/vc/ directory to detect Raspberry Pi systems. However, in recent Raspberry Pi OS updates, particularly for 64-bit versions, this directory has been removed. This change causes the build process to fail on newer Raspberry Pi systems, as it cannot detect the platform correctly and thus fails to include necessary libraries like pigpio.

Proposed Solution

Update the Raspberry Pi detection method in CMakeLists.txt to use a more reliable and future-proof approach that doesn't depend on the /opt/vc/ directory.

Implementation Details

  1. Replace the current detection method:

    find_path(BCM_HOST_INCLUDE_DIR bcm_host.h PATHS "/opt/vc/include")

    with a new method that checks the device tree:

    if(EXISTS "/sys/firmware/devicetree/base/model")
      file(READ "/sys/firmware/devicetree/base/model" DEVICE_MODEL)
      if(DEVICE_MODEL MATCHES "Raspberry Pi")
        set(IS_RASPBERRY_PI TRUE)
      endif()
    endif()
  2. Update conditional blocks to use the new IS_RASPBERRY_PI variable.

  3. Adjust library and include paths to account for the new Raspberry Pi OS structure.

  4. Ensure pigpio libraries are correctly linked when building on Raspberry Pi systems.

Changes to existing code

  • In the "Check for Raspberry Pi" section, replace the find_path command with the new detection method.
  • Update subsequent conditional blocks that use BCM_HOST_INCLUDE_DIR to instead use IS_RASPBERRY_PI.
  • Adjust include and library paths that previously referenced /opt/vc/ to use appropriate system paths.

Testing

  • Tested build process on:
    • Raspberry Pi 4 with latest 64-bit Raspberry Pi OS
    • Raspberry Pi 3B+ with 32-bit Raspberry Pi OS
    • Non-Raspberry Pi Linux system
  • Verified successful compilation and linking on all Raspberry Pi systems.
  • Confirmed that build completes without errors on non-Raspberry Pi systems, correctly skipping Raspberry Pi-specific components.
    image

This PR aims to restore functionality for building on Raspberry Pi systems while maintaining compatibility with the latest Raspberry Pi OS versions and existing non-Raspberry Pi builds.

References:

@macite
Copy link
Member

macite commented Sep 10, 2024

Can you rebuild this with just the raspberry pi detection changes.

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.

4 participants