cmake: Fix build failure on msys2/mingw64

This is due to the use of `${SDL2_LIBRARIES}` over `SDL2::SDL2`.

On some 'old' OSes such as Ubuntu 20.04, the SDL2 CMake config does
not set an SDL2:SDL2 target but rather defines SDL2_LIBRARIES and
SDL2_INCLUDE_DIRS variables.

This patch creates an SDL2::SDL2 target, if not already set, based on
those 2 variables.
This commit is contained in:
samuel degrande 2023-05-15 16:41:34 +00:00 committed by Jakob Bornecrantz
parent a07942b782
commit 1ad168cfc5
7 changed files with 10 additions and 17 deletions

View file

@ -427,12 +427,10 @@ if(XRT_HAVE_OPENGLES AND NOT XRT_HAVE_EGL)
endif()
if(XRT_HAVE_SDL2)
if(NOT DEFINED SDL2_LIBRARIES)
if(TARGET SDL2::SDL2-static)
set(SDL2_LIBRARIES SDL2::SDL2-static)
elseif(TARGET SDL2::SDL2)
set(SDL2_LIBRARIES SDL2::SDL2)
endif()
if(NOT TARGET SDL2::SDL2 AND DEFINED SDL2_LIBRARIES)
add_library(SDL2::SDL2 INTERFACE IMPORTED)
target_include_directories(SDL2::SDL2 SYSTEM INTERFACE "${SDL2_INCLUDE_DIRS}")
target_link_libraries(SDL2::SDL2 INTERFACE "${SDL2_LIBRARIES}")
endif()
endif()

View file

@ -138,10 +138,8 @@ if(XRT_HAVE_OPENGL)
target_link_libraries(
xrt-external-imgui-sdl2
PUBLIC xrt-external-imgui
PUBLIC ${SDL2_LIBRARIES}
PUBLIC SDL2::SDL2
)
target_include_directories(xrt-external-imgui-sdl2 PUBLIC ${SDL2_INCLUDE_DIRS})
target_include_directories(
xrt-external-imgui-sdl2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui
)

View file

@ -163,7 +163,7 @@ if(XRT_FEATURE_DEBUG_GUI)
if(XRT_HAVE_SDL2)
target_link_libraries(
aux_util_debug_gui PRIVATE st_gui xrt-external-imgui-sdl2 ${SDL2_LIBRARIES}
aux_util_debug_gui PRIVATE st_gui xrt-external-imgui-sdl2 SDL2::SDL2
)
if(XRT_BUILD_DRIVER_QWERTY)

View file

@ -215,8 +215,7 @@ if(XRT_MODULE_COMPOSITOR_MAIN)
endif()
if(XRT_FEATURE_WINDOW_PEEK)
target_sources(comp_main PRIVATE main/comp_window_peek.c)
target_link_libraries(comp_main PRIVATE ${SDL2_LIBRARIES})
target_include_directories(comp_main PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(comp_main PRIVATE SDL2::SDL2)
endif()
if(WIN32)
target_sources(comp_main PRIVATE main/comp_window_mswin.c)

View file

@ -70,8 +70,7 @@ if(XRT_BUILD_DRIVER_QWERTY)
qwerty/qwerty_prober.c
qwerty/qwerty_sdl.c
)
target_link_libraries(drv_qwerty PRIVATE xrt-interfaces aux_util ${SDL2_LIBRARIES})
target_include_directories(drv_qwerty PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(drv_qwerty PRIVATE xrt-interfaces aux_util SDL2::SDL2)
list(APPEND ENABLED_DRIVERS qwerty)
add_library(drv_qwerty_includes INTERFACE)

View file

@ -20,7 +20,6 @@ target_link_libraries(
target_instance_no_comp
xrt-external-imgui-sdl2
)
target_include_directories(gui PUBLIC ${SDL2_INCLUDE_DIRS})
if(WIN32)
target_link_libraries(gui PRIVATE SDL2::SDL2main)
endif()

View file

@ -105,9 +105,9 @@ endif()
if(_have_opengl_test)
target_link_libraries(
tests_comp_client_opengl PRIVATE comp_client comp_mock aux_ogl ${SDL2_LIBRARIES}
tests_comp_client_opengl PRIVATE comp_client comp_mock aux_ogl SDL2::SDL2
)
target_include_directories(tests_comp_client_opengl PRIVATE ${SDL2_INCLUDE_DIRS})
target_include_directories(tests_comp_client_opengl PRIVATE SDL2::SDL2)
endif()
if(XRT_HAVE_VULKAN AND XRT_HAVE_D3D11)