From b838f86a9d0f30898c868f301434de75cc3191e8 Mon Sep 17 00:00:00 2001
From: Charlie Birks <[EMAIL REDACTED]>
Date: Tue, 14 Dec 2021 10:00:54 +0000
Subject: [PATCH] cmake: Don't find_package SDL if the target already exists
Restores ability to build with SDL in a subdirectory. Also matches what
SDL2_image does.
---
CMakeLists.txt | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c7737dc..259e3903 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,8 +19,9 @@ option(SUPPORT_MID_TIMIDITY "Support loading MIDI music via TiMidity" OFF)
option(BUILD_SHARED_LIBS "Enable shared library" ON)
-find_package(SDL2 REQUIRED)
-include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR})
+if (NOT ANDROID AND NOT (TARGET SDL2 OR TARGET SDL2-static))
+ find_package(SDL2 REQUIRED)
+endif()
include_directories(include src src/codecs)
@@ -78,4 +79,4 @@ if (SUPPORT_MID_TIMIDITY)
endif()
target_include_directories(SDL2_mixer PUBLIC include)
-target_link_libraries(SDL2_mixer PRIVATE ${SDL2_LIBRARIES} ${SDL2_LIBRARY})
+target_link_libraries(SDL2_mixer PRIVATE SDL2::SDL2)