Remove FindSDL2 find-module, use sdl2-config.cmake instead 1.0.0
authorSimon McVittie <smcv@debian.org>
Mon, 12 Sep 2022 10:40:53 -0400
branch1.0.0
changeset 15881 7b1d6dfa3173
parent 15879 139a1887f83e
child 15882 acfa0869b579
Remove FindSDL2 find-module, use sdl2-config.cmake instead This requires SDL >= 2.0.4. Since <https://bugzilla.libsdl.org/show_bug.cgi?id=2464> was fixed in SDL 2.0.4, SDL behaves as a CMake "config-file package", even if it was not itself built using CMake: it installs a sdl2-config.cmake file to ${libdir}/cmake/SDL2, which tells CMake where to find SDL's headers and library, analogous to a pkg-config .pc file. As a result, we no longer need to copy/paste a "find-module package" to be able to find a system copy of SDL >= 2.0.4 with find_package(SDL2). Find-module packages are now discouraged by the CMake developers, in favour of having upstream projects behave as config-file packages. This results in a small API change: FindSDL2 used to set SDL2_INCLUDE_DIR and SDL2_LIBRARY, but the standard behaviour for config-file packages is to set <name>_INCLUDE_DIRS and <name>_LIBRARIES. Use the CONFIG keyword to make sure we search in config-file package mode, and will not find a FindSDL2.cmake in some other directory that implements the old interface. In addition to deleting redundant code, this avoids some assumptions in FindSDL2 about the layout of a SDL installation. The current libsdl2-dev package in Debian breaks those assumptions; this is considered a bug and will hopefully be fixed soon, but it illustrates how fragile these assumptions can be. We can be more robust against different installation layouts by relying on SDL's own CMake integration. When linking to a copy of CMake in a non-standard location, users can now set the SDL2_DIR or CMAKE_PREFIX_PATH environment variable to point to it; previously, these users would have used the SDL2DIR environment variable. This continues to be unnecessary if using matching system-wide installations of CMake and SDL2, for example both from Debian.
QTfrontend/CMakeLists.txt
hedgewars/CMakeLists.txt
misc/libphyslayer/CMakeLists.txt
project_files/hwc/CMakeLists.txt
tools/CMakeLists.txt
--- a/QTfrontend/CMakeLists.txt	Wed Sep 07 16:54:58 2022 -0400
+++ b/QTfrontend/CMakeLists.txt	Mon Sep 12 10:40:53 2022 -0400
@@ -13,9 +13,9 @@
 
 include(CheckLibraryExists)
 
-find_package(SDL2 REQUIRED)
+find_package(SDL2 REQUIRED CONFIG)
 find_package(SDL2_mixer 2 REQUIRED) #audio in SDLInteraction
-include_directories(${SDL2_INCLUDE_DIR})
+include_directories(${SDL2_INCLUDE_DIRS})
 include_directories(${SDL2_MIXER_INCLUDE_DIRS})
 
 if(LIBAV_FOUND)
@@ -230,12 +230,12 @@
     )
 
 list(APPEND HW_LINK_LIBS
-    ${SDL2_LIBRARY}
+    ${SDL2_LIBRARIES}
     ${SDL2_MIXER_LIBRARIES}
     )
 
 if(WIN32 AND NOT UNIX)
-    if(NOT SDL2_LIBRARY)
+    if(NOT SDL2_LIBRARIES)
         list(APPEND HW_LINK_LIBS SDL2)
     endif()
 
--- a/hedgewars/CMakeLists.txt	Wed Sep 07 16:54:58 2022 -0400
+++ b/hedgewars/CMakeLists.txt	Mon Sep 12 10:40:53 2022 -0400
@@ -1,6 +1,6 @@
 enable_language(Pascal)
 
-find_package(SDL2 REQUIRED)
+find_package(SDL2 REQUIRED CONFIG)
 find_package(SDL2_image 2 REQUIRED)
 find_package(SDL2_net 2 REQUIRED)
 find_package(SDL2_ttf 2 REQUIRED)
@@ -130,7 +130,7 @@
     add_flag_append(CMAKE_Pascal_FLAGS "-k-framework -kOpenGL")
 
     #set the correct library or framework style depending on the main SDL
-    string(FIND "${SDL2_LIBRARY}" "dylib" sdl_framework)
+    string(FIND "${SDL2_LIBRARIES}" "dylib" sdl_framework)
     if(${sdl_framework} GREATER -1)
         add_flag_append(CMAKE_Pascal_FLAGS "-k-lsdl2 -k-lsdl2_image -k-lsdl2_mixer -k-lsdl2_ttf -k-lsdl2_net")
     else()
--- a/misc/libphyslayer/CMakeLists.txt	Wed Sep 07 16:54:58 2022 -0400
+++ b/misc/libphyslayer/CMakeLists.txt	Mon Sep 12 10:40:53 2022 -0400
@@ -1,6 +1,6 @@
-find_package(SDL2 REQUIRED)
+find_package(SDL2 REQUIRED CONFIG)
 
-include_directories(${SDL2_INCLUDE_DIR})
+include_directories(${SDL2_INCLUDE_DIRS})
 include_directories(${PHYSFS_INCLUDE_DIR})
 include_directories(${LUA_INCLUDE_DIR})
 
@@ -17,7 +17,7 @@
 set_target_properties(physlayer PROPERTIES
                           VERSION 1.0
                           SOVERSION 1.0)
-target_link_libraries(physlayer ${SDL2_LIBRARY} lua physfs)
+target_link_libraries(physlayer ${SDL2_LIBRARIES} lua physfs)
 install(TARGETS physlayer RUNTIME DESTINATION ${target_binary_install_dir}
                           LIBRARY DESTINATION ${target_library_install_dir}
                           ARCHIVE DESTINATION ${target_library_install_dir})
--- a/project_files/hwc/CMakeLists.txt	Wed Sep 07 16:54:58 2022 -0400
+++ b/project_files/hwc/CMakeLists.txt	Mon Sep 12 10:40:53 2022 -0400
@@ -1,6 +1,6 @@
 #the usual set of dependencies
 find_package(OpenGL REQUIRED)
-find_package(SDL2 REQUIRED)
+find_package(SDL2 REQUIRED CONFIG)
 find_package(SDL2_mixer 2 REQUIRED)
 find_package(SDL2_net 2 REQUIRED)
 find_package(SDL2_image 2 REQUIRED)
@@ -111,7 +111,7 @@
 target_link_libraries(hwengine  fpcrtl
                                 ${LUA_LIBRARY}
                                 ${OPENGL_LIBRARY}
-                                ${SDL2_LIBRARY}
+                                ${SDL2_LIBRARIES}
                                 ${SDL2_MIXER_LIBRARIES}
                                 ${SDL2_NET_LIBRARIES}
                                 ${SDL2_IMAGE_LIBRARIES}
--- a/tools/CMakeLists.txt	Wed Sep 07 16:54:58 2022 -0400
+++ b/tools/CMakeLists.txt	Mon Sep 12 10:40:53 2022 -0400
@@ -8,7 +8,7 @@
 
 if(APPLE AND NOT SKIPBUNDLE)
     find_package(Qt5 REQUIRED QUIET COMPONENTS Core Widgets Gui Network)
-    find_package(SDL2 REQUIRED)
+    find_package(SDL2 REQUIRED CONFIG)
     find_package(SDL2_image 2 REQUIRED)
     find_package(SDL2_net 2 REQUIRED)
     find_package(SDL2_ttf 2 REQUIRED)
@@ -26,9 +26,9 @@
         endif()
     endif()
 
-    #remove the ";-framework Cocoa" from the SDL2_LIBRARY variable
-    string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL2_LIBRARY}")
-    #remove the "libSDLmain.a" from the SDL2_LIBRARY variable
+    #remove the ";-framework Cocoa" from the SDL2_LIBRARIES variable
+    string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL2_LIBRARIES}")
+    #remove the "libSDLmain.a" from the SDL2_LIBRARIES variable
     string(REGEX REPLACE ".*;(.*)" "\\1" sdl_library_only "${sdl_library_only}")
 
     #get the neme of the library (harmelss if it is static)