Fix build error with scons-4.4.0 version which is based on python3
[platform/upstream/iotivity.git] / service / resource-container / SConscript
1 #******************************************************************
2 #
3 # Copyright 2015 Samsung Electronics All Rights Reserved.
4 #
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 ##
22 # resource container build script
23 ##
24 import os
25 Import('env')
26 import os.path
27
28 containerJavaSupport = ARGUMENTS.get('containerJavaSupport',0)
29
30 def filtered_glob(env, pattern, omit=[],
31   ondisk=True, source=False, strings=False):
32     return [f for f in env.Glob(pattern) if os.path.basename(f.path) not in omit]
33
34 env.AddMethod(filtered_glob, "FilteredGlob");
35
36 # Add third party libraries
37 lib_env = env.Clone()
38 SConscript('#service/third_party_libs.scons', exports = 'lib_env')
39
40 resource_container_env = lib_env.Clone()
41 target_os = env.get('TARGET_OS')
42 ######################################################################
43 # Build flags
44 ######################################################################
45
46 if int(containerJavaSupport):
47     try:
48         print('Java Home: ', os.environ['JAVA_HOME'])
49         print('Java Lib: ', os.environ['JAVA_LIB'])
50         resource_container_env.Append(CPPDEFINES={'JAVA_SUPPORT':1})
51     except KeyError:
52         print('''
53     *********************************** Error *************************************
54     * Building resource container without Java support. JAVA_HOME or JAVA_LIB are not set properly
55     * Please configure JAVA_HOME to point to your Java 7 JDK and
56     * JAVA_LIB to your folder containing libjvm
57     * Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
58     *          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server
59     *******************************************************************************
60         ''')
61         resource_container_env.Append(CPPDEFINES={'JAVA_SUPPORT':0})
62
63
64 resource_container_env.AppendUnique(
65     CPPPATH = [
66         env.get('SRC_DIR')+'/extlibs',
67         '../resource-encapsulation/include',
68         'include',
69         'bundle-api/include',
70         'src'
71     ])
72
73 if int(containerJavaSupport):
74     try:
75         resource_container_env.AppendUnique(
76         CPPPATH = [
77             os.environ['JAVA_HOME']+'/include',
78             os.environ['JAVA_HOME']+'/include/linux'
79         ])
80     except KeyError:
81         print('')
82
83
84 if target_os not in ['windows']:
85     resource_container_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
86     if target_os != 'android':
87         resource_container_env.AppendUnique(CXXFLAGS = ['-pthread'])
88
89 if target_os not in ['darwin', 'ios', 'windows']:
90     resource_container_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
91
92 if target_os == 'android':
93     resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
94     resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
95
96 try:
97     resource_container_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
98 except KeyError:
99     print('')
100
101 resource_container_env.PrependUnique(LIBS = ['coap'])
102 resource_container_env.AppendUnique(LIBS = ['connectivity_abstraction'])
103 resource_container_env.AppendUnique(LIBS = ['oc_logger'])
104 resource_container_env.AppendUnique(LIBS = ['octbstack'])
105 resource_container_env.AppendUnique(LIBS = ['oc'])
106 resource_container_env.AppendUnique(LIBS = ['rcs_client'])
107 resource_container_env.AppendUnique(LIBS = ['rcs_server'])
108 resource_container_env.AppendUnique(LIBS = ['rcs_common'])
109 resource_container_env.AppendUnique(LIBS = ['dl'])
110 resource_container_env.AppendUnique(LIBS = ['boost_system'])
111 resource_container_env.AppendUnique(LIBS = ['boost_date_time'])
112 resource_container_env.AppendUnique(LIBS = ['boost_thread'])
113
114 if resource_container_env.get('SECURED') == '1':
115         if resource_container_env.get('WITH_TCP') == True:
116                 resource_container_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
117
118 if int(containerJavaSupport):
119     try:
120         print('Java Lib: ', os.environ['JAVA_LIB'])
121         resource_container_env.AppendUnique(LIBS = ['jvm'])
122     except KeyError:
123         print('')
124
125 ######################################################################
126 # Source files and Targets
127 ######################################################################
128 res_container_src = [ Glob('src/*.cpp') ]
129
130 res_container_static = resource_container_env.StaticLibrary('rcs_container', res_container_src)
131 if target_os not in ['ios']:
132     res_container_shared = resource_container_env.SharedLibrary('rcs_container', res_container_src)
133     resource_container_env.InstallTarget([res_container_static,res_container_shared], 'libResContainer')
134     resource_container_env.UserInstallTargetLib([res_container_static,res_container_shared], 'libResContainer')
135 else:
136     resource_container_env.InstallTarget([res_container_static], 'libResContainer')
137     resource_container_env.UserInstallTargetLib([res_container_static], 'libResContainer')
138
139 resource_container_env.UserInstallTargetHeader('include/RCSBundleInfo.h', 'service/resource-container', 'RCSBundleInfo.h')
140 resource_container_env.UserInstallTargetHeader('include/RCSResourceContainer.h', 'service/resource-container', 'RCSResourceContainer.h')
141
142 ######################################################################
143 # build discomfort index sensor sample bundle
144 ######################################################################
145 if target_os in ['linux', 'tizen', 'android']:
146     DI_sensor_bundle_env = resource_container_env.Clone()
147     DI_sensor_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
148
149     DI_SENSOR_BUNDLE_DIR = 'examples/DiscomfortIndexSensorBundle/'
150     DI_sensor_bundle_env.AppendUnique(CPPPATH = [ DI_SENSOR_BUNDLE_DIR + 'include' ])
151
152     DI_sensor_bundle_env.PrependUnique(LIBS = ['rcs_container'])
153
154     DI_sensor_bundle_src = [ Glob(DI_SENSOR_BUNDLE_DIR + 'src/*.cpp')]
155
156     DISensorBundle = DI_sensor_bundle_env.SharedLibrary('DISensorBundle', DI_sensor_bundle_src)
157     DI_sensor_bundle_env.InstallTarget(DISensorBundle, 'libDISensorBundle')
158     DI_sensor_bundle_env.UserInstallTargetLib(DISensorBundle, 'libDISensorBundle')
159
160     if target_os in ['linux']:
161         SConscript(DI_SENSOR_BUNDLE_DIR + 'src/inputSensors/SConscript')
162         Command("THSensorApp", DI_SENSOR_BUNDLE_DIR + "src/inputSensors/THSensorApp/THSensorApp", Copy("$TARGET", "$SOURCE"))
163         Command("THSensorApp1", DI_SENSOR_BUNDLE_DIR + "src/inputSensors/THSensorApp1/THSensorApp1", Copy("$TARGET", "$SOURCE"))
164
165 ######################################################################
166 # build BMI sensor sample bundle
167 ######################################################################
168 if target_os in ['linux', 'tizen', 'android']:
169     BMI_sensor_bundle_env = resource_container_env.Clone()
170     BMI_sensor_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
171
172     BMI_SENSOR_BUNDLE_DIR = 'examples/BMISensorBundle/'
173     BMI_sensor_bundle_env.AppendUnique(CPPPATH = [ BMI_SENSOR_BUNDLE_DIR + 'include' ])
174
175     BMI_sensor_bundle_env.PrependUnique(LIBS = ['rcs_container'])
176
177     BMI_sensor_bundle_src = [ Glob(BMI_SENSOR_BUNDLE_DIR + 'src/*.cpp')]
178
179     BMISensorBundle = BMI_sensor_bundle_env.SharedLibrary('BMISensorBundle', BMI_sensor_bundle_src)
180     BMI_sensor_bundle_env.InstallTarget(BMISensorBundle, 'libBMISensorBundle')
181     BMI_sensor_bundle_env.UserInstallTargetLib(BMISensorBundle, 'libBMISensorBundle')
182
183     if target_os in ['linux']:
184         SConscript(BMI_SENSOR_BUNDLE_DIR + 'src/inputSensors/SConscript')
185         Command("HeightSensorApp", BMI_SENSOR_BUNDLE_DIR + "src/inputSensors/HeightSensorApp/HeightSensorApp", Copy("$TARGET", "$SOURCE"))
186         Command("WeightSensorApp", BMI_SENSOR_BUNDLE_DIR + "src/inputSensors/WeightSensorApp/WeightSensorApp", Copy("$TARGET", "$SOURCE"))
187
188 ######################################################################
189 # build hue sample bundle
190 ######################################################################
191
192 conf2 = Configure(lib_env)
193 if not conf2.CheckLib('curl'):
194     print('''X
195 *********************************** Error *************************************
196 * Cannot build hue sample. Please install libcurl.
197 * Example (Ubuntu):
198 *   sudo apt-get install libcurl4-openssl-dev
199 *   sudo ldconfig
200 * Hint: check with pkg-config --libs libcurl and clear scons cache.
201 * Skipping hue sample build.
202 *******************************************************************************
203     ''')
204 else:
205     hue_resource_bundle_env = resource_container_env.Clone()
206     hue_resource_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
207
208     HUE_RESOURCE_BUNDLE_DIR = 'examples/HueSampleBundle/'
209     hue_resource_bundle_env.AppendUnique(CPPPATH = [
210             HUE_RESOURCE_BUNDLE_DIR + 'include',
211             'include/'
212             ])
213
214     hue_resource_bundle_env.PrependUnique(LIBS = ['curl', 'rcs_container'])
215
216     hue_resource_bundle_src = [ Glob(HUE_RESOURCE_BUNDLE_DIR + 'src/*.cpp')]
217
218     HueBundle = hue_resource_bundle_env.SharedLibrary('HueBundle', hue_resource_bundle_src)
219     hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
220     hue_resource_bundle_env.UserInstallTargetLib(HueBundle, 'libHueBundle')
221 lib_env = conf2.Finish()
222
223 ######################################################################
224 # build resource container unit tests
225 ######################################################################
226 if target_os in ['linux']:
227     SConscript('unittests/SConscript')
228
229 ######################################################################
230 # Build Container Sample
231 ######################################################################
232 if target_os not in ['ios']:
233     containersample_env = resource_container_env.Clone();
234     containersample_env.AppendUnique(LINKFLAGS=["-rdynamic"])
235
236     # Copy test configuration
237     Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
238     Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml")
239
240     containersample_env.AppendUnique(LIBS = ['rcs_container'])
241
242     containersampleapp_src =  ['examples/ContainerSample.cpp']
243     containersampleapp = containersample_env.Program('ContainerSample',containersampleapp_src)
244     Alias("containersample", containersampleapp)
245     env.AppendTarget('containersample')
246
247 ######################################################################
248 # Build Container Sample Client
249 ######################################################################
250     containersampleclient_env = resource_container_env.Clone();
251
252     containersample_env.AppendUnique(LIBS = ['rcs_container'])
253     containersampleclient_src =  ['examples/ContainerSampleClient.cpp']
254     containersampleclientapp = containersample_env.Program('ContainerSampleClient',containersampleclient_src)
255     Alias("containersampleclient", containersampleclientapp)
256     env.AppendTarget('containersampleclient')
257
258 ######################################################################
259 # Build Container Java SDK
260 ######################################################################
261 if target_os == 'android':
262     SConscript('android/SConscript')