diff --git a/build_tests/configure/check_c_header_no_fail_set_define.rb b/build_tests/configure/check_c_header_no_fail_set_define.rb new file mode 100644 index 0000000..f9031d0 --- /dev/null +++ b/build_tests/configure/check_c_header_no_fail_set_define.rb @@ -0,0 +1,7 @@ +configure do + check_c_header "not___found.h", fail: false, set_define: "HAVE_NOT___FOUND_H" +end + +Rscons::Environment.new(echo: :command) do |env| + env.Object("simple.o", "simple.c") +end diff --git a/build_tests/configure/check_c_header_success_set_define.rb b/build_tests/configure/check_c_header_success_set_define.rb new file mode 100644 index 0000000..a321fcb --- /dev/null +++ b/build_tests/configure/check_c_header_success_set_define.rb @@ -0,0 +1,7 @@ +configure do + check_c_header "string.h", set_define: "HAVE_STRING_H" +end + +Rscons::Environment.new(echo: :command) do |env| + env.Object("simple.o", "simple.c") +end diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 2f3fe5f..2be1e3a 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -398,6 +398,9 @@ module Rscons success_message = options[:success_message] || "found" if status == 0 Ansi.write($stdout, :green, "#{success_message}\n") + if options[:set_define] + store_append("CPPDEFINES" => options[:set_define]) + end else if options.has_key?(:fail) and not options[:fail] Ansi.write($stdout, :yellow, "not found\n") @@ -406,9 +409,6 @@ module Rscons raise ConfigureFailure.new end end - if options[:set_define] - store_append("CPPDEFINES" => options[:set_define]) - end end # Check if a directory contains a certain executable. diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index a4af799..e332c83 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1659,6 +1659,30 @@ EOF expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/ end + + it "sets the specified define when the header is found" do + test_dir "configure" + result = run_rscons(rsconscript: "check_c_header_success_set_define.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/ + result = run_rscons(rsconscript: "check_c_header_success_set_define.rb", op: "build") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /-DHAVE_STRING_H/ + end + + it "does not set the specified define when the header is not found" do + test_dir "configure" + result = run_rscons(rsconscript: "check_c_header_no_fail_set_define.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/ + result = run_rscons(rsconscript: "check_c_header_no_fail_set_define.rb", op: "build") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to_not match /-DHAVE_/ + end end context "check_cxx_header" do