Skip to content

Commit 707239a

Browse files
MaxHeimbrockclaude
andauthored
fix: avoid SDL3 target conflict when a system SDL3 is installed (#22)
find_package(SDL3) was followed by a check of INTERFACE_INCLUDE_DIRECTORIES on SDL3::SDL3 to decide whether the found package is usable. In the standard SDL3 package layout, SDL3::SDL3 is an alias of SDL3::SDL3-shared, which gets its include dirs transitively via SDL3::Headers instead of carrying them itself. The check therefore came back empty on e.g. Homebrew installs, SDL3 was fetched from source anyway, and its add_library(SDL3::Headers ALIAS ...) collided with the already-imported target: CMake Error: add_library cannot create ALIAS target "SDL3::Headers" because another target with the same name already exists. Trust the find_package result instead: fetch only when no SDL3::SDL3 target exists. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 7e76bea commit 707239a

1 file changed

Lines changed: 1 addition & 12 deletions

File tree

cmake/ExampleDeps.cmake

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,10 @@ if(NOT TARGET nlohmann_json::nlohmann_json)
1010
endif()
1111

1212
find_package(SDL3 CONFIG QUIET)
13-
set(_need_sdl3_fetch TRUE)
14-
if(TARGET SDL3::SDL3)
15-
get_target_property(_sdl3_include_dirs SDL3::SDL3 INTERFACE_INCLUDE_DIRECTORIES)
16-
if(_sdl3_include_dirs)
17-
set(_need_sdl3_fetch FALSE)
18-
endif()
19-
endif()
20-
21-
if(_need_sdl3_fetch)
13+
if(NOT TARGET SDL3::SDL3)
2214
FetchContent_Declare(
2315
SDL3
2416
URL https://github.com/libsdl-org/SDL/releases/download/release-3.2.26/SDL3-3.2.26.tar.gz
2517
)
2618
FetchContent_MakeAvailable(SDL3)
2719
endif()
28-
29-
unset(_need_sdl3_fetch)
30-
unset(_sdl3_include_dirs)

0 commit comments

Comments
 (0)