Skip to content

Commit

Permalink
Add ENV.cxx14 and option :cxx14
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoonj committed Sep 13, 2017
1 parent f3ec40d commit 8cfb487
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Library/Homebrew/build_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def cxx11?
include?("c++11") && option_defined?("c++11")
end

# True if a {Formula} is being built in C++14 mode.
def cxx14?
include?("c++14") && option_defined?("c++14")
end

# @private
def used_options
@options & @args
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/extend/ENV/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ def gcc_with_cxx11_support?(cc)
version = cc[/^gcc-(\d+(?:\.\d+)?)$/, 1]
version && Version.create(version) >= Version.create("4.8")
end

def gcc_with_cxx14_support?(cc)
version = cc[/^gcc-(\d+(?:\.\d+)?)$/, 1]
version && Version.create(version) >= Version.create("5")
end
end

require "extend/os/extend/ENV/shared"
11 changes: 11 additions & 0 deletions Library/Homebrew/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ def cxx11
end
end

def cxx14
if compiler == :clang
append "CXX", "-std=c++14"
append "CXX", "-stdlib=libc++"
elsif gcc_with_cxx14_support?(compiler)
append "CXX", "-std=c++14"
else
raise "The selected compiler doesn't support C++14: #{compiler}"
end
end

def libcxx
append "CXX", "-stdlib=libc++" if compiler == :clang
end
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def setup_build_environment(formula = nil)
# O - Enables argument refurbishing. Only active under the
# make/bsdmake wrappers currently.
# x - Enable C++11 mode.
# y - Enable C++14 mode.
# g - Enable "-stdlib=libc++" for clang.
# h - Enable "-stdlib=libstdc++" for clang.
# K - Don't strip -arch <arch>, -m32, or -m64
Expand Down Expand Up @@ -305,6 +306,17 @@ def cxx11
end
end

def cxx14
if homebrew_cc == "clang"
append "HOMEBREW_CCCFG", "y", ""
append "HOMEBREW_CCCFG", "g", ""
elsif gcc_with_cxx14_support?(homebrew_cc)
append "HOMEBREW_CCCFG", "y", ""
else
raise "The selected compiler doesn't support C++14: #{homebrew_cc}"
end
end

def libcxx
append "HOMEBREW_CCCFG", "g", "" if compiler == :clang
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/rubocops/options_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)

if option !~ /with(out)?-/ &&
option != "cxx11" &&
option != "cxx14" &&
option != "universal"
problem "Options should begin with with/without."\
" Migrate '--#{option}' with `deprecated_option`."
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/shims/super/cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Cmd
def cxxflags
args = cflags
args << "-std=c++11" if cxx11?
args << "-std=c++14" if cxx14?
args << "-stdlib=libc++" if libcxx?
args << "-stdlib=libstdc++" if libstdcxx?
args
Expand Down Expand Up @@ -298,6 +299,10 @@ class Cmd
config.include?("x")
end
def cxx14?
config.include?("y")
end
def libcxx?
config.include?("g")
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SoftwareSpec
PREDEFINED_OPTIONS = {
universal: Option.new("universal", "Build a universal binary"),
cxx11: Option.new("c++11", "Build using C++11 mode"),
cxx14: Option.new("c++14", "Build using C++14 mode"),
}.freeze

attr_reader :name, :full_name, :owner
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def cxx11?
include?("c++11")
end

def cxx14?
include?("c++14")
end

def head?
spec == :head
end
Expand Down
32 changes: 32 additions & 0 deletions Library/Homebrew/test/ENV_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,36 @@
expect(subject["HOMEBREW_CCCFG"]).to include("g")
end
end

describe "#cxx14" do
it "raises an error when the compiler isn't supported" do
%w[gcc gcc-4.7 gcc-4.8 gcc-4.9].each do |compiler|
subject["HOMEBREW_CC"] = compiler

expect { subject.cxx14 }
.to raise_error(/The selected compiler doesn't support C\+\+14:/)

expect(subject["HOMEBREW_CCCFG"]).to be nil
end
end

it "supports gcc-5" do
subject["HOMEBREW_CC"] = "gcc-5"
subject.cxx14
expect(subject["HOMEBREW_CCCFG"]).to include("y")
end

example "supports gcc-6" do
subject["HOMEBREW_CC"] = "gcc-6"
subject.cxx14
expect(subject["HOMEBREW_CCCFG"]).to include("y")
end

it "supports clang" do
subject["HOMEBREW_CC"] = "clang"
subject.cxx14
expect(subject["HOMEBREW_CCCFG"]).to include("y")
expect(subject["HOMEBREW_CCCFG"]).to include("g")
end
end
end
6 changes: 6 additions & 0 deletions Library/Homebrew/test/software_spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
expect(subject).not_to have_defined_option("cxx11")
end

it "special cases the cxx14 option" do
subject.option(:cxx14)
expect(subject).to have_defined_option("c++14")
expect(subject).not_to have_defined_option("cxx14")
end

it "supports options with descriptions" do
subject.option("bar", "description")
expect(subject.options.first.description).to eq("description")
Expand Down

0 comments on commit 8cfb487

Please sign in to comment.