C++11 support.
* Add options and ENV method to specify building in C++11 mode.
- Set C++ compiler flags to enable C++11 mode.
- To add options to support C++11 mode, a formula can now use
option :cxx11
to provide "--c++11" option, and detect and enable C++11 support in
install method using
ENV.cxx11 if build.cxx11?
Closes Homebrew/homebrew#22453.
This commit is contained in:
parent
0e6df1c3bf
commit
f2132c47bd
@ -45,11 +45,19 @@ class Cmd
|
||||
if @arg0 == 'cpp' or @arg0 == 'ld'
|
||||
@arg0.to_sym
|
||||
elsif @args.include? '-c'
|
||||
:cc
|
||||
if @arg0 =~ /(?:c|g|clang)\+\+/
|
||||
:cxx
|
||||
else
|
||||
:cc
|
||||
end
|
||||
elsif @args.include? '-E'
|
||||
:ccE
|
||||
else
|
||||
:ccld
|
||||
if @arg0 =~ /(?:c|g|clang)\+\+/
|
||||
:cxxld
|
||||
else
|
||||
:ccld
|
||||
end
|
||||
end
|
||||
end
|
||||
def tool
|
||||
@ -83,9 +91,9 @@ class Cmd
|
||||
args << "-syslibroot" << $sdkroot
|
||||
end if nclt?
|
||||
allflags = case mode
|
||||
when :ccld
|
||||
when :ccld, :cxxld
|
||||
cflags + args + cppflags + ldflags
|
||||
when :cc
|
||||
when :cc, :cxx
|
||||
cflags + args + cppflags
|
||||
when :ccE
|
||||
args + cppflags
|
||||
@ -149,9 +157,15 @@ class Cmd
|
||||
args
|
||||
end
|
||||
def cflags
|
||||
return [] unless cccfg? 'O'
|
||||
args = []
|
||||
if mode == :cxx
|
||||
args << '-std=c++11' if cccfg? 'x'
|
||||
args << '-stdlib=libc++' if cccfg? 'g'
|
||||
end
|
||||
|
||||
args = %w{-pipe -w -Os}
|
||||
return args unless cccfg? 'O'
|
||||
|
||||
args << '-pipe' << '-w' << '-Os'
|
||||
|
||||
# When bottling use the oldest supported CPU type.
|
||||
if cccfg? 'bc'
|
||||
@ -199,6 +213,9 @@ class Cmd
|
||||
case mode
|
||||
when :ld then args << '-headerpad_max_install_names'
|
||||
when :ccld then args << '-Wl,-headerpad_max_install_names'
|
||||
when :cxxld
|
||||
args << '-Wl,-headerpad_max_install_names'
|
||||
args << '-stdlib=libc++' if cccfg? 'g'
|
||||
end
|
||||
args
|
||||
end
|
||||
|
||||
@ -7,6 +7,7 @@ class BuildOptions
|
||||
|
||||
attr_accessor :args
|
||||
attr_accessor :universal
|
||||
attr_accessor :cxx11
|
||||
attr_reader :options
|
||||
protected :options
|
||||
|
||||
@ -25,6 +26,7 @@ class BuildOptions
|
||||
description ||= case name.to_s
|
||||
when "universal" then "Build a universal binary"
|
||||
when "32-bit" then "Build 32-bit only"
|
||||
when "c++11" then "Build using C++11 mode"
|
||||
end.to_s
|
||||
|
||||
@options << Option.new(name, description)
|
||||
@ -94,6 +96,11 @@ class BuildOptions
|
||||
universal || args.include?('--universal') && has_option?('universal')
|
||||
end
|
||||
|
||||
# True if the user requested to enable C++11 mode.
|
||||
def cxx11?
|
||||
cxx11 || args.include?('--c++11') && has_option?('c++11')
|
||||
end
|
||||
|
||||
# Request a 32-bit only build.
|
||||
# This is needed for some use-cases though we prefer to build Universal
|
||||
# when a 32-bit version is needed.
|
||||
|
||||
@ -322,6 +322,17 @@ module Stdenv
|
||||
end
|
||||
end
|
||||
|
||||
def cxx11
|
||||
if compiler == :clang
|
||||
append 'CXX', '-std=c++11'
|
||||
append 'CXX', '-stdlib=libc++'
|
||||
elsif compiler =~ /gcc-4\.(8|9)/
|
||||
append 'CXX', '-std=c++11'
|
||||
else
|
||||
raise "The selected compiler doesn't support C++11: #{compiler}"
|
||||
end
|
||||
end
|
||||
|
||||
def replace_in_cflags before, after
|
||||
CC_FLAG_VARS.each do |key|
|
||||
self[key] = self[key].sub(before, after) if has_key?(key)
|
||||
|
||||
@ -97,6 +97,8 @@ module Superenv
|
||||
# A - Installing from a bottle on PPC with Altivec
|
||||
# O - Enables argument refurbishing. Only active under the
|
||||
# make/bsdmake wrappers currently.
|
||||
# x - Enable C++11 mode.
|
||||
# g - Enable "-stdlib=libc++" for clang.
|
||||
#
|
||||
# On 10.8 and newer, these flags will also be present:
|
||||
# s - apply fix for sed's Unicode support
|
||||
@ -110,6 +112,17 @@ module Superenv
|
||||
append 'HOMEBREW_CCCFG', "u", ''
|
||||
end
|
||||
|
||||
def cxx11
|
||||
if self['HOMEBREW_CC'] == 'clang'
|
||||
append 'HOMEBREW_CCCFG', "x", ''
|
||||
append 'HOMEBREW_CCCFG', "g", ''
|
||||
elsif self['HOMEBREW_CC'] =~ /gcc-4\.(8|9)/
|
||||
append 'HOMEBREW_CCCFG', "x", ''
|
||||
else
|
||||
raise "The selected compiler doesn't support C++11: #{self['HOMEBREW_CC']}"
|
||||
end
|
||||
end
|
||||
|
||||
# m32 on superenv does not add any CC flags. It prevents "-m32" from being erased.
|
||||
def m32
|
||||
append 'HOMEBREW_CCCFG', "3", ''
|
||||
|
||||
@ -50,6 +50,7 @@ class SoftwareSpec
|
||||
end
|
||||
|
||||
def option name, description=nil
|
||||
name = 'c++11' if name == :cxx11
|
||||
name = name.to_s if Symbol === name
|
||||
raise "Option name is required." if name.empty?
|
||||
raise "Options should not start with dashes." if name[0, 1] == "-"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user