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 - Clang detection in CMake build is incorrect
Summary: Clang detection in CMake build is incorrect
Status: RESPONDED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: x86 Windows 10
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-09 14:41 UTC by vladius
Modified: 2021-02-10 13:14 UTC (History)
1 user (show)

See Also:


Attachments
Robust Clang and libc detection. (5.95 KB, patch)
2021-02-10 09:00 UTC, vladius
Details | Diff
NEW Robust Clang and libc detection. (1.09 KB, patch)
2021-02-10 13:14 UTC, vladius
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.