[cmake-developers] [CMake] libc++ usage in CMake with Clang?

Craig Scott craig.scott at crascit.com
Tue Aug 21 19:40:36 EDT 2018


On Wed, Aug 22, 2018 at 7:18 AM, Robert Dailey <rcdailey.lists at gmail.com>
wrote:

> On Tue, Aug 21, 2018 at 3:47 PM Craig Scott <craig.scott at crascit.com>
> wrote:
> > Excuse the brevity, but it sounds like you might be looking for the
> CXX_EXTENSIONS target property (sorry if I've misunderstood your problem,
> let me know why it isn't appropriate if so). See the following article for
> a more complete overview of this and related properties:
> >
> > https://crascit.com/2015/03/28/enabling-cxx11-in-cmake/
>
> Unfortunately that's not the same. Extensions manage C++ language
> features and STL capabilities, but -stdlib is for selecting an STL
> implementation, AFAIK. Such as GNU STL and LLVM STL (which is libc++
> to clang).
>

Sorry, yes I misunderstood your problem. After a little digging, it seems
like you probably shouldn't be using the -stdlib option on Linux
<https://stackoverflow.com/a/50407611/1938798> anyway. FWIW, for Android,
the roadmap
<https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md> is
converging on a single STL implementation too.

Regarding your earlier comment:

I'll explain a bit why I'm asking. I noticed that for code bases that
> work on Android plus other UNIX platforms, they unconditionally
> specify `-stdlib=libc++`, however this doesn't work on Ubuntu by
> default, which uses gnu stl + gcc/clang. So  you get compiler errors.
> There's no way for me to "search" a platform to see if it is eligible
> for the libc++ flag, I simply have to either disable it completely or
> conditionally include it based on target platform and/or toolchain.
> None of these really address the root cause.

If you are trying to control which STL to use for Android builds,
CMake variables like CMAKE_ANDROID_STL_TYPE are probably the more
appropriate way to do that rather than hard-coding compiler flags.
This would also mean that non-Android builds won't be affected since
they would simply ignore that variable (and target properties it may
affect) and should then pick up the right STL implementation
automatically.The Android-specific variable would ideally be set in a
toolchain file rather than in the project itself.


-- 

Craig Scott
Melbourne, Australia
https://crascit.com

New book released: Professional CMake: A Practical Guide
<https://crascit.com/professional-cmake/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake-developers/attachments/20180822/ee72875e/attachment.html>


More information about the cmake-developers mailing list