]> git.tdb.fi Git - builder.git/blob - source/gnucxxcompiler.cpp
Some additional log statements
[builder.git] / source / gnucxxcompiler.cpp
1 #include <msp/fs/stat.h>
2 #include <msp/io/print.h>
3 #include <msp/strings/regex.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):
14         GnuCompiler(b, "CXX", "g++")
15 {
16         input_suffixes.push_back(".cpp");
17         input_suffixes.push_back(".cc");
18         aux_suffixes.push_back(".hpp");
19
20         ExternalTask::Arguments argv;
21         argv.push_back(name);
22         argv.push_back("--version");
23         builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
24         ExternalTask task(argv);
25         task.set_stdout(ExternalTask::CAPTURE);
26         task.set_stderr(ExternalTask::IGNORE);
27         task.start();
28         Task::Status status;
29         while((status=task.check())==Task::RUNNING) ;
30         if(status==Task::SUCCESS)
31                 if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(task.get_output()))
32                 {
33                         string cxx_ver = m[0].str;
34                         while(!cxx_ver.empty())
35                         {
36                                 FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
37                                 if(FS::is_dir(cxx_path))
38                                 {
39                                         builder.get_logger().log("tools", format("%s version is %s", name, cxx_ver));
40                                         system_path.push_back(cxx_path);
41                                         break;
42                                 }
43
44                                 string::size_type dot = cxx_ver.rfind('.');
45                                 if(dot==string::npos)
46                                         break;
47                                 cxx_ver.erase(dot);
48                         }
49                 }
50 }
51
52 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
53 {
54         return new CSourceFile(builder, comp, path);
55 }
56
57 Target *GnuCxxCompiler::create_source(const FS::Path &path) const
58 {
59         return new CSourceFile(builder, path);
60 }