]> git.tdb.fi Git - builder.git/blob - source/androidcompiler.cpp
Make AndroidCompiler more robust about detecting the cxx-stl location
[builder.git] / source / androidcompiler.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include <msp/strings/format.h>
5 #include <msp/strings/utils.h>
6 #include "androidcompiler.h"
7 #include "androidtools.h"
8 #include "builder.h"
9 #include "externaltask.h"
10 #include "filetarget.h"
11
12 using namespace std;
13 using namespace Msp;
14
15 AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string &t, const AndroidNdk &n):
16         GnuCompiler(b, a, t, n.get_platform_sysroot()),
17         ndk(n)
18 {
19         set_command((ndk.get_bin_dir()/command).str());
20         build_info.incpath.insert(build_info.incpath.end(), system_path.begin(), system_path.end());
21         if(tag=="CXX")
22                 build_info.libs.push_back("gnustl_static");
23 }
24
25 void AndroidCompiler::do_prepare()
26 {
27         GnuCompiler::do_prepare();
28         if(executable && tag=="CXX")
29         {
30                 ExternalTask::Arguments argv;
31                 argv.push_back(executable->get_path().str());
32                 argv.push_back("-dumpversion");
33
34                 builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
35                 string version;
36                 try
37                 {
38                         version = strip(ExternalTask::run_and_capture_output(argv));
39                         builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), version));
40                 }
41                 catch(const runtime_error &)
42                 { }
43
44                 FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
45                 FS::Path libstdcxx_path;
46                 while(1)
47                 {
48                         libstdcxx_path = libstdcxx_dir/version;
49                         if(FS::exists(libstdcxx_path))
50                                 break;
51
52                         string::size_type dot = version.rfind('.');
53                         if(dot==string::npos)
54                         {
55                                 problems.push_back("C++ standard library not found");
56                                 return;
57                         }
58
59                         version = version.substr(0, dot);
60                 }
61
62                 FS::Path public_dir = libstdcxx_path/"include";
63                 system_path.push_back(public_dir);
64                 build_info.incpath.push_back(public_dir);
65
66                 FS::Path arch_path = libstdcxx_path/"libs";
67                 builder.get_logger().log("files", format("Traversing %s", arch_path.str()));
68                 string arch_dir = architecture->best_match(list_files(arch_path));
69                 if(!arch_dir.empty())
70                 {
71                         build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
72                         build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
73                 }
74         }
75 }