@@ -106,6 +106,46 @@ class Recipe(with_metaclass(RecipeMeta)):
106
106
107
107
archs = ['armeabi' ] # Not currently implemented properly
108
108
109
+ need_stl_shared = False
110
+ '''Some libraries or python packages may need to be linked with android's
111
+ stl. We can automatically do this for any recipe if we set this property to
112
+ `True`'''
113
+
114
+ stl_lib_name = 'c++_shared'
115
+ '''
116
+ The default STL shared lib to use: `c++_shared`.
117
+
118
+ .. note:: Android NDK version > 17 only supports 'c++_shared', because
119
+ starting from NDK r18 the `gnustl_shared` lib has been deprecated.
120
+ '''
121
+
122
+ stl_lib_source = '{ctx.ndk_dir}/sources/cxx-stl/llvm-libc++'
123
+ '''
124
+ The source directory of the selected stl lib, defined in property
125
+ `stl_lib_name`
126
+ '''
127
+
128
+ @property
129
+ def stl_include_dir (self ):
130
+ return join (self .stl_lib_source .format (ctx = self .ctx ), 'include' )
131
+
132
+ def get_stl_lib_dir (self , arch ):
133
+ return join (
134
+ self .stl_lib_source .format (ctx = self .ctx ), 'libs' , arch .arch
135
+ )
136
+
137
+ def get_stl_library (self , arch ):
138
+ return join (
139
+ self .get_stl_lib_dir (arch ),
140
+ 'lib{name}.so' .format (name = self .stl_lib_name ),
141
+ )
142
+
143
+ def install_stl_lib (self , arch ):
144
+ if not self .ctx .has_lib (
145
+ arch .arch , 'lib{name}.so' .format (name = self .stl_lib_name )
146
+ ):
147
+ self .install_libs (arch , self .get_stl_library (arch ))
148
+
109
149
@property
110
150
def version (self ):
111
151
key = 'VERSION_' + self .name
@@ -435,7 +475,22 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True, clang=False):
435
475
"""
436
476
if arch is None :
437
477
arch = self .filtered_archs [0 ]
438
- return arch .get_env (with_flags_in_cc = with_flags_in_cc , clang = clang )
478
+ env = arch .get_env (with_flags_in_cc = with_flags_in_cc , clang = clang )
479
+
480
+ if self .need_stl_shared :
481
+ env ['CPPFLAGS' ] = env .get ('CPPFLAGS' , '' )
482
+ env ['CPPFLAGS' ] += ' -I{}' .format (self .stl_include_dir )
483
+
484
+ env ['CXXFLAGS' ] = env ['CFLAGS' ] + ' -frtti -fexceptions'
485
+
486
+ if with_flags_in_cc :
487
+ env ['CXX' ] += ' -frtti -fexceptions'
488
+
489
+ env ['LDFLAGS' ] += ' -L{}' .format (self .get_stl_lib_dir (arch ))
490
+ env ['LIBS' ] = env .get ('LIBS' , '' ) + " -l{}" .format (
491
+ self .stl_lib_name
492
+ )
493
+ return env
439
494
440
495
def prebuild_arch (self , arch ):
441
496
'''Run any pre-build tasks for the Recipe. By default, this checks if
@@ -501,6 +556,9 @@ def postbuild_arch(self, arch):
501
556
if hasattr (self , postbuild ):
502
557
getattr (self , postbuild )()
503
558
559
+ if self .need_stl_shared :
560
+ self .install_stl_lib (arch )
561
+
504
562
def prepare_build_dir (self , arch ):
505
563
'''Copies the recipe data into a build dir for the given arch. By
506
564
default, this unpacks a downloaded recipe. You should override
0 commit comments