]> git.tdb.fi Git - builder.git/blob - source/gnucxxcompiler.cpp
Redesign the way commands are set for tools
[builder.git] / source / gnucxxcompiler.cpp
1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/io/print.h>
4 #include <msp/strings/utils.h>
5 #include "builder.h"
6 #include "csourcefile.h"
7 #include "externaltask.h"
8 #include "gnucxxcompiler.h"
9
10 using namespace std;
11 using namespace Msp;
12
13 GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a):
14         GnuCompiler(b, a, "CXX")
15 {
16         set_command("g++", true);
17         input_suffixes.push_back(".cpp");
18         input_suffixes.push_back(".cc");
19         aux_suffixes.push_back(".hpp");
20 }
21
22 void GnuCxxCompiler::query_version()
23 {
24         ExternalTask::Arguments argv;
25         argv.push_back(executable->get_path().str());
26         argv.push_back("-dumpversion");
27         builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
28         try
29         {
30                 string cxx_ver = strip(ExternalTask::run_and_capture_output(argv));
31                 FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
32                 if(FS::is_dir(cxx_path))
33                 {
34                         builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver));
35                         system_path.push_back(cxx_path);
36                 }
37         }
38         catch(const runtime_error &)
39         { }
40 }
41
42 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
43 {
44         return new CSourceFile(builder, comp, path);
45 }
46
47 Target *GnuCxxCompiler::create_source(const FS::Path &path) const
48 {
49         return new CSourceFile(builder, path);
50 }
51
52 void GnuCxxCompiler::do_prepare()
53 {
54         GnuCompiler::do_prepare();
55         if(executable)
56                 query_version();
57 }