We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5542

Summary: Clang detection in CMake build is incorrect
Product: SDL Reporter: vladius <vturbanov>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESPONDED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.0   
Hardware: x86   
OS: Windows 10   
Attachments: Robust Clang and libc detection.
NEW Robust Clang and libc detection.

Description vladius 2021-02-09 14:41:49 UTC
The detection mechanism uses CMAKE_COMPILER_IS_GNUCC first, but that actually hides the Clang detection that way, cause Clang is also GNU-compliant.

I would suggest swapping the two clauses like so:

# Compiler info
>if(CMAKE_C_COMPILER_ID MATCHES "Clang")
>  set(USE_CLANG TRUE)
>  set(OPT_DEF_ASM TRUE)
>elseif(CMAKE_COMPILER_IS_GNUCC)
>  set(USE_GCC TRUE)
>  set(OPT_DEF_ASM TRUE)

That would allow for a proper default LIBC value detection via:
>if(UNIX OR MINGW OR MSYS OR USE_CLANG)
>  set(OPT_DEF_LIBC ON)
>endif()

This doesn't uses the OR USE_CLANG now currently, and misses that available Clang's libc that way. This second code snippet must also be moved down, right after USE_CLANG detection to be able to work correctly.

Thank you.
Comment 1 Sam Lantinga 2021-02-09 23:05:35 UTC
Can you attach a tested patch that implements this change?

Thanks!
Comment 2 vladius 2021-02-10 09:00:30 UTC
Created attachment 4789 [details]
Robust Clang and libc detection.

I'm now successfully detecting the presence of the libc under Clang with the following changes:
Comment 3 vladius 2021-02-10 09:01:11 UTC
Added a patch.
Comment 4 Ozkan Sezer 2021-02-10 12:03:50 UTC
(In reply to vladius from comment #2)
> Created attachment 4789 [details]
> Robust Clang and libc detection.
> 
> I'm now successfully detecting the presence of the libc under Clang with the
> following changes:

This patch touches things it is not supposed to,  e.g.: all
changes after about line 400.
Comment 5 vladius 2021-02-10 13:11:47 UTC
(In reply to Ozkan Sezer from comment #4)
> (In reply to vladius from comment #2)
> > Created attachment 4789 [details]
> > Robust Clang and libc detection.
> > 
> > I'm now successfully detecting the presence of the libc under Clang with the
> > following changes:
> 
> This patch touches things it is not supposed to,  e.g.: all
> changes after about line 400.

You're right. Seems like I've done something wrong. Not quite used to Mercurial as of now.
Attaching the correct patch now.
Comment 6 vladius 2021-02-10 13:14:13 UTC
Created attachment 4791 [details]
NEW Robust Clang and libc detection.

Together with a patch from this issue https://bugzilla.libsdl.org/show_bug.cgi?id=5539
Clang now should compile correctly on Windows via CMake.