Skip to content

Commit b8d4c13

Browse files
authored
Use INTERFACE_LINK_OPTIONS in sdl2_vendor (#195)
* Use INTERFACE_LINK_OPTIONS in sdl2_vendor The SDL2_LIBRARIES value populated by sdl2-config.cmake doesn't actually contain the path to the SDL2 library, but rather the linker options necessary to link against SDL2. On Ubuntu, this appears to be `-lSDL2`. On RHEL, this is `-L/usr/lib64 -lSDL2`. The OBJECT_LOCATION property creates a Makefile target that the imported library depends on. On Ubuntu, this utilizes a little-known feature of GNU make where a target that starts with `-l` triggers a search on the VPATH for a library to satisfy the target. There are two problems here: 1. When SDL2_LIBRARIES contains more than just the `-lSDL2` linker option, the aforementioned VPATH search doesn't work correctly. 2. The VPATH search may not be able to find libSDL2.so if it isn't in a standard location, and the current approach doesn't make any effort to modify the VPATH in the presence of a `-L` option. I'm not sure if the `-l` behavior was known when this change was implemented, or if we just got lucky that this worked out on Ubuntu. In any case, switching to INTERFACE_LINK_OPTIONS is a more appropriate way to use the stuff in the SDL2_LIBRARIES value. Unfortunately, a SHARED target requires a backing object, so I had to switch it to an INTERFACE target to make this work. I'm not entirely sure what secondary effects that might have, but it appears to work in all cases that I tested. Signed-off-by: Scott K Logan <[email protected]>
1 parent 92b5a03 commit b8d4c13

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sdl2_vendor/cmake/Modules/Findsdl2_custom.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ if(SDL2_FOUND)
44
# and SDL2_LIBRARIES. In these cases, generate a fake SDL2::SDL2 so that
55
# downstreams consumers can just target_link_libraries(SDL2::SDL2)
66
if(NOT TARGET SDL2::SDL2)
7-
add_library(SDL2::SDL2 SHARED IMPORTED)
7+
add_library(SDL2::SDL2 INTERFACE IMPORTED)
88
set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIRS})
9-
set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION ${SDL2_LIBRARIES})
9+
target_link_libraries(SDL2::SDL2 INTERFACE ${SDL2_LIBRARIES})
1010
endif()
1111
endif()

0 commit comments

Comments
 (0)