cmake: use compatible interface properties to disallow linking to a different version of SDL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7970eac..bb43fbb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3278,6 +3278,8 @@ if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
if (NOT ANDROID)
set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
endif()
+ set_property(TARGET SDL2main APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
+ set_property(TARGET SDL2main PROPERTY INTERFACE_SDL_VERSION "SDL2")
endif()
if(ANDROID)
@@ -3365,8 +3367,10 @@ if(SDL_SHARED)
set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
endif()
# Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
- set_property(TARGET SDL2 PROPERTY INTERFACE_SDL2_SHARED TRUE)
set_property(TARGET SDL2 APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
+ set_property(TARGET SDL2 PROPERTY INTERFACE_SDL2_SHARED TRUE)
+ set_property(TARGET SDL2 APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
+ set_property(TARGET SDL2 PROPERTY INTERFACE_SDL_VERSION "SDL2")
endif()
if(SDL_STATIC)
@@ -3393,8 +3397,10 @@ if(SDL_STATIC)
set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
endif()
# Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
- set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL2_SHARED FALSE)
set_property(TARGET SDL2-static APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
+ set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL2_SHARED FALSE)
+ set_property(TARGET SDL2-static APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
+ set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL_VERSION "SDL2")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MAJOR_VERSION=${SDL_MAJOR_VERSION}")
@@ -3416,6 +3422,8 @@ if(SDL_TEST)
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>")
target_link_libraries(SDL2_test PRIVATE ${EXTRA_TEST_LIBS})
+ set_property(TARGET SDL2_test APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
+ set_property(TARGET SDL2_test PROPERTY INTERFACE_SDL_VERSION "SDL2")
endif()
##### Installation targets #####
diff --git a/VisualC/pkg-support/cmake/sdl2-config.cmake b/VisualC/pkg-support/cmake/sdl2-config.cmake
index 1a25259..0f03a63 100644
--- a/VisualC/pkg-support/cmake/sdl2-config.cmake
+++ b/VisualC/pkg-support/cmake/sdl2-config.cmake
@@ -68,6 +68,8 @@ if(EXISTS "${_sdl2_library}" AND EXISTS "${_sdl2_dll_library}")
IMPORTED_LOCATION "${_sdl2_dll_library}"
COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED"
INTERFACE_SDL2_SHARED "ON"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2_FOUND TRUE)
@@ -84,6 +86,8 @@ if(EXISTS "${_sdl2main_library}")
set_target_properties(SDL2::SDL2main
PROPERTIES
IMPORTED_LOCATION "${_sdl2main_library}"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2main_FOUND TRUE)
@@ -100,6 +104,8 @@ if(EXISTS "${_sdl2test_library}")
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
IMPORTED_LOCATION "${_sdl2test_library}"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2test_FOUND TRUE)
diff --git a/Xcode/SDL/pkg-support/resources/CMake/sdl2-config.cmake b/Xcode/SDL/pkg-support/resources/CMake/sdl2-config.cmake
index 28c34bc..e1b7713 100644
--- a/Xcode/SDL/pkg-support/resources/CMake/sdl2-config.cmake
+++ b/Xcode/SDL/pkg-support/resources/CMake/sdl2-config.cmake
@@ -57,6 +57,8 @@ if(NOT TARGET SDL2::SDL2)
INTERFACE_LINK_OPTIONS "SHELL:-F \"${SDL2_FRAMEWORK_PARENT_PATH}\";SHELL:-framework SDL2"
COMPATIBLE_INTERFACE_BOOL "SDL2_SHARED"
INTERFACE_SDL2_SHARED "ON"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2_FOUND TRUE)
diff --git a/sdl2-config.cmake.in b/sdl2-config.cmake.in
index ea2639c..d75f8b4 100644
--- a/sdl2-config.cmake.in
+++ b/sdl2-config.cmake.in
@@ -73,6 +73,8 @@ if(EXISTS "${_sdl2main_library}")
set_target_properties(SDL2::SDL2main
PROPERTIES
IMPORTED_LOCATION "${_sdl2main_library}"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
if(WIN32)
# INTERFACE_LINK_OPTIONS needs CMake 3.13
@@ -116,6 +118,8 @@ if(WIN32)
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_IMPLIB "${_sdl2_implib}"
IMPORTED_LOCATION "${_sdl2_dll}"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2_FOUND TRUE)
@@ -135,6 +139,8 @@ else()
INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${_sdl2_shared}"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2_FOUND TRUE)
@@ -155,6 +161,8 @@ if(EXISTS "${_sdl2_static}")
INTERFACE_LINK_LIBRARIES "${_sdl2_link_libraries};${_sdl2_static_private_libs}"
INTERFACE_LINK_DIRECTORIES "${_sdl2_libdirs};${_sdl2_static_private_libdirs}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2-static_FOUND TRUE)
@@ -174,6 +182,8 @@ if(EXISTS "${_sdl2test_library}")
IMPORTED_LOCATION "${_sdl2test_library}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+ INTERFACE_SDL_VERSION "SDL2"
)
endif()
set(SDL2_SDL2test_FOUND TRUE)