Fixed bug 2683 - Raspberry PI support using CMake
authorSam Lantinga <slouken@libsdl.org>
Sat, 16 Aug 2014 23:28:40 -0700
changeset 907728e6de55eb07
parent 9076 5e713281410c
child 9078 230e7558f76a
Fixed bug 2683 - Raspberry PI support using CMake

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.
CMakeLists.txt
cmake/sdlchecks.cmake
include/SDL_config.h.cmake
     1.1 --- a/CMakeLists.txt	Sat Aug 16 23:25:02 2014 -0700
     1.2 +++ b/CMakeLists.txt	Sat Aug 16 23:28:40 2014 -0700
     1.3 @@ -237,6 +237,7 @@
     1.4  set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
     1.5  set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
     1.6  set_option(VIDEO_MIR           "Use Mir video driver" ${UNIX_SYS})
     1.7 +set_option(VIDEO_RPI           "Use Raspberry Pi video driver" ${UNIX_SYS})
     1.8  dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
     1.9  set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
    1.10  foreach(_SUB ${SDL_X11_OPTIONS})
    1.11 @@ -658,6 +659,8 @@
    1.12    endif()
    1.13  
    1.14    if(SDL_VIDEO)
    1.15 +    # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
    1.16 +    CheckRPI()
    1.17      CheckX11()
    1.18      CheckMir()
    1.19      CheckDirectFB()
     2.1 --- a/cmake/sdlchecks.cmake	Sat Aug 16 23:25:02 2014 -0700
     2.2 +++ b/cmake/sdlchecks.cmake	Sat Aug 16 23:28:40 2014 -0700
     2.3 @@ -917,3 +917,32 @@
     2.4      set(CMAKE_REQUIRED_FLAGS)
     2.5    endif(HAVE_USBHID)
     2.6  endmacro(CheckUSBHID)
     2.7 +
     2.8 +# Requires:
     2.9 +# - n/a
    2.10 +macro(CheckRPI)
    2.11 +  if(VIDEO_RPI)
    2.12 +    set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
    2.13 +    set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
    2.14 +    set(VIDEO_RPI_LIBS bcm_host )
    2.15 +    listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
    2.16 +    listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
    2.17 +
    2.18 +    set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
    2.19 +    set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
    2.20 +    check_c_source_compiles("
    2.21 +        #include <bcm_host.h>
    2.22 +        int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
    2.23 +    set(CMAKE_REQUIRED_FLAGS)
    2.24 +    set(CMAKE_REQUIRED_LIBRARIES)
    2.25 +
    2.26 +    if(SDL_VIDEO AND HAVE_VIDEO_RPI)
    2.27 +      set(HAVE_SDL_VIDEO TRUE)
    2.28 +      set(SDL_VIDEO_DRIVER_RPI 1)
    2.29 +      file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
    2.30 +      set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
    2.31 +      list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
    2.32 +      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
    2.33 +    endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
    2.34 +  endif(VIDEO_RPI)
    2.35 +endmacro(CheckRPI)
     3.1 --- a/include/SDL_config.h.cmake	Sat Aug 16 23:25:02 2014 -0700
     3.2 +++ b/include/SDL_config.h.cmake	Sat Aug 16 23:28:40 2014 -0700
     3.3 @@ -264,6 +264,7 @@
     3.4  #cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
     3.5  #cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
     3.6  #cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
     3.7 +#cmakedefine SDL_VIDEO_DRIVER_RPI @SDL_VIDEO_DRIVER_RPI@
     3.8  
     3.9  #if 0
    3.10  /* !!! FIXME: in configure script version, missing here: */