]> git.tdb.fi Git - builder.git/blob - source/gnucxxcompiler.cpp
9e206cc6b525edca08587ec43e966eba37afdf76
[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", "g++")
15 {
16         input_suffixes.push_back(".cpp");
17         input_suffixes.push_back(".cc");
18         aux_suffixes.push_back(".hpp");
19
20         if(executable)
21                 query_version();
22 }
23
24 void GnuCxxCompiler::query_version()
25 {
26         ExternalTask::Arguments argv;
27         argv.push_back(executable->get_path().str());
28         argv.push_back("-dumpversion");
29         builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
30         try
31         {
32                 string cxx_ver = strip(ExternalTask::run_and_capture_output(argv));
33                 FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
34                 if(FS::is_dir(cxx_path))
35                 {
36                         builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver));
37                         system_path.push_back(cxx_path);
38                 }
39         }
40         catch(const runtime_error &)
41         { }
42 }
43
44 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
45 {
46         return new CSourceFile(builder, comp, path);
47 }
48
49 Target *GnuCxxCompiler::create_source(const FS::Path &path) const
50 {
51         return new CSourceFile(builder, path);
52 }