support compiling C++ objects with Object builder
This commit is contained in:
parent
e6a12ac57b
commit
6fa4a8556a
4
build_tests/simple_cc/build.rb
Normal file
4
build_tests/simple_cc/build.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Rscons::Environment.new do |env|
|
||||||
|
# CHANGE FLAGS
|
||||||
|
env.Program('simple', Dir['*.cc'])
|
||||||
|
end
|
8
build_tests/simple_cc/simple.cc
Normal file
8
build_tests/simple_cc/simple.cc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
cout << "This is a simple C++ program" << endl;
|
||||||
|
}
|
@ -12,20 +12,28 @@ module Rscons
|
|||||||
'ASDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
|
'ASDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
|
||||||
'ASCOM' => ['$AS', '-c', '-o', '$TARGET', '$ASDEPGEN', '-I$[ASPPPATH]', '$ASPPFLAGS', '$ASFLAGS', '$SOURCES'],
|
'ASCOM' => ['$AS', '-c', '-o', '$TARGET', '$ASDEPGEN', '-I$[ASPPPATH]', '$ASPPFLAGS', '$ASFLAGS', '$SOURCES'],
|
||||||
|
|
||||||
'CC' => 'gcc',
|
|
||||||
'CFLAGS' => [],
|
|
||||||
'CPPFLAGS' => [],
|
'CPPFLAGS' => [],
|
||||||
'CPPPATH' => [],
|
'CPPPATH' => [],
|
||||||
|
|
||||||
|
'CC' => 'gcc',
|
||||||
|
'CFLAGS' => [],
|
||||||
'CSUFFIX' => '.c',
|
'CSUFFIX' => '.c',
|
||||||
'CCDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
|
'CCDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
|
||||||
'CCCOM' => ['$CC', '-c', '-o', '$TARGET', '$CCDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CFLAGS', '$SOURCES'],
|
'CCCOM' => ['$CC', '-c', '-o', '$TARGET', '$CCDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CFLAGS', '$SOURCES'],
|
||||||
|
|
||||||
|
'CXX' => 'g++',
|
||||||
|
'CXXFLAGS' => [],
|
||||||
|
'CXXSUFFIX' => '.cc',
|
||||||
|
'CXXDEPGEN' => ['-MMD', '-MF', '$DEPFILE'],
|
||||||
|
'CXXCOM' =>['$CXX', '-c', '-o', '$TARGET', '$CXXDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CXXFLAGS', '$SOURCES'],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def produces?(target, source, env)
|
def produces?(target, source, env)
|
||||||
target.has_suffix?(env['OBJSUFFIX']) and (
|
target.has_suffix?(env['OBJSUFFIX']) and (
|
||||||
source.has_suffix?(env['ASSUFFIX']) or
|
source.has_suffix?(env['ASSUFFIX']) or
|
||||||
source.has_suffix?(env['CSUFFIX']))
|
source.has_suffix?(env['CSUFFIX']) or
|
||||||
|
source.has_suffix?(env['CXXSUFFIX']))
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env)
|
def run(target, sources, cache, env)
|
||||||
@ -38,6 +46,8 @@ module Rscons
|
|||||||
'AS'
|
'AS'
|
||||||
elsif sources.first.has_suffix?(env['CSUFFIX'])
|
elsif sources.first.has_suffix?(env['CSUFFIX'])
|
||||||
'CC'
|
'CC'
|
||||||
|
elsif sources.first.has_suffix?(env['CXXSUFFIX'])
|
||||||
|
'CXX'
|
||||||
else
|
else
|
||||||
raise "Error: unknown input file type: #{sources.first.inspect}"
|
raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ module Rscons
|
|||||||
|
|
||||||
def run(target, sources, cache, env)
|
def run(target, sources, cache, env)
|
||||||
# convert sources to object file names
|
# convert sources to object file names
|
||||||
sources = sources.map do |source|
|
objects = sources.map do |source|
|
||||||
if source.has_suffix?([env['OBJSUFFIX'], env['LIBSUFFIX']])
|
if source.has_suffix?([env['OBJSUFFIX'], env['LIBSUFFIX']])
|
||||||
source
|
source
|
||||||
else
|
else
|
||||||
@ -24,16 +24,20 @@ module Rscons
|
|||||||
builder.run(o_file, [source], cache, env) or break
|
builder.run(o_file, [source], cache, env) or break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if sources
|
if objects
|
||||||
|
use_cxx = sources.map do |s|
|
||||||
|
s.has_suffix?(env['CXXSUFFIX'])
|
||||||
|
end.any?
|
||||||
|
ld_alt = use_cxx ? env['CXX'] : env['CC']
|
||||||
vars = {
|
vars = {
|
||||||
'TARGET' => target,
|
'TARGET' => target,
|
||||||
'SOURCES' => sources,
|
'SOURCES' => objects,
|
||||||
'LD' => env['LD'] || env['CC'], # TODO: figure out whether to use CC or CXX
|
'LD' => env['LD'] || ld_alt,
|
||||||
}
|
}
|
||||||
command = env.build_command(env['LDCOM'], vars)
|
command = env.build_command(env['LDCOM'], vars)
|
||||||
unless cache.up_to_date?(target, command, sources)
|
unless cache.up_to_date?(target, command, objects)
|
||||||
return false unless env.execute("LD #{target}", command)
|
return false unless env.execute("LD #{target}", command)
|
||||||
cache.register_build(target, command, sources)
|
cache.register_build(target, command, objects)
|
||||||
end
|
end
|
||||||
target
|
target
|
||||||
end
|
end
|
||||||
|
@ -89,6 +89,14 @@ module Rscons
|
|||||||
@varset.send(:append, *args)
|
@varset.send(:append, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def targets
|
||||||
|
@targets.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def target_sources(target)
|
||||||
|
@targets[target][:source] rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
def process
|
def process
|
||||||
cache = Cache.new
|
cache = Cache.new
|
||||||
targets_processed = Set.new
|
targets_processed = Set.new
|
||||||
|
@ -136,4 +136,11 @@ describe Rscons do
|
|||||||
%q{gcc -o program-release release/program.o},
|
%q{gcc -o program-release release/program.o},
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'builds a C++ program with one source file' do
|
||||||
|
test_dir('simple_cc')
|
||||||
|
File.exists?('simple.o').should be_true
|
||||||
|
`./simple`.should == "This is a simple C++ program\n"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user