Commit 5b18ae29b74fa17a180ab99b9e1078b427c78ae5

Ozkan Sezer 2021-08-03T14:01:02

improvements to libdecor support in cmake this makes it consistent with wayland support, and makes cmake side in line with autotools' libdecor support.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 82f8730..a1bda7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -389,6 +389,7 @@ set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
 set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
 dep_option(WAYLAND_SHARED      "Dynamically load Wayland support" ON "VIDEO_WAYLAND" OFF)
 dep_option(WAYLAND_LIBDECOR    "Use client-side window decorations on Wayland" ON "VIDEO_WAYLAND" ON)
+dep_option(LIBDECOR_SHARED     "Dynamically load libdecor support" ON "WAYLAND_LIBDECOR" OFF)
 dep_option(VIDEO_WAYLAND_QT_TOUCH  "QtWayland server support for Wayland video driver" ON "VIDEO_WAYLAND" OFF)
 set_option(VIDEO_RPI           "Use Raspberry Pi video driver" ${UNIX_SYS})
 dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
@@ -2593,9 +2594,6 @@ if(SDL_SHARED)
   if(IOS OR TVOS)
     set_property(TARGET SDL2 APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc")
   endif()
-  if(WAYLAND_LIBDECOR)
-    target_include_directories(SDL2 PRIVATE "${LIBDECOR_INCLUDE_DIRS}")
-  endif()
 endif()
 
 if(ANDROID)
@@ -2647,10 +2645,6 @@ if(SDL_STATIC)
   if(IOS OR TVOS)
     set_property(TARGET SDL2-static APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc")
   endif()
-  if(WAYLAND_LIBDECOR)
-    target_include_directories(SDL2-static PRIVATE "${LIBDECOR_INCLUDE_DIRS}")
-    target_link_libraries(SDL2-static "${LIBDECOR_LIBRARIES}")
-  endif()
 endif()
 
 ##### Tests #####
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 4d90f9a..52fed5d 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -701,9 +701,20 @@ macro(CheckWayland)
         pkg_check_modules(LIBDECOR libdecor-0)
         if(LIBDECOR_FOUND)
             set(HAVE_WAYLAND_LIBDECOR TRUE)
-            FindLibraryAndSONAME(decor-0)
-            set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
-            add_definitions(-DHAVE_LIBDECOR_H)
+            set(HAVE_LIBDECOR_H 1)
+            link_directories(${LIBDECOR_LIBRARY_DIRS})
+            include_directories(${LIBDECOR_INCLUDE_DIRS})
+            if(LIBDECOR_SHARED)
+              if(NOT HAVE_DLOPEN)
+                message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading")
+              else()
+                set(HAVE_LIBDECOR_SHARED TRUE)
+                FindLibraryAndSONAME(decor-0)
+                set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"")
+              endif()
+            else()
+              set(EXTRA_LIBS ${LIBDECOR_LIBRARIES} ${EXTRA_LIBS})
+            endif()
         endif()
       endif()
 
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 897d06a..511ffc0 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -224,6 +224,7 @@
 #cmakedefine HAVE_IMMINTRIN_H 1
 #cmakedefine HAVE_LIBUDEV_H 1
 #cmakedefine HAVE_LIBSAMPLERATE_H 1
+#cmakedefine HAVE_LIBDECOR_H  1
 
 #cmakedefine HAVE_D3D_H @HAVE_D3D_H@
 #cmakedefine HAVE_D3D11_H @HAVE_D3D11_H@