standard way to require c++11?

Mojca Miklavec mojca at macports.org
Mon Apr 13 22:44:07 PDT 2015


On Tue, Apr 14, 2015 at 3:54 AM, Mihai Moldovan <ionic at macports.org> wrote:
> As a reply to what we discussed on IRC today, here's the relevant
> changes for the "C++11 on steroids" part of one of my ports
> (audacious-core):
>
> /.../
>
> +# A compiler supporting C++11 is required to build audacious and its
> plugins.
> +# The newer, the merrier.
> +# Compilers supporting C++11 are GCC >= 4.6 and clang >= 3.3.
> +# We do not know what "cc" is, so blacklist it as well.
> +compiler.blacklist-append   {*gcc-4.[0-5]} {clang < 500}
> macports-clang-2.* \
> +                            {macports-clang-3.[0-2]} cc
> +
>  platform darwin {
> [...]
> +    if {${os.major} >= 13} {
> +        if {${configure.cxx_stdlib} ne {} &&
> +            [string equal ${configure.cxx_stdlib} "libc++"]} {
> +            # Blacklist all GCC compilers to not accidentally pull in
> libstdc++.
> +            compiler.blacklist-append {*gcc*}
> +
> +            # Make sure binary runs on 10.9+ only.
> +            configure.ldflags-append  "-mmacosx-version-min=10.9"
>          } else {
> [...]
> +            ui_error "The system libraries in OS X 10.9 and higher use
> libc++. Thus, libstdc++ is not supported for this port."
> +            error "libstdc++ supported on <= 10.8 only."
>          }
>      } else {
> [...]
> +        if {${configure.cxx_stdlib} ne {} &&
> +            [string equal ${configure.cxx_stdlib} "libc++"]} {
> +            ui_error "The system libraries in OS X 10.8 and lower use
> libstdc++. Thus, libstdc++ is not supported for this port."
> +            error "libc++ supported on >= 10.9 only."
> +        } else {
> +            # Shameless copy from rust.
> +            depends_lib-append
> {path:lib/libstdc\\+\\+.6.dylib:libgcc}
> +
> +            # Force GCC 4.9.
> +            compiler.blacklist-append   {*clang*}
> +            compiler.fallback-append    macports-gcc-4.9

Could something like that be added to the compiler_blacklist
PortGroup? I believe that pure C++11 projects need consistent handling
and it would be very handy to allow a keyword like "compiler.c++11" or
"compiler.<something> c++11" to replace all of the logic above inside
a port.

> -------------------------------------------------------------------------
>
> Human-readable explanation:
>
> I've added the compiler_blacklist_versions PortGroup and blacklisted GCC
> < 4.6 and clang < 3.3, as only newer versions than that are fully
> C++11-compatible for all platforms.
>
> Then, I'm patching out -lc++ added by upstream for not very smart
> reasons ("I need this on my machine") -- AND CHANGED -std=gnu++11 TO
> -std=c++11. This is getting important soonish.
>
> Next up: checking the OS X version. For 10.9 (darwin 13) and higher, I
> error out if configure.cxx_stdlib is set to libstdc++. Likewise, I error
> out on 10.8 (darwin 12) and lower if configure.cxx_stdlib is set to libc++.

I don't fully understand that part. What if someone sets libc++
globally? And: won't that pull in libstdc++ from gcc?

> This leaves us with libc++ on 10.9+ and libstdc++ on 10.8-. Compatible
> with the system C++ runtime. Good.
>
> For 10.9+ with libc++, only blacklisting all GCC versions is necessary
> to not pull in libstdc++ accidentally.
>
> ===
> Caveat: make sure the port does not use -std=gnu++11 on 10.9+. It WILL
> make clang link to libstdc++ (even if passing -stdlib=libc++!), because
> gnu++11 is "c++11 with GNU extensions", which libc++ naturally does not
> provide.
> ===
>
> 10.8- is a little bit more complicated. We need to make sure a recent
> libstdc++ is available. What Apple ships might not be recent enough,
> especially on 10.7 and 10.6.

But then you'll run into problems that are more or less equivalent (or
worse) to mixing libc++ and libstdc++.
> Thus comes:
>
> depends_lib-append          {path:lib/libstdc\\+\\+.6.dylib:libgcc}
>
> In my experiments with a 10.6 VM, mp-clang-3.4 -std=c++11
> -stdlib=libstdc++ chokes on #include <type_traits>.

I would suspect some misconfiguration. I successfully compiled many
C++11 projects with mp-clang-3.4 (and libc++ of course).
> Hence, I blacklist all clang versions on 10.8-.
>
> This will leave us with quite a mess. Now all compilers are blacklisted
> on older systems. Great.
>
> Not a big deal, though. We can set compiler.fallback to macports-gcc-4.9
> and port will use this specific compiler, given all others are blacklisted.
>
> With that, compiling C++11 code on 10.8- works great (I've tested it in
> a 10.6 VM) -- and the binaries even run correctly.

I still believe that if the code was moved to a PortGroup, one would
have to allow building with clang against libc++.

(And I still believe that we need to set up buildbots to build the
complete macports against libc++ on 10.6-10.8.)

Mojca


More information about the macports-dev mailing list