Current best practice to select GCC compiler in Portfile

Rainer Müller raimue at macports.org
Thu Feb 26 06:30:34 PST 2015


On 2015-02-26 14:22, Artur Szostak wrote:
> Let me rephrase: Assuming I have to use gcc rather than clang. What
> is the standard/best way to do that in a Portfile?
> 
> I have a numerical code that gives inferior results with clang
> compared to gcc. Thus, I need to make sure the port uses GCC. Also,
> the code is C99, so that should mitigate any ABI issues.

Starting with Xcode 6, there are only clang and macports-clang-* in the
default list of usable compilers. To use gcc you explicitly need to
whitelist it.

The simplest and least flexible would be to just use a specific version
of gcc:

  configure.compiler macports-gcc-4.9


To be more flexible, you can also create variants that allow to choose
the version of gcc with +gcc49, +gcc48, etc:

  variant gcc47 description {Build with MacPorts gcc 4.7 compiler} conflicts gcc48 gcc49 {
      configure.compiler macports-gcc-4.7
  }

  variant gcc48 description {Build with MacPorts gcc 4.8 compiler} conflicts gcc47 gcc49 {
      configure.compiler macports-gcc-4.8
  }

  variant gcc49 description {Build with MacPorts gcc 4.9 compiler} conflicts gcc47 gcc48 {
      configure.compiler macports-gcc-4.9
  }

  if {![variant_isset gcc47] && ![variant_isset gcc48] && ![variant_isset gcc49]} {
      default_variants +gcc49
  }


Recently, there was also a new compilers port group added to the ports
tree which is supposed to generate these variants automatically.
However, as far as I was able to test it, it does not automatically
handle the selection of a default compiler yet as shown in the example
above using the variant_isset conditionals, so you still need to add
that. Manually adding this would make the construct a bit fragile as
new versions will be added to the port group in the future.

  compilers.choose    cc cpp
  compilers.setup     -clang -llvm -dragonegg
  default_variants    +gcc49

@Sean, David: did I do something wrong or is automatic selection just
not supported yet by the compilers port group?

Rainer


More information about the macports-dev mailing list