Make rpi video cross-compiler friendly.
author"Guillermo A. Amaral" <g@maral.me>
Wed, 17 Jan 2018 13:17:10 -0800
changeset 11829fcbafc9e443c
parent 11828 da1ca77eb713
child 11830 a01af1a724b3
Make rpi video cross-compiler friendly.
* Stops using fixed path to find GLES/EGL libs.
* Tries pkg-config to locate bcm_host.

Signed-off-by: Guillermo A. Amaral <g@maral.me>
cmake/sdlchecks.cmake
configure
configure.in
src/video/SDL_egl.c
     1.1 --- a/cmake/sdlchecks.cmake	Wed Jan 17 13:12:39 2018 -0800
     1.2 +++ b/cmake/sdlchecks.cmake	Wed Jan 17 13:17:10 2018 -0800
     1.3 @@ -1127,15 +1127,18 @@
     1.4  # - n/a
     1.5  macro(CheckRPI)
     1.6    if(VIDEO_RPI)
     1.7 -    set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
     1.8 -    set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
     1.9 -    set(VIDEO_RPI_LIBS bcm_host )
    1.10 +    pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
    1.11 +    if (NOT VIDEO_RPI_FOUND)
    1.12 +      set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
    1.13 +      set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
    1.14 +      set(VIDEO_RPI_LIBRARIES bcm_host )
    1.15 +    endif()
    1.16      listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
    1.17      listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
    1.18  
    1.19      set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
    1.20      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
    1.21 -    set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
    1.22 +    set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
    1.23      check_c_source_compiles("
    1.24          #include <bcm_host.h>
    1.25          int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
    1.26 @@ -1147,7 +1150,7 @@
    1.27        set(SDL_VIDEO_DRIVER_RPI 1)
    1.28        file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
    1.29        set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
    1.30 -      list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
    1.31 +      list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
    1.32        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
    1.33      endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
    1.34    endif(VIDEO_RPI)
     2.1 --- a/configure	Wed Jan 17 13:12:39 2018 -0800
     2.2 +++ b/configure	Wed Jan 17 13:17:10 2018 -0800
     2.3 @@ -19502,7 +19502,51 @@
     2.4  fi
     2.5  
     2.6      if test x$enable_video = xyes -a x$enable_video_rpi = xyes; then
     2.7 -        if test x$ARCH = xnetbsd; then
     2.8 +        # Extract the first word of "pkg-config", so it can be a program name with args.
     2.9 +set dummy pkg-config; ac_word=$2
    2.10 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
    2.11 +$as_echo_n "checking for $ac_word... " >&6; }
    2.12 +if ${ac_cv_path_PKG_CONFIG+:} false; then :
    2.13 +  $as_echo_n "(cached) " >&6
    2.14 +else
    2.15 +  case $PKG_CONFIG in
    2.16 +  [\\/]* | ?:[\\/]*)
    2.17 +  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
    2.18 +  ;;
    2.19 +  *)
    2.20 +  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
    2.21 +for as_dir in $PATH
    2.22 +do
    2.23 +  IFS=$as_save_IFS
    2.24 +  test -z "$as_dir" && as_dir=.
    2.25 +    for ac_exec_ext in '' $ac_executable_extensions; do
    2.26 +  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    2.27 +    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
    2.28 +    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    2.29 +    break 2
    2.30 +  fi
    2.31 +done
    2.32 +  done
    2.33 +IFS=$as_save_IFS
    2.34 +
    2.35 +  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
    2.36 +  ;;
    2.37 +esac
    2.38 +fi
    2.39 +PKG_CONFIG=$ac_cv_path_PKG_CONFIG
    2.40 +if test -n "$PKG_CONFIG"; then
    2.41 +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
    2.42 +$as_echo "$PKG_CONFIG" >&6; }
    2.43 +else
    2.44 +  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
    2.45 +$as_echo "no" >&6; }
    2.46 +fi
    2.47 +
    2.48 +
    2.49 +        if test x$PKG_CONFIG != xno && $PKG_CONFIG --exists bcm_host; then
    2.50 +            RPI_CFLAGS=`$PKG_CONFIG --cflags bcm_host brcmegl`
    2.51 +            RPI_LDFLAGS=`$PKG_CONFIG --libs bcm_host brcmegl`
    2.52 +        elif test x$ARCH = xnetbsd; then
    2.53              RPI_CFLAGS="-I/usr/pkg/include -I/usr/pkg/include/interface/vcos/pthreads -I/usr/pkg/include/interface/vmcs_host/linux"
    2.54              RPI_LDFLAGS="-Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lbcm_host"
    2.55          else
     3.1 --- a/configure.in	Wed Jan 17 13:12:39 2018 -0800
     3.2 +++ b/configure.in	Wed Jan 17 13:17:10 2018 -0800
     3.3 @@ -1571,7 +1571,11 @@
     3.4  AC_HELP_STRING([--enable-video-rpi], [use Raspberry Pi video driver [[default=yes]]]),
     3.5                    , enable_video_rpi=yes)
     3.6      if test x$enable_video = xyes -a x$enable_video_rpi = xyes; then
     3.7 -        if test x$ARCH = xnetbsd; then
     3.8 +        AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
     3.9 +        if test x$PKG_CONFIG != xno && $PKG_CONFIG --exists bcm_host; then
    3.10 +            RPI_CFLAGS=`$PKG_CONFIG --cflags bcm_host brcmegl`
    3.11 +            RPI_LDFLAGS=`$PKG_CONFIG --libs bcm_host brcmegl`
    3.12 +        elif test x$ARCH = xnetbsd; then
    3.13              RPI_CFLAGS="-I/usr/pkg/include -I/usr/pkg/include/interface/vcos/pthreads -I/usr/pkg/include/interface/vmcs_host/linux"
    3.14              RPI_LDFLAGS="-Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lbcm_host"
    3.15          else
     4.1 --- a/src/video/SDL_egl.c	Wed Jan 17 13:12:39 2018 -0800
     4.2 +++ b/src/video/SDL_egl.c	Wed Jan 17 13:17:10 2018 -0800
     4.3 @@ -44,12 +44,13 @@
     4.4  
     4.5  #if SDL_VIDEO_DRIVER_RPI
     4.6  /* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
     4.7 -#define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "/opt/vc/lib/libbrcmEGL.so" )
     4.8 -#define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "/opt/vc/lib/libbrcmGLESv2.so" )
     4.9 -#define ALT_EGL "/opt/vc/lib/libEGL.so"
    4.10 -#define ALT_OGL_ES2 "/opt/vc/lib/libGLESv2.so"
    4.11 -#define DEFAULT_OGL_ES_PVR ( vc4 ? "libGLES_CM.so.1" : "/opt/vc/lib/libbrcmGLESv2.so" )
    4.12 -#define DEFAULT_OGL_ES ( vc4 ? "libGLESv1_CM.so.1" : "/opt/vc/lib/libbrcmGLESv2.so" )
    4.13 +static const char g_rpi_opt_path[] = "/opt/vc/lib";
    4.14 +#define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
    4.15 +#define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" )
    4.16 +#define ALT_EGL "libEGL.so"
    4.17 +#define ALT_OGL_ES2 "libGLESv2.so"
    4.18 +#define DEFAULT_OGL_ES_PVR ( vc4 ? "libGLES_CM.so.1" : "libbrcmGLESv2.so" )
    4.19 +#define DEFAULT_OGL_ES ( vc4 ? "libGLESv1_CM.so.1" : "libbrcmGLESv2.so" )
    4.20  
    4.21  #elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE
    4.22  /* Android */
    4.23 @@ -265,6 +266,20 @@
    4.24  #endif
    4.25  #if SDL_VIDEO_DRIVER_RPI
    4.26      SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));
    4.27 +
    4.28 +    path = SDL_getenv("LD_LIBRARY_PATH");
    4.29 +    if (path) {
    4.30 +        const int path_size = SDL_strlen(path) + 1 + sizeof(g_rpi_opt_path);
    4.31 +        char *new_path = SDL_calloc(1, path_size);
    4.32 +        strcat(new_path, path);
    4.33 +        strcat(new_path, ":");
    4.34 +        strcat(new_path, g_rpi_opt_path);
    4.35 +        SDL_setenv("LD_LIBRARY_PATH", new_path, 1);
    4.36 +        SDL_free(new_path);
    4.37 +    } else {
    4.38 +        SDL_setenv("LD_LIBRARY_PATH", g_rpi_opt_path, 1);
    4.39 +    }
    4.40 +    path = NULL;
    4.41  #endif
    4.42  
    4.43      if (_this->egl_data) {