libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.57k stars 1.77k forks source link

SDL2 threading config in ./cmake/sdlchecks.cmake not correct for non-GNU compiler (e.g. SunPro cc) #10096

Open joncox123 opened 3 months ago

joncox123 commented 3 months ago

Within the cmake config script, ./cmake/sdlchecks.cmake, there is a check that decides how to enable pthread support for different platforms. If this check detects a platform of either "Solaris" or "SunOS", it issues set(PTHREAD_LDFLAGS "-pthread -lposix4"). However this is only correct for the GNU toolchain, such as gcc. As a result, configure and CMake will fail trying to find threading support on Solaris 10 1/13 (SPARC), and the build will fail, if it is being compiled with Sun's Solaris Studio 12.4 compilers, for example.

According to the Oracle documentation, the correct way to enabled pthread support is to use -mt -lpthread. Therefore, I suggest that a check be made more sophisticated, such that if GNU is not being used, the command is instead set(PTHREAD_LDFLAGS "-mt -lpthread"). I think there are other places in the CMake scripts that do check for GNU, so this should be trivial to add.

I don't think we should be assuming use of the GNU toolchain because they continue to introduce incompatible, breaking features and flags. FSF is great, but they have become so successful they are almost like Microsoft was in the 90s in that regard.

madebr commented 3 months ago

What is the output of the following, when pasted at the bottom of SDL's cmake script?

message("CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}")
icculus commented 3 months ago

I managed to get CMake 3.14 to work.

CMAKE_C_COMPILER_ID: SunPro

Also, if(SOLARIS) works, too.