Skip to content

CMake: Check shared libs support using properties#15795

Draft
FtZPetruska wants to merge 3 commits into
libsdl-org:mainfrom
FtZPetruska:cmake_shared_available_property
Draft

CMake: Check shared libs support using properties#15795
FtZPetruska wants to merge 3 commits into
libsdl-org:mainfrom
FtZPetruska:cmake_shared_available_property

Conversation

@FtZPetruska

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

This queries CMake to check what platform support shared libraries instead of hard-coding the static-only platforms.

Existing Issue(s)

@nightmareci mentioned it on discord, dug into it and turns out it was a quick fix.

@nightmareci

Copy link
Copy Markdown
Contributor

I'm not so sure removing the explicit checks is advisable, as those toolchains might not correctly report they don't support dynamic libraries. So the safest bet is to leave those checks in, then do the dynamic library support query for all other platforms.

@FtZPetruska

Copy link
Copy Markdown
Contributor Author

I'm not so sure removing the explicit checks is advisable, as those toolchains might not correctly report they don't support dynamic libraries. So the safest bet is to leave those checks in, then do the dynamic library support query for all other platforms.

Looking at the CI run on my fork, it seems the property is supported on all the platforms listed in the check, however I see your point about it being risky.

How about this instead:

# Set the default for all platforms
get_cmake_property(SDL_SHARED_AVAILABLE TARGET_SUPPORTS_SHARED_LIBS)
...
# For platforms that are known to be static-only, make it always off regardless of what CMake thinks
if(platform_we_known_is_static_only)
  set(SDL_SHARED_AVAILABLE OFF)
endif()

@nightmareci

Copy link
Copy Markdown
Contributor

I'm not so sure removing the explicit checks is advisable, as those toolchains might not correctly report they don't support dynamic libraries. So the safest bet is to leave those checks in, then do the dynamic library support query for all other platforms.

Looking at the CI run on my fork, it seems the property is supported on all the platforms listed in the check, however I see your point about it being risky.

How about this instead:

# Set the default for all platforms
get_cmake_property(SDL_SHARED_AVAILABLE TARGET_SUPPORTS_SHARED_LIBS)
...
# For platforms that are known to be static-only, make it always off regardless of what CMake thinks
if(platform_we_known_is_static_only)
  set(SDL_SHARED_AVAILABLE OFF)
endif()

That's the right idea. But the actual code could be like this:

if(VITA OR PSP OR PS2 OR N3DS OR RISCOS OR NGAGE OR DOS)
  set(SDL_SHARED_AVAILABLE OFF)
else()
  get_cmake_property(SDL_SHARED_AVAILABLE TARGET_SUPPORTS_SHARED_LIBS)
endif()

So we'd only add new hard-coded checks if the shared library support query is broken on newly supported toolchains. Though it appears the code without the hard coded checks passed CI (except OpenBSD, but that's just broken right now), so maybe the hard-coded checks aren't needed.

@slouken slouken added this to the 3.6.0 milestone Jun 9, 2026
@madebr

madebr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This only works when the toolchain does set_property(GLOBAL TARGET_SUPPORTS_SHARED_LIBS PROPERTY TRUE | FALSE).

DOS (djgpp) supports dynamic libraries (through dxe's) but CMake from main does not support it (yet).

@madebr madebr marked this pull request as draft June 10, 2026 01:57
@madebr

madebr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

(I'm treating this pr as a scratchpad for the time being, when things cleared up we can remove everything through a force push)

@madebr

madebr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

So only RISCOS, NGage and DOS are causing trouble.
(ngage pr: ngagesdk/ngage-toolchain#23 @mupfdev)

The ps2 toolchain contains this:
https://github.com/ps2dev/ps2sdk/blob/cbca54a551535a07cbbdf51a5c35d957f2f8de9e/samples/ps2dev.cmake#L42
but no shared libraries are actually built. Why is that? Because CMAKE_SYSTEM_NAME is set to Generic?

@mupfdev

mupfdev commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Technically, Symbian does support shared libraries, however, DLLs can't have writable static data. The compiler won't report it as unsupported.

@slouken slouken modified the milestones: 3.6.0, 3.x Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants