Imported Upstream version 1.1.0
[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 filter(
33       lambda f: os.path.basename(f.path) not in omit,
34       env.Glob(pattern))
35
36 env.AddMethod(filtered_glob, "FilteredGlob");
37
38 # Add third party libraries
39 lib_env = env.Clone()
40 SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
41
42 resource_container_env = lib_env.Clone()
43 target_os = env.get('TARGET_OS')
44 ######################################################################
45 # Build flags
46 ######################################################################
47
48 if int(containerJavaSupport):
49     try:
50         print 'Java Home: ', os.environ['JAVA_HOME']
51         print 'Java Lib: ', os.environ['JAVA_LIB']
52         resource_container_env.Append(CPPDEFINES={'JAVA_SUPPORT':1})
53     except KeyError:
54         print '''
55     *********************************** Error *************************************
56     * Building resource container without Java support. JAVA_HOME or JAVA_LIB are not set properly
57     * Please configure JAVA_HOME to point to your Java 7 JDK and
58     * JAVA_LIB to your folder containing libjvm
59     * Example: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
60     *          export JAVA_LIB=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server
61     *******************************************************************************
62         '''
63         resource_container_env.Append(CPPDEFINES={'JAVA_SUPPORT':0})
64
65
66 resource_container_env.AppendUnique(
67     CPPPATH = [
68         env.get('SRC_DIR')+'/extlibs',
69         '../resource-encapsulation/include',
70         'include',
71         'bundle-api/include',
72         'src'
73     ])
74
75 if int(containerJavaSupport):
76     try:
77         resource_container_env.AppendUnique(
78         CPPPATH = [
79             os.environ['JAVA_HOME']+'/include',
80             os.environ['JAVA_HOME']+'/include/linux'
81         ])
82     except KeyError:
83         print ''
84
85
86 if target_os not in ['windows', 'winrt']:
87     resource_container_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
88     if target_os != 'android':
89         resource_container_env.AppendUnique(CXXFLAGS = ['-pthread'])
90
91 if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
92     resource_container_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
93
94 if target_os == 'android':
95     resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
96     resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
97
98 try:
99     resource_container_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
100 except KeyError:
101     print ''
102
103
104 resource_container_env.PrependUnique(LIBS = ['rcs_client', 'rcs_server', 'rcs_common', 'oc','octbstack', 'oc_logger', 'connectivity_abstraction'])
105 resource_container_env.AppendUnique(LIBS = ['dl', 'boost_system', 'boost_date_time', 'boost_thread'])
106
107 if int(containerJavaSupport):
108     try:
109         print 'Java Lib: ', os.environ['JAVA_LIB']
110         resource_container_env.AppendUnique(LIBS = ['jvm'])
111     except KeyError:
112         print ''
113
114 ######################################################################
115 # Source files and Targets
116 ######################################################################
117 res_container_src = [ Glob('src/*.cpp') ]
118
119 res_container_static = resource_container_env.StaticLibrary('rcs_container', res_container_src)
120 res_container_shared = resource_container_env.SharedLibrary('rcs_container', res_container_src)
121
122 resource_container_env.InstallTarget([res_container_static,res_container_shared], 'libResContainer')
123 resource_container_env.UserInstallTargetLib([res_container_static,res_container_shared], 'libResContainer')
124
125 resource_container_env.UserInstallTargetHeader('include/RCSBundleInfo.h', 'service/resource-container', 'RCSBundleInfo.h')
126 resource_container_env.UserInstallTargetHeader('include/RCSResourceContainer.h', 'service/resource-container', 'RCSResourceContainer.h')
127
128 ######################################################################
129 # build discomfort index sensor sample bundle
130 ######################################################################
131 if target_os in ['linux', 'tizen', 'android']:
132     DI_sensor_bundle_env = resource_container_env.Clone()
133     DI_sensor_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
134
135     DI_SENSOR_BUNDLE_DIR = 'examples/DiscomfortIndexSensorBundle/'
136     DI_sensor_bundle_env.AppendUnique(CPPPATH = [ DI_SENSOR_BUNDLE_DIR + 'include' ])
137
138     DI_sensor_bundle_env.PrependUnique(LIBS = ['rcs_container'])
139
140     DI_sensor_bundle_src = [ Glob(DI_SENSOR_BUNDLE_DIR + 'src/*.cpp')]
141
142     DISensorBundle = DI_sensor_bundle_env.SharedLibrary('DISensorBundle', DI_sensor_bundle_src)
143     DI_sensor_bundle_env.InstallTarget(DISensorBundle, 'libDISensorBundle')
144     DI_sensor_bundle_env.UserInstallTargetLib(DISensorBundle, 'libDISensorBundle')
145
146     if target_os == 'linux' :
147         SConscript(DI_SENSOR_BUNDLE_DIR + 'src/inputSensors/SConscript')
148         Command("THSensorApp", DI_SENSOR_BUNDLE_DIR + "src/inputSensors/THSensorApp/THSensorApp", Copy("$TARGET", "$SOURCE"))
149         Command("THSensorApp1", DI_SENSOR_BUNDLE_DIR + "src/inputSensors/THSensorApp1/THSensorApp1", Copy("$TARGET", "$SOURCE"))
150
151 ######################################################################
152 # build BMI sensor sample bundle
153 ######################################################################
154 if target_os in ['linux', 'tizen', 'android']:
155     BMI_sensor_bundle_env = resource_container_env.Clone()
156     BMI_sensor_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
157
158     BMI_SENSOR_BUNDLE_DIR = 'examples/BMISensorBundle/'
159     BMI_sensor_bundle_env.AppendUnique(CPPPATH = [ BMI_SENSOR_BUNDLE_DIR + 'include' ])
160
161     BMI_sensor_bundle_env.PrependUnique(LIBS = ['rcs_container'])
162
163     BMI_sensor_bundle_src = [ Glob(BMI_SENSOR_BUNDLE_DIR + 'src/*.cpp')]
164
165     BMISensorBundle = BMI_sensor_bundle_env.SharedLibrary('BMISensorBundle', BMI_sensor_bundle_src)
166     BMI_sensor_bundle_env.InstallTarget(BMISensorBundle, 'libBMISensorBundle')
167     BMI_sensor_bundle_env.UserInstallTargetLib(BMISensorBundle, 'libBMISensorBundle')
168
169     if target_os == 'linux' :
170         SConscript(BMI_SENSOR_BUNDLE_DIR + 'src/inputSensors/SConscript')
171         Command("HeightSensorApp", BMI_SENSOR_BUNDLE_DIR + "src/inputSensors/HeightSensorApp/HeightSensorApp", Copy("$TARGET", "$SOURCE"))
172         Command("WeightSensorApp", BMI_SENSOR_BUNDLE_DIR + "src/inputSensors/WeightSensorApp/WeightSensorApp", Copy("$TARGET", "$SOURCE"))
173
174 ######################################################################
175 # build hue sample bundle
176 ######################################################################
177
178 conf2 = Configure(lib_env)
179 if not conf2.CheckLib('curl'):
180     print '''X
181 *********************************** Error *************************************
182 * Cannot build hue sample. Please install libcurl.
183 * Example (Ubuntu):
184 *   sudo apt-get install libcurl4-openssl-dev
185 *   sudo ldconfig
186 * Hint: check with pkg-config --libs libcurl and clear scons cache.
187 * Skipping hue sample build.
188 *******************************************************************************
189     '''
190 else:
191     hue_resource_bundle_env = resource_container_env.Clone()
192     hue_resource_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
193
194     HUE_RESOURCE_BUNDLE_DIR = 'examples/HueSampleBundle/'
195     hue_resource_bundle_env.AppendUnique(CPPPATH = [
196             HUE_RESOURCE_BUNDLE_DIR + 'include',
197             'include/'
198             ])
199
200     hue_resource_bundle_env.PrependUnique(LIBS = ['curl', 'rcs_container'])
201
202     hue_resource_bundle_src = [ Glob(HUE_RESOURCE_BUNDLE_DIR + 'src/*.cpp')]
203
204     HueBundle = hue_resource_bundle_env.SharedLibrary('HueBundle', hue_resource_bundle_src)
205     hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
206     hue_resource_bundle_env.UserInstallTargetLib(HueBundle, 'libHueBundle')
207 lib_env = conf2.Finish()
208
209 ######################################################################
210 # build resource container unit tests
211 ######################################################################
212 if target_os == 'linux':
213     SConscript('unittests/SConscript')
214
215 ######################################################################
216 # Build Container Sample
217 ######################################################################
218 containersample_env = resource_container_env.Clone();
219 containersample_env.AppendUnique(LINKFLAGS=["-rdynamic"])
220
221 # Copy test configuration
222 Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
223 Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml")
224
225 containersample_env.AppendUnique(LIBS = ['rcs_container'])
226
227 containersampleapp_src =  ['examples/ContainerSample.cpp']
228 containersampleapp = containersample_env.Program('ContainerSample',containersampleapp_src)
229 Alias("containersample", containersampleapp)
230 env.AppendTarget('containersample')
231
232 ######################################################################
233 # Build Container Sample Client
234 ######################################################################
235 containersampleclient_env = resource_container_env.Clone();
236
237 containersample_env.AppendUnique(LIBS = ['rcs_container'])
238 containersampleclient_src =  ['examples/ContainerSampleClient.cpp']
239 containersampleclientapp = containersample_env.Program('ContainerSampleClient',containersampleclient_src)
240 Alias("containersampleclient", containersampleclientapp)
241 env.AppendTarget('containersampleclient')
242
243 ######################################################################
244 # Build Container Java SDK
245 ######################################################################
246 if target_os == 'android':
247     SConscript('android/SConscript')