1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/io/print.h>
4 #include <msp/strings/regex.h>
5 #include <msp/strings/utils.h>
7 #include "csourcefile.h"
8 #include "externaltask.h"
9 #include "gnucxxcompiler.h"
14 GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a):
15 GnuCompiler(b, a, "CXX", "g++")
17 input_suffixes.push_back(".cpp");
18 input_suffixes.push_back(".cc");
19 aux_suffixes.push_back(".hpp");
21 ExternalTask::Arguments argv;
22 argv.push_back(executable->get_path().str());
23 argv.push_back("--version");
24 builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
25 ExternalTask task(argv);
26 task.set_stdout(ExternalTask::CAPTURE);
27 task.set_stderr(ExternalTask::IGNORE);
30 while((status=task.check())==Task::RUNNING) ;
31 if(status==Task::SUCCESS)
32 if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(task.get_output()))
34 string cxx_ver = m[0].str;
35 while(!cxx_ver.empty())
37 FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
38 if(FS::is_dir(cxx_path))
40 builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver));
41 system_path.push_back(cxx_path);
45 string::size_type dot = cxx_ver.rfind('.');
53 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
55 return new CSourceFile(builder, comp, path);
58 Target *GnuCxxCompiler::create_source(const FS::Path &path) const
60 return new CSourceFile(builder, path);