implement ConfigureOp#check_lib

This commit is contained in:
Josh Holtrop 2018-11-14 22:53:00 -05:00
parent 88fd4bd405
commit 3b586cb476
7 changed files with 78 additions and 7 deletions

View File

@ -0,0 +1,3 @@
configure do
check_lib "mfoofoo"
end

View File

@ -0,0 +1,3 @@
configure do
check_lib "mfoofoo", fail: false
end

View File

@ -0,0 +1,3 @@
configure do
check_lib "m"
end

View File

@ -115,6 +115,11 @@ module Rscons
co.check_d_import(*cdi) co.check_d_import(*cdi)
end end
end end
if cls = @script.check_libs
cls.each do |cl|
co.check_lib(*cl)
end
end
if ces = @script.check_executables if ces = @script.check_executables
ces.each do |ce| ces.each do |ce|
co.check_executable(*ce) co.check_executable(*ce)

View File

@ -161,6 +161,27 @@ module Rscons
common_config_checks(status, options) common_config_checks(status, options)
end 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. # Check for an executable.
def check_executable(executable, options = {}) def check_executable(executable, options = {})
$stdout.write("Checking for executable '#{executable}'... ") $stdout.write("Checking for executable '#{executable}'... ")

View File

@ -60,6 +60,12 @@ module Rscons
@script.check_d_imports << args @script.check_d_imports << args
end end
# Check for a library.
def check_lib(*args)
@script.check_libs ||= []
@script.check_libs << args
end
# Check for an executable. # Check for an executable.
def check_executable(*args) def check_executable(*args)
@script.check_executables ||= [] @script.check_executables ||= []
@ -71,31 +77,35 @@ module Rscons
# Project name. # Project name.
attr_accessor :project_name attr_accessor :project_name
# @return [Array<String>] # @return [Array<Array>]
# C compilers to check for. # C compilers to check for.
attr_accessor :check_c_compiler attr_accessor :check_c_compiler
# @return [Array<String>] # @return [Array<Array>]
# C++ compilers to check for. # C++ compilers to check for.
attr_accessor :check_cxx_compiler attr_accessor :check_cxx_compiler
# @return [Array<String>] # @return [Array<Array>]
# D compilers to check for. # D compilers to check for.
attr_accessor :check_d_compiler attr_accessor :check_d_compiler
# @return [Array<String>] # @return [Array<Array>]
# C headers to check for. # C headers to check for.
attr_accessor :check_c_headers attr_accessor :check_c_headers
# @return [Array<String>] # @return [Array<Array>]
# C++ headers to check for. # C++ headers to check for.
attr_accessor :check_cxx_headers attr_accessor :check_cxx_headers
# @return [Array<String>] # @return [Array<Array>]
# D imports to check for. # D imports to check for.
attr_accessor :check_d_imports attr_accessor :check_d_imports
# @return [Array<String>] # @return [Array<Array>]
# Libraries to check for.
attr_accessor :check_libs
# @return [Array<Array>]
# Executables to check for. # Executables to check for.
attr_accessor :check_executables attr_accessor :check_executables

View File

@ -1699,6 +1699,32 @@ EOF
end end
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 context "check_executable" do
it "succeeds when the requested executable is found" do it "succeeds when the requested executable is found" do
test_dir "configure" test_dir "configure"