Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceContainer / 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                 '../../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 == 'android':
92     resource_container_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
93     resource_container_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
94         
95 try:
96         resource_container_env.AppendUnique(LIBPATH = [os.environ['JAVA_LIB']])
97 except KeyError:
98         print ''
99         
100
101 resource_container_env.PrependUnique(LIBS = ['rcs_server', 'rcs_common', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction'])
102 resource_container_env.AppendUnique(LIBS = ['dl'])      
103
104 if int(containerJavaSupport):
105         try:    
106                 print 'Java Lib: ', os.environ['JAVA_LIB']
107                 resource_container_env.AppendUnique(LIBS = ['jvm'])             
108         except KeyError:
109                 print ''
110
111 ######################################################################
112 # Source files and Targets
113 ######################################################################
114 res_container_src = ['src/BaseActivator.cpp','src/BundleActivator.cpp','src/RCSBundleInfo.cpp', 
115         'src/BundleInfoInternal.cpp', 'src/BundleResource.cpp', 'src/Configuration.cpp', 'src/JavaBundleResource.cpp', 'src/ProtocolBridgeResource.cpp',
116         'src/ProtocolBridgeConnector.cpp', 'src/RCSResourceContainer.cpp', 'src/ResourceContainerBundleAPI.cpp', 'src/ResourceContainerImpl.cpp', 
117         'src/SoftSensorResource.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
124 ######################################################################
125 # build soft sensor sample bundle
126 ######################################################################
127
128 ss_resource_bundle_env = resource_container_env.Clone()
129 ss_resource_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
130
131 SS_RESOURCE_BUNDLE_DIR = 'examples/SoftSensorSampleBundle/'
132 ss_resource_bundle_env.AppendUnique(CPPPATH = [
133                 SS_RESOURCE_BUNDLE_DIR + 'include',
134                 'include/',
135                 '../../include',
136                 ])              
137                 
138 ss_resource_bundle_env.PrependUnique(LIBS = ['rcs_container'])
139
140 ss_resource_bundle_src = [ Glob(SS_RESOURCE_BUNDLE_DIR + 'src/*.cpp')]
141
142 SoftSensorBundle = ss_resource_bundle_env.SharedLibrary('SoftSensorBundle', ss_resource_bundle_src)
143 ss_resource_bundle_env.InstallTarget(SoftSensorBundle, 'libSoftSensorBundle')
144
145 ######################################################################
146 # build hue sample bundle
147 ######################################################################
148
149 conf2 = Configure(lib_env)
150 if not conf2.CheckLib('curl'):
151         print '''X
152 *********************************** Error *************************************
153 * Cannot build hue sample. Please install libcurl.
154 * Example (Ubuntu): 
155 *       sudo apt-get install libcurl4-openssl-dev
156 *       sudo ldconfig
157 * Hint: check with pkg-config --libs libcurl and clear scons cache.
158 * Skipping hue sample build.
159 ******************************************************************************* 
160         '''
161 else:
162         hue_resource_bundle_env = resource_container_env.Clone()
163         hue_resource_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
164         
165         HUE_RESOURCE_BUNDLE_DIR = 'examples/HueSampleBundle/'
166         hue_resource_bundle_env.AppendUnique(CPPPATH = [
167                         HUE_RESOURCE_BUNDLE_DIR + 'include',
168                         'include/'
169                         ])              
170                 
171         hue_resource_bundle_env.PrependUnique(LIBS = ['curl', 'rcs_container'])
172                 
173         hue_resource_bundle_src = [ Glob(HUE_RESOURCE_BUNDLE_DIR + 'src/*.cpp')]
174         
175         HueBundle = hue_resource_bundle_env.SharedLibrary('HueBundle', hue_resource_bundle_src)
176         hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
177         lib_env = conf2.Finish()
178
179 ######################################################################
180 # build resource container unit tests
181 ######################################################################
182 SConscript('unittests/SConscript')
183
184 ######################################################################
185 # Build Container Sample
186 ######################################################################
187 containersample_env = resource_container_env.Clone();
188 containersample_env.AppendUnique(LINKFLAGS=["-rdynamic"])
189
190 # Copy test configuration
191 Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
192 Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml")
193
194 containersample_env.AppendUnique(LIBS = ['rcs_container'])
195
196 containersampleapp_src =  ['examples/ContainerSample.cpp']
197 containersampleapp = containersample_env.Program('ContainerSample',containersampleapp_src)
198 Alias("containersample", containersampleapp)
199 env.AppendTarget('containersample')
200
201 ######################################################################
202 # Build Container Sample Client
203 ######################################################################
204 containersampleclient_env = resource_container_env.Clone();
205
206 containersample_env.AppendUnique(LIBS = ['rcs_container'])
207 containersampleclient_src =  ['examples/ContainerSampleClient.cpp']
208 containersampleclientapp = containersample_env.Program('ContainerSampleClient',containersampleclient_src)
209 Alias("containersampleclient", containersampleclientapp)
210 env.AppendTarget('containersampleclient')
211
212