[IOT-1540] Connection manager logic add.
[platform/upstream/iotivity.git] / resource / csdk / stack / SConscript
1 #******************************************************************
2 #
3 # Copyright 2014 Intel Mobile Communications GmbH 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 # liboctbstack (share library) build script
23 ##
24 Import('env')
25
26 liboctbstack_env = env.Clone()
27
28 # Build C Samples
29 SConscript('samples/SConscript', exports = { 'stacksamples_env' : liboctbstack_env })
30
31 SConscript('#resource/third_party_libs.scons', exports = { 'lib_env' : liboctbstack_env })
32
33 target_os = env.get('TARGET_OS')
34 rd_mode = env.get('RD_MODE')
35 with_ra = env.get('WITH_RA')
36 with_ra_ibb = env.get('WITH_RA_IBB')
37 with_tcp = env.get('WITH_TCP')
38 with_cloud = env.get('WITH_CLOUD')
39 with_mq = env.get('WITH_MQ')
40 # As in the source code, it includes arduino Time library (C++)
41 # It requires compile the .c with g++
42 if target_os == 'arduino':
43     liboctbstack_env.Replace(CC = env.get('CXX'))
44     liboctbstack_env.Replace(CFLAGS = env.get('CXXFLAGS'))
45
46 ######################################################################
47 # Build flags
48 ######################################################################
49 with_upstream_libcoap = liboctbstack_env.get('WITH_UPSTREAM_LIBCOAP')
50 if with_upstream_libcoap == '1':
51     # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
52     liboctbstack_env.PrependUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
53 else:
54     # For bring up purposes only, the forked version will live here.
55     liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/connectivity/lib/libcoap-4.1.1/include'])
56
57 liboctbstack_env.PrependUnique(CPPPATH = [
58         '#/extlibs/timer/',
59         '#resource/csdk/logger/include',
60         '#resource/csdk/include',
61         'include',
62         'include/internal',
63         '#resource/oc_logger/include',
64         '#resource/csdk/connectivity/common/inc',
65         '#resource/csdk/connectivity/inc',
66         '#resource/csdk/connectivity/inc/pkix',
67         '#resource/csdk/connectivity/api',
68         '#resource/csdk/connectivity/external/inc',
69         '#resource/csdk/security/include',
70         '#resource/csdk/security/include/internal',
71         '#resource/csdk/security/provisioning/include',
72         ])
73
74 if 'SUB' in with_mq:
75     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
76 if 'PUB' in with_mq:
77     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
78 if 'BROKER' in with_mq:
79     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
80
81 if target_os not in ['arduino', 'windows']:
82     liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX', '_GNU_SOURCE'])
83     liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
84
85 if liboctbstack_env.get('ROUTING') == 'GW':
86     liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
87 elif liboctbstack_env.get('ROUTING') == 'EP':
88     liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
89
90 if target_os not in ['windows']:
91     liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
92
93 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
94
95 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap', 'timer'])
96
97 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
98     liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
99
100 if env.get('SECURED') == '1':
101     liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto', 'tinydtls'])
102
103 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
104     liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
105
106     if with_ra_ibb:
107         liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
108     else :
109         if with_ra:
110             liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
111
112 if target_os not in ['windows', 'msys_nt']:
113     liboctbstack_env.AppendUnique(LIBS = ['m'])
114 else:
115     # octbstack.def specifies the list of functions exported by octbstack.dll.
116     liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
117
118     if env.get('SECURED') != '1':
119         liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def')])
120     else:
121         # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
122         liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
123
124         if with_tcp == True:
125             liboctbstack_env.Textfile(target = 'octbstack_temp.def', source = [File('octbstack_product.def'), File('octbstack_product_with_tcp.def')])
126         else:
127             liboctbstack_env.Textfile(target = 'octbstack_temp.def', source = [File('octbstack_product.def')])
128
129         if env.get('MULTIPLE_OWNER') == '1':
130             liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp.def'), File('octbstack_product_secured.def'), File('octbstack_product_secured_mot.def')])
131         else:
132             liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp.def'), File('octbstack_product_secured.def')])
133
134 if target_os in ['tizen', 'linux']:
135     liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
136     liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
137
138 if target_os == 'arduino':
139     liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
140 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
141     liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
142 if target_os in ['darwin', 'ios']:
143     env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
144     liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
145     liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
146 if target_os not in ['arduino', 'windows']:
147     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
148 if target_os == 'android':
149     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
150
151 if env.get('LOGGING'):
152     liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
153
154 liboctbstack_env.Append(LIBS = ['c_common'])
155
156 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
157     liboctbstack_env.Prepend(LIBS = ['routingmanager'])
158
159 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
160     liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/resource-directory/include'])
161     if 'CLIENT' in rd_mode:
162         liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
163     if 'SERVER' in rd_mode:
164         liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
165         if target_os in ['tizen']:
166             liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
167         else:
168             liboctbstack_env.AppendUnique(CPPPATH = ['#extlibs/sqlite3'])
169
170 ######################################################################
171 # Source files and Targets
172 ######################################################################
173 OCTBSTACK_SRC = 'src/'
174 liboctbstack_src = [
175     OCTBSTACK_SRC + 'ocstack.c',
176     OCTBSTACK_SRC + 'ocpayload.c',
177     OCTBSTACK_SRC + 'ocpayloadparse.c',
178     OCTBSTACK_SRC + 'ocpayloadconvert.c',
179     OCTBSTACK_SRC + 'occlientcb.c',
180     OCTBSTACK_SRC + 'ocresource.c',
181     OCTBSTACK_SRC + 'ocobserve.c',
182     OCTBSTACK_SRC + 'ocserverrequest.c',
183     OCTBSTACK_SRC + 'occollection.c',
184     OCTBSTACK_SRC + 'oicgroup.c',
185     OCTBSTACK_SRC + 'ocendpoint.c'
186     ]
187
188 if with_tcp == True:
189     liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
190     if with_cloud == True:
191         liboctbstack_src.append(OCTBSTACK_SRC + 'occonnectionmanager.c')
192
193 if 'SERVER' in rd_mode:
194     liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
195     if target_os not in ['linux', 'tizen']:
196         liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c')
197
198 if target_os in ['linux']:
199     # Linux uses a Shared library because SCons chooses the shared library on Linux
200     # when only 'octbstack' is added to the LIBS.
201     # TODO: Switch Linux to use a Static library for testing like every other OS.
202     test_liboctbstack = liboctbstack_env.SharedLibrary('octbstack_test', liboctbstack_src)
203 else:
204     test_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_test', liboctbstack_src)
205
206 octbstack_libs = Flatten(test_liboctbstack)
207
208 if target_os in ['windows', 'msys_nt']:
209     # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
210     static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
211 else:
212     static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
213
214 octbstack_libs += Flatten(static_liboctbstack)
215
216 if target_os not in ['arduino','darwin','ios'] :
217     shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
218     octbstack_libs += Flatten(shared_liboctbstack)
219     liboctbstack_env.UserInstallTargetHeader('include/ocstack.h', 'resource', 'ocstack.h')
220     liboctbstack_env.UserInstallTargetHeader('include/ocpresence.h', 'resource', 'ocpresence.h')
221
222 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
223 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
224
225 liboctbstack_env.UserInstallTargetHeader('include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
226 liboctbstack_env.UserInstallTargetHeader('include/ocpayload.h', 'resource', 'ocpayload.h')