From 66a28acaa471fd1c3c57cf2e99527a0765b4e2ee Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 26 Oct 2017 01:47:29 +0200 Subject: [PATCH] cmake: make SDL2 an imported target --- cmake/modules/FindSDL2.cmake | 12 ++++++++++++ rwgame/CMakeLists.txt | 3 +-- tests/CMakeLists.txt | 3 +-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmake/modules/FindSDL2.cmake b/cmake/modules/FindSDL2.cmake index 163abf46..97e8a9c3 100644 --- a/cmake/modules/FindSDL2.cmake +++ b/cmake/modules/FindSDL2.cmake @@ -194,3 +194,15 @@ IF(SDL2_STATIC) SET(SDL2_LIBRARY ${SDL2_LINK_FLAGS}) ENDIF() ENDIF(SDL2_STATIC) + +if(SDL2_FOUND) + set(SDL2_EXTRA_LIBS "${SDL2_LIBRARY_TEMP}") + list(REMOVE_ITEM SDL2_EXTRA_LIBS "${SDL2_LIBRARY_PATH}") + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C;CXX" + IMPORTED_LINK_DEPENDENT_LIBRARIES "${SDL2_EXTRA_LIBS}" + IMPORTED_LOCATION "${SDL2_LIBRARY_PATH}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) +endif() diff --git a/rwgame/CMakeLists.txt b/rwgame/CMakeLists.txt index 8e0bf3e3..cdfed6ee 100644 --- a/rwgame/CMakeLists.txt +++ b/rwgame/CMakeLists.txt @@ -50,7 +50,6 @@ target_include_directories(rwgame PRIVATE ${BULLET_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} - ${SDL2_INCLUDE_DIR} ) target_include_directories(rwgame @@ -64,7 +63,7 @@ target_link_libraries(rwgame ${Boost_LIBRARIES} ${OPENGL_LIBRARIES} ${BULLET_LIBRARIES} - ${SDL2_LIBRARY} + SDL2::SDL2 ) install(TARGETS rwgame RUNTIME DESTINATION "${BIN_DIR}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 97b89a25..bc2499c4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -60,7 +60,6 @@ target_include_directories(run_tests SYSTEM PRIVATE ${BULLET_INCLUDE_DIR} - ${SDL2_INCLUDE_DIR} ) target_include_directories(run_tests @@ -74,7 +73,7 @@ target_link_libraries(run_tests rwengine ${OPENGL_LIBRARIES} ${BULLET_LIBRARIES} - ${SDL2_LIBRARY} + SDL2::SDL2 ${PNG_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} )