Skip to content

Commit

Permalink
Fixed bug 2683 - Raspberry PI support using CMake
Browse files Browse the repository at this point in the history
Tobias Himmer

this patch adds a check to the CMake build script to detect whether the VideoCore API is available.
If it is found, it enables SDL_VIDEO_DRIVER_RPI and will also add the needed include/library directory flags to CMAKE_C_FLAGS so the subsequent check for GLES succeeds in picking up the headers.

Seems to work fine on Raspbian.
  • Loading branch information
slouken committed Aug 17, 2014
1 parent 8272ed1 commit 984d0fc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -237,6 +237,7 @@ set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SY
set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS})
set_option(VIDEO_WAYLAND "Use Wayland video driver" ${UNIX_SYS})
set_option(VIDEO_MIR "Use Mir video driver" ${UNIX_SYS})
set_option(VIDEO_RPI "Use Raspberry Pi video driver" ${UNIX_SYS})
dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF)
set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
foreach(_SUB ${SDL_X11_OPTIONS})
Expand Down Expand Up @@ -658,6 +659,8 @@ if(UNIX AND NOT APPLE)
endif()

if(SDL_VIDEO)
# Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
CheckRPI()
CheckX11()
CheckMir()
CheckDirectFB()
Expand Down
29 changes: 29 additions & 0 deletions cmake/sdlchecks.cmake
Expand Up @@ -917,3 +917,32 @@ macro(CheckUSBHID)
set(CMAKE_REQUIRED_FLAGS)
endif(HAVE_USBHID)
endmacro(CheckUSBHID)

# Requires:
# - n/a
macro(CheckRPI)
if(VIDEO_RPI)
set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
set(VIDEO_RPI_LIBS bcm_host )
listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")

set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
check_c_source_compiles("
#include <bcm_host.h>
int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_LIBRARIES)

if(SDL_VIDEO AND HAVE_VIDEO_RPI)
set(HAVE_SDL_VIDEO TRUE)
set(SDL_VIDEO_DRIVER_RPI 1)
file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
endif(VIDEO_RPI)
endmacro(CheckRPI)
1 change: 1 addition & 0 deletions include/SDL_config.h.cmake
Expand Up @@ -264,6 +264,7 @@
#cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
#cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
#cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
#cmakedefine SDL_VIDEO_DRIVER_RPI @SDL_VIDEO_DRIVER_RPI@

#if 0
/* !!! FIXME: in configure script version, missing here: */
Expand Down

0 comments on commit 984d0fc

Please sign in to comment.