From 1ad168cfc5f6450731cad1605baf68e9237c5864 Mon Sep 17 00:00:00 2001 From: samuel degrande Date: Mon, 15 May 2023 16:41:34 +0000 Subject: [PATCH] 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. --- CMakeLists.txt | 10 ++++------ src/external/CMakeLists.txt | 4 +--- src/xrt/auxiliary/util/CMakeLists.txt | 2 +- src/xrt/compositor/CMakeLists.txt | 3 +-- src/xrt/drivers/CMakeLists.txt | 3 +-- src/xrt/targets/gui/CMakeLists.txt | 1 - tests/CMakeLists.txt | 4 ++-- 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e6aefd7a..c57fb9e55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt index 347e5eab0..474bb97d3 100644 --- a/src/external/CMakeLists.txt +++ b/src/external/CMakeLists.txt @@ -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 ) diff --git a/src/xrt/auxiliary/util/CMakeLists.txt b/src/xrt/auxiliary/util/CMakeLists.txt index 93582a854..5e8347ca1 100644 --- a/src/xrt/auxiliary/util/CMakeLists.txt +++ b/src/xrt/auxiliary/util/CMakeLists.txt @@ -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) diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt index cd614dc92..b87965070 100644 --- a/src/xrt/compositor/CMakeLists.txt +++ b/src/xrt/compositor/CMakeLists.txt @@ -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) diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt index 4e994a0a1..a6d5a1d8d 100644 --- a/src/xrt/drivers/CMakeLists.txt +++ b/src/xrt/drivers/CMakeLists.txt @@ -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) diff --git a/src/xrt/targets/gui/CMakeLists.txt b/src/xrt/targets/gui/CMakeLists.txt index 1cf3f5dd3..2aac66147 100644 --- a/src/xrt/targets/gui/CMakeLists.txt +++ b/src/xrt/targets/gui/CMakeLists.txt @@ -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() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 771e948d4..befe39066 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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)