Skip to content

Commit 0be1a37

Browse files
committed
Use INTERFACE targets for SDL2 libraries
1 parent 5cdd028 commit 0be1a37

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ target_compile_definitions(supertux2_lib PUBLIC -DGLM_ENABLE_EXPERIMENTAL)
205205

206206
if(WIN32)
207207
add_executable(supertux2 WIN32 src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
208-
target_link_libraries(supertux2 ${SDL2MAIN_LIBRARIES})
208+
target_link_libraries(supertux2 SDL2main)
209209
else()
210210
add_executable(supertux2 src/main.cpp)
211211
endif()
@@ -238,14 +238,7 @@ endif()
238238

239239
## Link supertux binary with squirrel and other libraries
240240
if(NOT EMSCRIPTEN)
241-
target_include_directories(supertux2_lib SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS})
242-
target_include_directories(supertux2_lib SYSTEM PUBLIC ${SDL2IMAGE_INCLUDE_DIRS})
243-
if(VCPKG_BUILD AND NOT WIN32)
244-
target_link_libraries(supertux2_lib PRIVATE SDL2::SDL2main SDL2::SDL2 SDL2::SDL2_image)
245-
else()
246-
target_link_libraries(supertux2_lib PUBLIC ${SDL2_LIBRARIES})
247-
target_link_libraries(supertux2_lib PUBLIC ${SDL2IMAGE_LIBRARIES})
248-
endif()
241+
target_link_libraries(supertux2_lib PUBLIC SDL2 SDL2_image)
249242
endif()
250243

251244
target_link_libraries(supertux2_lib PUBLIC SDL2_ttf)

mk/cmake/SuperTux/ProvideSDL2.cmake

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
message(STATUS "Checking for SDL2")
12
if(WIN32)
23
if(VCPKG_BUILD)
34
find_package(SDL2 CONFIG REQUIRED)
45
find_library(SDL2IMAGE_LIBRARIES SDL2_image)
56
find_library(SDL2MAIN_LIBRARIES SDL2main)
6-
message(STATUS "SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIRS}")
77
else()
88
find_path(SDL2_INCLUDE_DIRS NAMES SDL.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2")
99
find_path(SDL2IMAGE_INCLUDE_DIRS NAMES SDL_image.h PATHS "${DEPENDENCY_FOLDER}/include/SDL2_image")
@@ -25,7 +25,6 @@ else()
2525
set(SDL2IMAGE_INCLUDE_DIRS ${SDL2IMAGE_INCLUDE_DIRS}/SDL2)
2626
find_library(SDL2_LIBRARIES SDL2)
2727
find_library(SDL2IMAGE_LIBRARIES SDL2_image)
28-
message(STATUS "SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIRS}")
2928
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
3029
# 32-bit
3130
find_library(SDL2_LIBRARIES SDL2)
@@ -34,18 +33,38 @@ else()
3433
find_path(SDL2IMAGE_INCLUDE_DIRS SDL2/SDL_image.h)
3534
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS}/SDL2)
3635
set(SDL2IMAGE_INCLUDE_DIRS ${SDL2IMAGE_INCLUDE_DIRS}/SDL2)
37-
message(STATUS "SDL LIBS: ${SDL2_LIBRARIES}")
38-
message(STATUS "SDL INCL: ${SDL2_INCLUDE_DIRS}")
3936
else()
4037
# 64-bit
4138
include(FindPkgConfig)
4239
pkg_search_module(SDL2 REQUIRED sdl2>=2.0.1)
4340
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
41+
set(SDL2_LIBRARIES "${SDL2_LINK_LIBRARIES}")
42+
set(SDL2IMAGE_LIBRARIES "${SDL2IMAGE_LINK_LIBRARIES}")
4443
endif()
4544
endif()
4645
endif()
4746
set(HAVE_SDL TRUE)
4847

48+
message(STATUS " SDL2_LIBRARIES: ${SDL2_LIBRARIES}")
49+
message(STATUS " SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}")
50+
message(STATUS " SDL2IMAGE_LIBRARIES: ${SDL2IMAGE_LIBRARIES}")
51+
message(STATUS " SDL2IMAGE_INCLUDE_DIRS: ${SDL2IMAGE_INCLUDE_DIRS}")
52+
53+
add_library(SDL2 INTERFACE)
54+
set_target_properties(SDL2 PROPERTIES
55+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
56+
INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}")
57+
58+
add_library(SDL2main INTERFACE)
59+
set_target_properties(SDL2main PROPERTIES
60+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
61+
INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}")
62+
63+
add_library(SDL2_image INTERFACE)
64+
set_target_properties(SDL2_image PROPERTIES
65+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2IMAGE_INCLUDE_DIRS}"
66+
INTERFACE_LINK_LIBRARIES "${SDL2IMAGE_LIBRARIES}")
67+
4968
mark_as_advanced(
5069
SDL2_INCLUDE_DIRS
5170
SDL2_LIBRARIES

0 commit comments

Comments
 (0)