diff --git a/build_tests/configure/check_lib_failure.rb b/build_tests/configure/check_lib_failure.rb new file mode 100644 index 0000000..2c69245 --- /dev/null +++ b/build_tests/configure/check_lib_failure.rb @@ -0,0 +1,3 @@ +configure do + check_lib "mfoofoo" +end diff --git a/build_tests/configure/check_lib_no_fail.rb b/build_tests/configure/check_lib_no_fail.rb new file mode 100644 index 0000000..30a4c51 --- /dev/null +++ b/build_tests/configure/check_lib_no_fail.rb @@ -0,0 +1,3 @@ +configure do + check_lib "mfoofoo", fail: false +end diff --git a/build_tests/configure/check_lib_success.rb b/build_tests/configure/check_lib_success.rb new file mode 100644 index 0000000..d98af8c --- /dev/null +++ b/build_tests/configure/check_lib_success.rb @@ -0,0 +1,3 @@ +configure do + check_lib "m" +end diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index da8501d..1a13419 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -115,6 +115,11 @@ module Rscons co.check_d_import(*cdi) end end + if cls = @script.check_libs + cls.each do |cl| + co.check_lib(*cl) + end + end if ces = @script.check_executables ces.each do |ce| co.check_executable(*ce) diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 053c117..f6f866d 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -161,6 +161,27 @@ module Rscons common_config_checks(status, options) end + # Check for a library. + def check_lib(lib, options = {}) + $stdout.write("Checking for library '#{lib}'... ") + File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| + fh.puts <<-EOF + int main(int argc, char * argv[]) { + return 0; + } + EOF + end + vars = { + "LD" => "${CC}", + "LIBS" => [lib], + "_SOURCES" => "#{@work_dir}/cfgtest.c", + "_TARGET" => "#{@work_dir}/cfgtest.exe", + } + command = @env.build_command("${LDCMD}", vars) + _, _, status = log_and_test_command(command) + common_config_checks(status, options) + end + # Check for an executable. def check_executable(executable, options = {}) $stdout.write("Checking for executable '#{executable}'... ") diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 6bcef46..cc2c24c 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -60,6 +60,12 @@ module Rscons @script.check_d_imports << args end + # Check for a library. + def check_lib(*args) + @script.check_libs ||= [] + @script.check_libs << args + end + # Check for an executable. def check_executable(*args) @script.check_executables ||= [] @@ -71,31 +77,35 @@ module Rscons # Project name. attr_accessor :project_name - # @return [Array] + # @return [Array] # C compilers to check for. attr_accessor :check_c_compiler - # @return [Array] + # @return [Array] # C++ compilers to check for. attr_accessor :check_cxx_compiler - # @return [Array] + # @return [Array] # D compilers to check for. attr_accessor :check_d_compiler - # @return [Array] + # @return [Array] # C headers to check for. attr_accessor :check_c_headers - # @return [Array] + # @return [Array] # C++ headers to check for. attr_accessor :check_cxx_headers - # @return [Array] + # @return [Array] # D imports to check for. attr_accessor :check_d_imports - # @return [Array] + # @return [Array] + # Libraries to check for. + attr_accessor :check_libs + + # @return [Array] # Executables to check for. attr_accessor :check_executables diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 3032db0..30c5827 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1699,6 +1699,32 @@ EOF end end + context "check_lib" do + it "succeeds when the requested library is found" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_lib_success.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for library 'm'... found/ + end + + it "fails when the requested library is not found" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_lib_failure.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to_not eq 0 + expect(result.stdout).to match /Checking for library 'mfoofoo'... not found/ + end + + it "succeeds when the requested library is not found but :fail is set to false" do + test_dir "configure" + result = run_rscons(rsconsfile: "check_lib_no_fail.rb", op: "configure") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for library 'mfoofoo'... not found/ + end + end + context "check_executable" do it "succeeds when the requested executable is found" do test_dir "configure"