Skip to content

Commit f104525

Browse files
committed
mkmf: cpp_command in C++ mode
1 parent a4fa75e commit f104525

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/mkmf.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,16 @@ def cc_command(opt="")
573573
conf)
574574
end
575575

576-
def cpp_command(outfile, opt="")
576+
def cpp_config(opt)
577577
conf = cc_config(opt)
578578
if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
579579
conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
580580
end
581+
conf
582+
end
583+
584+
def cpp_command(outfile, opt="")
585+
conf = cpp_config(opt)
581586
RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
582587
conf)
583588
end
@@ -3037,6 +3042,15 @@ def cc_command(opt="")
30373042
conf)
30383043
end
30393044

3045+
def cpp_command(outfile, opt="")
3046+
conf = cpp_config(opt)
3047+
cpp = conf['CPP'].sub(/(\A|\s)#{Regexp.quote(conf['CC'])}(?=\z|\s)/) {
3048+
"#$1#{conf['CXX']}"
3049+
}
3050+
RbConfig::expand("#{cpp} #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #{opt} #{CONFTEST_CXX} #{outfile}",
3051+
conf)
3052+
end
3053+
30403054
def link_command(ldflags, *opts)
30413055
conf = link_config(ldflags, *opts)
30423056
RbConfig::expand(TRY_LINK_CXX.dup, conf)

test/mkmf/test_egrep_cpp.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ def test_egrep_cpp
1010
def test_not_have_func
1111
assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG)
1212
end
13+
14+
class TestMkmfEgrepCxx < self
15+
def test_cxx_egrep_cpp
16+
assert_equal(true, MakeMakefile["C++"].egrep_cpp(/^ok/, <<~SRC), MKMFLOG)
17+
#ifdef __cplusplus
18+
ok
19+
#else
20+
#error not C++
21+
#endif
22+
SRC
23+
end
24+
end
1325
end

0 commit comments

Comments
 (0)