diff --git a/CMakeLists.txt b/CMakeLists.txt index f26a33a675..d7e5d3b409 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1748,9 +1748,10 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) return argc + dlnote.hdr.a; } ]==]) + set(SDL_DISABLE_DLOPEN_NOTES FALSE) check_c_source_compiles("${CHECK_ELF_DLNOTES_SRC}" COMPILER_SUPPORTS_ELFNOTES) - if(COMPILER_SUPPORTS_ELFNOTES) - set(HAVE_DLOPEN_NOTES TRUE) + if(NOT COMPILER_SUPPORTS_ELFNOTES) + set(SDL_DISABLE_DLOPEN_NOTES TRUE) endif() endif() diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj index fc014c84a3..cfd8970c0d 100644 --- a/VisualC-GDK/SDL/SDL.vcxproj +++ b/VisualC-GDK/SDL/SDL.vcxproj @@ -330,18 +330,21 @@ - - - + + + + + + @@ -351,9 +354,11 @@ - - + + + + @@ -361,11 +366,13 @@ + + @@ -384,7 +391,6 @@ - @@ -406,7 +412,7 @@ - + diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters index aee0794aaa..63bcf4bf40 100644 --- a/VisualC-GDK/SDL/SDL.vcxproj.filters +++ b/VisualC-GDK/SDL/SDL.vcxproj.filters @@ -238,17 +238,21 @@ - - + + + + + + @@ -258,8 +262,11 @@ - + + + + @@ -267,11 +274,13 @@ + + @@ -290,10 +299,10 @@ - + @@ -308,9 +317,10 @@ + - + diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj index 78539fc5a7..62209777c3 100644 --- a/VisualC/SDL/SDL.vcxproj +++ b/VisualC/SDL/SDL.vcxproj @@ -243,18 +243,21 @@ - - - + + + + + + @@ -264,9 +267,11 @@ - - + + + + @@ -274,11 +279,13 @@ + + @@ -297,7 +304,6 @@ - @@ -319,6 +325,7 @@ + diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters index 661206d034..9d525279ff 100644 --- a/VisualC/SDL/SDL.vcxproj.filters +++ b/VisualC/SDL/SDL.vcxproj.filters @@ -222,42 +222,51 @@ - - API Headers - - - API Headers - - - API Headers - API Headers API Headers + + API Headers + API Headers API Headers + + API Headers + API Headers API Headers + + API Headers + API Headers + + API Headers + API Headers API Headers + + API Headers + + + API Headers + API Headers @@ -276,19 +285,28 @@ API Headers + + API Headers + API Headers API Headers - - API Headers - API Headers - + + API Headers + + + API Headers + + + API Headers + + API Headers @@ -312,15 +330,27 @@ API Headers + + API Headers + API Headers + + API Headers + + + API Headers + API Headers API Headers + + API Headers + API Headers @@ -375,9 +405,6 @@ API Headers - - API Headers - API Headers @@ -387,6 +414,9 @@ API Headers + + API Headers + API Headers @@ -423,15 +453,24 @@ API Headers + + API Headers + API Headers + + API Headers + API Headers API Headers + + API Headers + API Headers diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index a0c52a3dff..eec0c6017e 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -54,6 +54,7 @@ 00CFA89D106B4BA100758660 /* ForceFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00CFA89C106B4BA100758660 /* ForceFeedback.framework */; platformFilters = (macos, ); }; 00D0D08410675DD9004B05EF /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D0D08310675DD9004B05EF /* CoreFoundation.framework */; platformFilters = (ios, maccatalyst, macos, tvos, ); settings = {ATTRIBUTES = (Required, ); }; }; 00D0D0D810675E46004B05EF /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007317C10858E15000B2BC32 /* Carbon.framework */; platformFilters = (macos, ); }; + 02D6A1C228A84B8F00A7F002 /* SDL_hidapi_sinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */; }; 1485C3312BBA4AF30063985B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1485C32F2BBA4A0C0063985B /* UniformTypeIdentifiers.framework */; platformFilters = (maccatalyst, macos, ); settings = {ATTRIBUTES = (Weak, ); }; }; 557D0CFA254586CA003913E3 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F37DC5F225350EBC0002E6F7 /* CoreHaptics.framework */; platformFilters = (ios, maccatalyst, macos, tvos, ); settings = {ATTRIBUTES = (Weak, ); }; }; 557D0CFB254586D7003913E3 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDABD23E28B6200529352 /* GameController.framework */; settings = {ATTRIBUTES = (Required, ); }; }; @@ -77,7 +78,6 @@ 89E580242D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c in Sources */ = {isa = PBXBuildFile; fileRef = 89E580212D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c */; }; 89E580252D03606400DAF6D3 /* SDL_hidapihaptic_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 89E580202D03606400DAF6D3 /* SDL_hidapihaptic_c.h */; }; 9846B07C287A9020000C35C8 /* SDL_hidapi_shield.c in Sources */ = {isa = PBXBuildFile; fileRef = 9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */; }; - 02D6A1C228A84B8F00A7F002 /* SDL_hidapi_sinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */; }; A1626A3E2617006A003F1973 /* SDL_triangle.c in Sources */ = {isa = PBXBuildFile; fileRef = A1626A3D2617006A003F1973 /* SDL_triangle.c */; }; A1626A522617008D003F1973 /* SDL_triangle.h in Headers */ = {isa = PBXBuildFile; fileRef = A1626A512617008C003F1973 /* SDL_triangle.h */; }; A1BB8B6327F6CF330057CFA8 /* SDL_list.c in Sources */ = {isa = PBXBuildFile; fileRef = A1BB8B6127F6CF320057CFA8 /* SDL_list.c */; }; @@ -417,6 +417,7 @@ F386F6F02884663E001840AA /* SDL_utils_c.h in Headers */ = {isa = PBXBuildFile; fileRef = F386F6E52884663E001840AA /* SDL_utils_c.h */; }; F386F6F92884663E001840AA /* SDL_utils.c in Sources */ = {isa = PBXBuildFile; fileRef = F386F6E62884663E001840AA /* SDL_utils.c */; }; F388C95528B5F6F700661ECF /* SDL_hidapi_ps3.c in Sources */ = {isa = PBXBuildFile; fileRef = F388C95428B5F6F600661ECF /* SDL_hidapi_ps3.c */; }; + F39344CE2E99771B0056986F /* SDL_dlopennote.h in Headers */ = {isa = PBXBuildFile; fileRef = F39344CD2E99771B0056986F /* SDL_dlopennote.h */; settings = {ATTRIBUTES = (Public, ); }; }; F395BF6525633B2400942BFF /* SDL_crc32.c in Sources */ = {isa = PBXBuildFile; fileRef = F395BF6425633B2400942BFF /* SDL_crc32.c */; }; F395C1932569C68F00942BFF /* SDL_iokitjoystick_c.h in Headers */ = {isa = PBXBuildFile; fileRef = F395C1912569C68E00942BFF /* SDL_iokitjoystick_c.h */; }; F395C19C2569C68F00942BFF /* SDL_iokitjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */; }; @@ -605,6 +606,7 @@ 007317C10858E15000B2BC32 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; }; 00CFA89C106B4BA100758660 /* ForceFeedback.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ForceFeedback.framework; path = System/Library/Frameworks/ForceFeedback.framework; sourceTree = SDKROOT; }; 00D0D08310675DD9004B05EF /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; + 02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_sinput.c; sourceTree = ""; }; 1485C32F2BBA4A0C0063985B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; }; 5616CA49252BB2A5005D5928 /* SDL_url.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_url.c; sourceTree = ""; }; 5616CA4A252BB2A6005D5928 /* SDL_sysurl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sysurl.h; sourceTree = ""; }; @@ -626,7 +628,6 @@ 89E580202D03606400DAF6D3 /* SDL_hidapihaptic_c.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDL_hidapihaptic_c.h; sourceTree = ""; }; 89E580212D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SDL_hidapihaptic_lg4ff.c; sourceTree = ""; }; 9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_shield.c; sourceTree = ""; }; - 02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_sinput.c; sourceTree = ""; }; A1626A3D2617006A003F1973 /* SDL_triangle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_triangle.c; sourceTree = ""; }; A1626A512617008C003F1973 /* SDL_triangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_triangle.h; sourceTree = ""; }; A1BB8B6127F6CF320057CFA8 /* SDL_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_list.c; sourceTree = ""; }; @@ -1000,6 +1001,7 @@ F386F6E52884663E001840AA /* SDL_utils_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_utils_c.h; sourceTree = ""; }; F386F6E62884663E001840AA /* SDL_utils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_utils.c; sourceTree = ""; }; F388C95428B5F6F600661ECF /* SDL_hidapi_ps3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_ps3.c; sourceTree = ""; }; + F39344CD2E99771B0056986F /* SDL_dlopennote.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDL_dlopennote.h; sourceTree = ""; }; F395BF6425633B2400942BFF /* SDL_crc32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_crc32.c; sourceTree = ""; }; F395C1912569C68E00942BFF /* SDL_iokitjoystick_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_iokitjoystick_c.h; sourceTree = ""; }; F395C1922569C68E00942BFF /* SDL_iokitjoystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_iokitjoystick.c; sourceTree = ""; }; @@ -1267,6 +1269,7 @@ F3D46A8B2D20625800D9CBDF /* SDL_copying.h */, F3D46A8C2D20625800D9CBDF /* SDL_cpuinfo.h */, F3D46A8D2D20625800D9CBDF /* SDL_dialog.h */, + F39344CD2E99771B0056986F /* SDL_dlopennote.h */, F3D46A8E2D20625800D9CBDF /* SDL_egl.h */, F3D46A8F2D20625800D9CBDF /* SDL_endian.h */, F3D46A902D20625800D9CBDF /* SDL_error.h */, @@ -2757,6 +2760,7 @@ A7D8B28A23E2514200DCD162 /* vulkan_xlib_xrandr.h in Headers */, A7D8B3D423E2514300DCD162 /* yuv_rgb.h in Headers */, F3FA5A252B59ACE000FEAD97 /* yuv_rgb_common.h in Headers */, + F39344CE2E99771B0056986F /* SDL_dlopennote.h in Headers */, F3FA5A1D2B59ACE000FEAD97 /* yuv_rgb_internal.h in Headers */, F3D8BDFC2D6D2C7000B22FA1 /* SDL_eventwatch_c.h in Headers */, F3DC38C92E5FC60300CD73DE /* SDL_libusb.h in Headers */, diff --git a/include/SDL3/SDL.h b/include/SDL3/SDL.h index ebfcbd11a6..7cfba76e61 100644 --- a/include/SDL3/SDL.h +++ b/include/SDL3/SDL.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include diff --git a/src/dynapi/SDL_dynapi_dlopennote.h b/include/SDL3/SDL_dlopennote.h similarity index 54% rename from src/dynapi/SDL_dynapi_dlopennote.h rename to include/SDL3/SDL_dlopennote.h index 8a2ec58ed1..a12ddbd7e7 100644 --- a/src/dynapi/SDL_dynapi_dlopennote.h +++ b/include/SDL3/SDL_dlopennote.h @@ -19,14 +19,83 @@ 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SDL_dynapi_dlopennote_h -#define SDL_dynapi_dlopennote_h +/* WIKI CATEGORY: DlopenNotes */ -#define SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED "required" -#define SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED "recommended" +/** + * # CategoryDlopenNotes + * + * This header allows you to annotate your code so external tools know about + * dynamic shared library dependencies. + * + * If you determine that your toolchain doesn't support dlopen notes, you can + * disable this feature by defining `SDL_DISABLE_DLOPEN_NOTES`. You can use this + * CMake snippet to check for support: + * + * ```cmake + * set(CHECK_ELF_DLNOTES_SRC [==[ + * #ifndef __ELF__ + * ELF DL notes is only supported on ELF platforms + * #endif + * __attribute__ ((used,aligned(4),section(".note.dlopen"))) static const struct { + * struct { int a; int b; int c; } hdr; char name[4]; __attribute__((aligned(4))) char json[24]; + * } dlnote = { { 4, 0x407c0c0aU, 16 }, "FDO", "[\\"a\\":{\\"a\\":\\"1\\",\\"b\\":\\"2\\"}]" }; + * int main(int argc, char *argv[]) { + * return argc + dlnote.hdr.a; + * } + * ]==]) + * check_c_source_compiles("${CHECK_ELF_DLNOTES_SRC}" COMPILER_SUPPORTS_ELFNOTES) + * if(NOT COMPILER_SUPPORTS_ELFNOTES) + * set(SDL_DISABLE_DLOPEN_NOTES TRUE) + * endif() + * ``` + */ + +#ifndef SDL_dlopennote_h +#define SDL_dlopennote_h + +/** + * Use this macro with SDL_ELF_NOTE_DLOPEN() to note that a dynamic shared library dependency is optional. + * + * Optional functionality uses the dependency, the binary will work and the dependency is only needed for full-featured installations. + * + * \since This macro is available since SDL 3.4.0. + * + * \sa SDL_ELF_NOTE_DLOPEN + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED + */ #define SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED "suggested" -#if defined(__ELF__) && defined(HAVE_DLOPEN_NOTES) +/** + * Use this macro with SDL_ELF_NOTE_DLOPEN() to note that a dynamic shared library dependency is recommended. + * + * Important functionality needs the dependency, the binary will work but in most cases the dependency should be provided. + * + * \since This macro is available since SDL 3.4.0. + * + * \sa SDL_ELF_NOTE_DLOPEN + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED + */ +#define SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED "recommended" + +/** + * Use this macro with SDL_ELF_NOTE_DLOPEN() to note that a dynamic shared library dependency is required. + * + * Core functionality needs the dependency, the binary will not work if it cannot be found. + * + * \since This macro is available since SDL 3.4.0. + * + * \sa SDL_ELF_NOTE_DLOPEN + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED + */ +#define SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED "required" + + +#if defined(__ELF__) && !defined(SDL_DISABLE_DLOPEN_NOTES) + +#include #define SDL_ELF_NOTE_DLOPEN_VENDOR "FDO" #define SDL_ELF_NOTE_DLOPEN_TYPE 0x407c0c0aU @@ -75,12 +144,44 @@ SDL_SONAME_ARRAY1 \ )(__VA_ARGS__) -// Create "unique" variable name using __LINE__, -// so creating elf notes on the same line is not supported +/* Create "unique" variable name using __LINE__, + * so creating elf notes on the same line is not supported + */ #define SDL_ELF_NOTE_JOIN2(A,B) A##B #define SDL_ELF_NOTE_JOIN(A,B) SDL_ELF_NOTE_JOIN2(A,B) -#define SDL_ELF_NOTE_UNIQUE_NAME SDL_ELF_NOTE_JOIN(s_dlopen_note_, __LINE__) +#define SDL_ELF_NOTE_UNIQUE_NAME SDL_ELF_NOTE_JOIN(s_SDL_dlopen_note_, __LINE__) +/** + * Note that your application has dynamic shared library dependencies. + * + * You can do this by adding the following to the global scope: + * + * ```c + * SDL_ELF_NOTE_DLOPEN( + * "png", + * "Support for loading PNG images using libpng (required for APNG)", + * SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, + * "libpng12.so.0" + * ); + * ``` + * + * Or if you support multiple versions of a library, you can list them: + * ```c + * // Our app supports SDL1, SDL2, and SDL3 by dynamically loading them + * SDL_ELF_NOTE_DLOPEN( + * "SDL", + * "Create windows through SDL video backend", + * SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED + * "libSDL-1.2.so.0", "libSDL2-2.0.so.0", "libSDL3.so.0" + * ); + * ``` + * + * \since This macro is available since SDL 3.4.0. + * + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED + * \sa SDL_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED + */ #define SDL_ELF_NOTE_DLOPEN(feature, description, priority, ...) \ SDL_ELF_NOTE_INTERNAL( \ "[{\"feature\":\"" feature \ @@ -89,10 +190,9 @@ "\",\"soname\":" SDL_SONAME_ARRAY(__VA_ARGS__) "}]", \ SDL_ELF_NOTE_UNIQUE_NAME) -#else - -#if defined (__GNUC__) && __GNUC__ < 3 +#elif defined (__GNUC__) && __GNUC__ < 3 +/* Variadic macros are not supported */ #define SDL_ELF_NOTE_DLOPEN #else @@ -101,6 +201,4 @@ #endif -#endif - -#endif +#endif /* SDL_dlopennote_h */ diff --git a/include/build_config/SDL_build_config.h.cmake b/include/build_config/SDL_build_config.h.cmake index 36d6ef988d..14dd86deaf 100644 --- a/include/build_config/SDL_build_config.h.cmake +++ b/include/build_config/SDL_build_config.h.cmake @@ -238,7 +238,7 @@ #cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR 1 #cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR_NP 1 -#cmakedefine HAVE_DLOPEN_NOTES 1 +#cmakedefine SDL_DISABLE_DLOPEN_NOTES 1 /* SDL internal assertion support */ #cmakedefine SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 1 diff --git a/src/SDL_internal.h b/src/SDL_internal.h index e891bb5095..7f8439e159 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -63,7 +63,6 @@ #include "SDL_build_config.h" #include "dynapi/SDL_dynapi.h" -#include "dynapi/SDL_dynapi_dlopennote.h" #if SDL_DYNAMIC_API #include "dynapi/SDL_dynapi_overrides.h"