@@ -125,6 +125,46 @@ class Recipe(with_metaclass(RecipeMeta)):
125
125
path: `'.', None or ''`
126
126
"""
127
127
128
+ need_stl_shared = False
129
+ '''Some libraries or python packages may need to be linked with android's
130
+ stl. We can automatically do this for any recipe if we set this property to
131
+ `True`'''
132
+
133
+ stl_lib_name = 'c++_shared'
134
+ '''
135
+ The default STL shared lib to use: `c++_shared`.
136
+
137
+ .. note:: Android NDK version > 17 only supports 'c++_shared', because
138
+ starting from NDK r18 the `gnustl_shared` lib has been deprecated.
139
+ '''
140
+
141
+ stl_lib_source = '{ctx.ndk_dir}/sources/cxx-stl/llvm-libc++'
142
+ '''
143
+ The source directory of the selected stl lib, defined in property
144
+ `stl_lib_name`
145
+ '''
146
+
147
+ @property
148
+ def stl_include_dir (self ):
149
+ return join (self .stl_lib_source .format (ctx = self .ctx ), 'include' )
150
+
151
+ def get_stl_lib_dir (self , arch ):
152
+ return join (
153
+ self .stl_lib_source .format (ctx = self .ctx ), 'libs' , arch .arch
154
+ )
155
+
156
+ def get_stl_library (self , arch ):
157
+ return join (
158
+ self .get_stl_lib_dir (arch ),
159
+ 'lib{name}.so' .format (name = self .stl_lib_name ),
160
+ )
161
+
162
+ def install_stl_lib (self , arch ):
163
+ if not self .ctx .has_lib (
164
+ arch .arch , 'lib{name}.so' .format (name = self .stl_lib_name )
165
+ ):
166
+ self .install_libs (arch , self .get_stl_library (arch ))
167
+
128
168
@property
129
169
def version (self ):
130
170
key = 'VERSION_' + self .name
@@ -454,7 +494,22 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
454
494
"""
455
495
if arch is None :
456
496
arch = self .filtered_archs [0 ]
457
- return arch .get_env (with_flags_in_cc = with_flags_in_cc )
497
+ env = arch .get_env (with_flags_in_cc = with_flags_in_cc )
498
+
499
+ if self .need_stl_shared :
500
+ env ['CPPFLAGS' ] = env .get ('CPPFLAGS' , '' )
501
+ env ['CPPFLAGS' ] += ' -I{}' .format (self .stl_include_dir )
502
+
503
+ env ['CXXFLAGS' ] = env ['CFLAGS' ] + ' -frtti -fexceptions'
504
+
505
+ if with_flags_in_cc :
506
+ env ['CXX' ] += ' -frtti -fexceptions'
507
+
508
+ env ['LDFLAGS' ] += ' -L{}' .format (self .get_stl_lib_dir (arch ))
509
+ env ['LIBS' ] = env .get ('LIBS' , '' ) + " -l{}" .format (
510
+ self .stl_lib_name
511
+ )
512
+ return env
458
513
459
514
def prebuild_arch (self , arch ):
460
515
'''Run any pre-build tasks for the Recipe. By default, this checks if
@@ -538,6 +593,9 @@ def postbuild_arch(self, arch):
538
593
if hasattr (self , postbuild ):
539
594
getattr (self , postbuild )()
540
595
596
+ if self .need_stl_shared :
597
+ self .install_stl_lib (arch )
598
+
541
599
def prepare_build_dir (self , arch ):
542
600
'''Copies the recipe data into a build dir for the given arch. By
543
601
default, this unpacks a downloaded recipe. You should override
0 commit comments