]> git.tdb.fi Git - builder.git/blob - source/gnucxxcompiler.cpp
Make tools capable of reporting a system-wide path used to locate input files
[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 "builder.h"
5 #include "csourcefile.h"
6 #include "externaltask.h"
7 #include "gnucxxcompiler.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 GnuCxxCompiler::GnuCxxCompiler(Builder &b):
13         GnuCompiler(b, "CXX", "g++")
14 {
15         input_suffixes.push_back(".cpp");
16         input_suffixes.push_back(".cc");
17         aux_suffixes.push_back(".hpp");
18
19         ExternalTask::Arguments argv;
20         argv.push_back(name);
21         argv.push_back("--version");
22         ExternalTask task(argv);
23         task.set_stdout(ExternalTask::CAPTURE);
24         task.set_stderr(ExternalTask::IGNORE);
25         task.start();
26         Task::Status status;
27         while((status=task.check())==Task::RUNNING) ;
28         if(status==Task::SUCCESS)
29                 if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(task.get_output()))
30                 {
31                         string cxx_ver = m[0].str;
32                         while(!cxx_ver.empty())
33                         {
34                                 FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
35                                 if(FS::is_dir(cxx_path))
36                                 {
37                                         if(builder.get_verbose()>=5)
38                                                 IO::print("%s version is %s\n", name, cxx_ver);
39                                         system_path.push_back(cxx_path);
40                                         break;
41                                 }
42
43                                 string::size_type dot = cxx_ver.rfind('.');
44                                 if(dot==string::npos)
45                                         break;
46                                 cxx_ver.erase(dot);
47                         }
48                 }
49 }
50
51 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
52 {
53         return new CSourceFile(builder, comp, path);
54 }