cmake: Now generates Wayland protocol source bits like the configure script.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 11 Oct 2016 16:36:40 -0400
changeset 105118e646a2d1929
parent 10510 01761b2d701e
child 10512 c6d79a1bec47
cmake: Now generates Wayland protocol source bits like the configure script.

Fixes Bugzilla #3430.
cmake/sdlchecks.cmake
     1.1 --- a/cmake/sdlchecks.cmake	Mon Oct 03 15:31:11 2016 +0100
     1.2 +++ b/cmake/sdlchecks.cmake	Tue Oct 11 16:36:40 2016 -0400
     1.3 @@ -539,6 +539,27 @@
     1.4      endif()
     1.5  endmacro()
     1.6  
     1.7 +macro(WaylandProtocolGen _SCANNER _XML _PROTL)
     1.8 +    set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
     1.9 +    set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
    1.10 +
    1.11 +    add_custom_command(
    1.12 +        OUTPUT "${_WAYLAND_PROT_H_CODE}"
    1.13 +        DEPENDS "${_XML}"
    1.14 +        COMMAND "${_SCANNER}"
    1.15 +        ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
    1.16 +    )
    1.17 +
    1.18 +    add_custom_command(
    1.19 +        OUTPUT "${_WAYLAND_PROT_C_CODE}"
    1.20 +        DEPENDS "${_WAYLAND_PROT_H_CODE}"
    1.21 +        COMMAND "${_SCANNER}"
    1.22 +        ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
    1.23 +    )
    1.24 +
    1.25 +    set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
    1.26 +endmacro()
    1.27 +
    1.28  # Requires:
    1.29  # - EGL
    1.30  # - PkgCheckModules
    1.31 @@ -547,7 +568,51 @@
    1.32  # - HAVE_DLOPEN opt
    1.33  macro(CheckWayland)
    1.34    if(VIDEO_WAYLAND)
    1.35 -    pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
    1.36 +    pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
    1.37 +
    1.38 +    # We have to generate some protocol interface code for some various Wayland features.
    1.39 +    if(WAYLAND_FOUND)
    1.40 +      execute_process(
    1.41 +        COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-client
    1.42 +        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    1.43 +        RESULT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR_RC
    1.44 +        OUTPUT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR
    1.45 +        ERROR_QUIET
    1.46 +        OUTPUT_STRIP_TRAILING_WHITESPACE
    1.47 +      )
    1.48 +      if(NOT WAYLAND_CORE_PROTOCOL_DIR_RC EQUAL 0)
    1.49 +        set(WAYLAND_FOUND FALSE)
    1.50 +      endif()
    1.51 +    endif()
    1.52 +
    1.53 +    if(WAYLAND_FOUND)
    1.54 +      execute_process(
    1.55 +        COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
    1.56 +        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    1.57 +        RESULT_VARIABLE WAYLAND_PROTOCOLS_DIR_RC
    1.58 +        OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
    1.59 +        ERROR_QUIET
    1.60 +        OUTPUT_STRIP_TRAILING_WHITESPACE
    1.61 +      )
    1.62 +      if(NOT WAYLAND_PROTOCOLS_DIR_RC EQUAL 0)
    1.63 +        set(WAYLAND_FOUND FALSE)
    1.64 +      endif()
    1.65 +    endif()
    1.66 +
    1.67 +    if(WAYLAND_FOUND)
    1.68 +      execute_process(
    1.69 +        COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
    1.70 +        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    1.71 +        RESULT_VARIABLE WAYLAND_SCANNER_RC
    1.72 +        OUTPUT_VARIABLE WAYLAND_SCANNER
    1.73 +        ERROR_QUIET
    1.74 +        OUTPUT_STRIP_TRAILING_WHITESPACE
    1.75 +      )
    1.76 +      if(NOT WAYLAND_SCANNER_RC EQUAL 0)
    1.77 +        set(WAYLAND_FOUND FALSE)
    1.78 +      endif()
    1.79 +    endif()
    1.80 +
    1.81      if(WAYLAND_FOUND)
    1.82        link_directories(
    1.83            ${WAYLAND_LIBRARY_DIRS}
    1.84 @@ -561,6 +626,17 @@
    1.85        file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
    1.86        set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
    1.87  
    1.88 +      # We have to generate some protocol interface code for some unstable Wayland features.
    1.89 +      file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
    1.90 +      include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
    1.91 +
    1.92 +      WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
    1.93 +
    1.94 +      foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
    1.95 +        string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
    1.96 +        WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
    1.97 +      endforeach()
    1.98 +
    1.99        if(VIDEO_WAYLAND_QT_TOUCH)
   1.100            set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   1.101        endif()