From 85b0111a6eb36f4cfb9083dad491c5c2396cb737 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 7 Nov 2018 21:44:04 -0500 Subject: [PATCH] implement ConfigureOp#check_cxx_header --- .../configure/check_cxx_header_failure.rb | 3 +++ .../configure/check_cxx_header_no_fail.rb | 3 +++ .../configure/check_cxx_header_success.rb | 3 +++ lib/rscons/application.rb | 5 ++++ lib/rscons/configure_op.rb | 21 +++++++++++++++ spec/build_tests_spec.rb | 26 +++++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 build_tests/configure/check_cxx_header_failure.rb create mode 100644 build_tests/configure/check_cxx_header_no_fail.rb create mode 100644 build_tests/configure/check_cxx_header_success.rb diff --git a/build_tests/configure/check_cxx_header_failure.rb b/build_tests/configure/check_cxx_header_failure.rb new file mode 100644 index 0000000..a06f439 --- /dev/null +++ b/build_tests/configure/check_cxx_header_failure.rb @@ -0,0 +1,3 @@ +configure do + check_cxx_header "not___found.h" +end diff --git a/build_tests/configure/check_cxx_header_no_fail.rb b/build_tests/configure/check_cxx_header_no_fail.rb new file mode 100644 index 0000000..adf647b --- /dev/null +++ b/build_tests/configure/check_cxx_header_no_fail.rb @@ -0,0 +1,3 @@ +configure do + check_cxx_header "not___found.h", fail: false +end diff --git a/build_tests/configure/check_cxx_header_success.rb b/build_tests/configure/check_cxx_header_success.rb new file mode 100644 index 0000000..5e01216 --- /dev/null +++ b/build_tests/configure/check_cxx_header_success.rb @@ -0,0 +1,3 @@ +configure do + check_cxx_header "string.h" +end diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index ce8ee19..07bcb32 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -99,6 +99,11 @@ module Rscons co.check_c_header(*cch) end end + if cchs = @script.check_cxx_headers + cchs.each do |cch| + co.check_cxx_header(*cch) + end + end rescue ConfigureOp::ConfigureFailure rv = 1 end diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 3977ab7..ca32f39 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -119,6 +119,27 @@ module Rscons common_config_checks(status, options) end + # Check for a C++ header. + def check_cxx_header(header_name, options = {}) + $stdout.write("Checking for C++ header '#{header_name}'... ") + File.open("#{@work_dir}/cfgtest.cxx", "wb") do |fh| + fh.puts <<-EOF + #include "#{header_name}" + int main(int argc, char * argv[]) { + return 0; + } + EOF + end + vars = { + "LD" => "${CXX}", + "_SOURCES" => "#{@work_dir}/cfgtest.cxx", + "_TARGET" => "#{@work_dir}/cfgtest.exe", + } + command = @env.build_command("${LDCMD}", vars) + _, _, status = log_and_test_command(command) + common_config_checks(status, options) + end + private # Test a C compiler. diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index e75b4f9..09c1118 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1646,6 +1646,32 @@ EOF expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/ end end + + context "check_cxx_header" do + it "succeeds when the requested header is found" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_cxx_header_success.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for C\+\+ header 'string\.h'... found/ + end + + it "fails when the requested header is not found" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_cxx_header_failure.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to_not eq 0 + expect(result.stdout).to match /Checking for C\+\+ header 'not___found\.h'... not found/ + end + + it "succeeds when the requested header is not found but :fail is set to false" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_cxx_header_no_fail.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for C\+\+ header 'not___found\.h'... not found/ + end + end end end