[IOT-2012] Windows: rename ocpmapi.lib
[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 import os
26
27 liboctbstack_env = env.Clone()
28
29 # Build C Samples
30 SConscript('samples/SConscript', exports = { 'stacksamples_env' : liboctbstack_env })
31
32 SConscript('#resource/third_party_libs.scons', exports = { 'lib_env' : liboctbstack_env })
33
34 target_os = env.get('TARGET_OS')
35 rd_mode = env.get('RD_MODE')
36 with_ra = env.get('WITH_RA')
37 with_ra_ibb = env.get('WITH_RA_IBB')
38 with_tcp = env.get('WITH_TCP')
39 with_cloud = env.get('WITH_CLOUD')
40 with_mq = env.get('WITH_MQ')
41 # As in the source code, it includes arduino Time library (C++)
42 # It requires compile the .c with g++
43 if target_os == 'arduino':
44     liboctbstack_env.Replace(CC = env.get('CXX'))
45     liboctbstack_env.Replace(CFLAGS = env.get('CXXFLAGS'))
46
47 ######################################################################
48 # Build flags
49 ######################################################################
50 with_upstream_libcoap = liboctbstack_env.get('WITH_UPSTREAM_LIBCOAP')
51 if with_upstream_libcoap == '1':
52     # For bring up purposes only, we manually copy the forked version to where the unforked version is downloaded.
53     liboctbstack_env.PrependUnique(CPPPATH = ['#extlibs/libcoap/libcoap/include'])
54 else:
55     # For bring up purposes only, the forked version will live here.
56     liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/connectivity/lib/libcoap-4.1.1/include'])
57
58 liboctbstack_env.PrependUnique(CPPPATH = [
59         '#resource/c_common/octimer/include',
60         '#resource/c_common/ocatomic/include',
61         '#resource/csdk/logger/include',
62         '#resource/csdk/include',
63         'include',
64         'include/internal',
65         '#resource/oc_logger/include',
66         '#resource/csdk/connectivity/common/inc',
67         '#resource/csdk/connectivity/inc',
68         '#resource/csdk/connectivity/inc/pkix',
69         '#resource/csdk/connectivity/api',
70         '#resource/csdk/connectivity/external/inc',
71         '#resource/csdk/security/include',
72         '#resource/csdk/security/include/internal',
73         '#resource/csdk/security/provisioning/include',
74         ])
75
76 if 'SUB' in with_mq:
77     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
78 if 'PUB' in with_mq:
79     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
80 if 'BROKER' in with_mq:
81     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
82
83 if target_os not in ['arduino', 'windows']:
84     liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX', '_GNU_SOURCE'])
85     liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
86
87 if liboctbstack_env.get('ROUTING') == 'GW':
88     liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
89 elif liboctbstack_env.get('ROUTING') == 'EP':
90     liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
91
92 if target_os not in ['windows']:
93     liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
94
95 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
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'])
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     liboctbstack_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
116
117     # octbstack.def specifies the list of functions exported by octbstack.dll.
118     liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
119
120     # On Windows, apps don't link directly with oc_logger. oc_logger is linked inside
121     # octbstack.dll and apps import its APIs by linking with octbstack.lib.
122     liboctbstack_env.PrependUnique(LIBS = ['oc_logger_internal'])
123
124     if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
125         # On Windows:
126         # - octbstack.dll is exporting resource_directory C APIs
127         # - resource_directory.lib contains just the implementation of the C++ RD APIs
128         liboctbstack_env.PrependUnique(LIBS = ['resource_directory_internal'])
129
130     if 'CLIENT' in rd_mode:
131         liboctbstack_env.Textfile(target = 'octbstack_temp1.def', source = [File('octbstack_product.def'), File('octbstack_rd_client.def')])
132     else:
133         liboctbstack_env.Textfile(target = 'octbstack_temp1.def', source = [File('octbstack_product.def')])
134
135     if 'SERVER' in rd_mode:
136         liboctbstack_env.Textfile(target = 'octbstack_temp2.def', source = [File('octbstack_temp1.def'), File('octbstack_rd_server.def')])
137     else:
138         liboctbstack_env.Textfile(target = 'octbstack_temp2.def', source = [File('octbstack_temp1.def')])
139
140     if env.get('SECURED') != '1':
141         liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp2.def')])
142     else:
143         # On Windows, apps don't link directly with ocpmapi.lib. ocpmapi is linked
144         # inside octbstack.dll and apps import its APIs by linking with octbstack.lib.
145         liboctbstack_env.PrependUnique(LIBS = ['ocpmapi_internal'])
146
147         liboctbstack_env.Textfile(target = 'octbstack_temp3.def', source = [File('octbstack_temp2.def'), File('octbstack_product_secured.def')])
148
149         if with_tcp == True:
150             liboctbstack_env.Textfile(target = 'octbstack_temp4.def', source = [File('octbstack_temp3.def'), File('octbstack_product_with_tcp.def')])
151         else:
152             liboctbstack_env.Textfile(target = 'octbstack_temp4.def', source = [File('octbstack_temp3.def')])
153
154         if env.get('MULTIPLE_OWNER') == '1':
155             liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp4.def'), File('octbstack_product_secured_mot.def')])
156         else:
157             liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp4.def')])
158
159 if target_os in ['tizen', 'linux']:
160     liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
161     liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
162
163 if target_os == 'arduino':
164     liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
165 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
166     liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
167 if target_os in ['darwin', 'ios']:
168     env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
169     liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
170 if target_os not in ['arduino', 'windows']:
171     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
172 if target_os == 'android':
173     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
174
175 if env.get('LOGGING'):
176     liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
177
178 liboctbstack_env.Append(LIBS = ['c_common', 'mbedcrypto'])
179
180 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
181     liboctbstack_env.Prepend(LIBS = ['routingmanager'])
182
183 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
184     liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/resource-directory/include'])
185
186     if target_os in ['windows']:
187         liboctbstack_env.AppendUnique(LIBS = ['sqlite3'])
188
189     if 'CLIENT' in rd_mode:
190         liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
191
192     if 'SERVER' in rd_mode:
193         liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
194         if target_os in ['tizen']:
195             liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
196         else:
197             liboctbstack_env.AppendUnique(CPPPATH = ['#extlibs/sqlite3'])
198
199 ######################################################################
200 # Source files and Targets
201 ######################################################################
202 OCTBSTACK_SRC = 'src/'
203 liboctbstack_src = [
204     OCTBSTACK_SRC + 'ocstack.c',
205     OCTBSTACK_SRC + 'ocpayload.c',
206     OCTBSTACK_SRC + 'ocpayloadparse.c',
207     OCTBSTACK_SRC + 'ocpayloadconvert.c',
208     OCTBSTACK_SRC + 'occlientcb.c',
209     OCTBSTACK_SRC + 'ocresource.c',
210     OCTBSTACK_SRC + 'ocobserve.c',
211     OCTBSTACK_SRC + 'ocserverrequest.c',
212     OCTBSTACK_SRC + 'occollection.c',
213     OCTBSTACK_SRC + 'oicgroup.c',
214     OCTBSTACK_SRC + 'ocendpoint.c'
215     ]
216
217 if with_tcp == True:
218     liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
219     if with_cloud == True:
220         liboctbstack_src.append(OCTBSTACK_SRC + 'occonnectionmanager.c')
221
222 if 'SERVER' in rd_mode:
223     liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
224     if target_os not in ['linux', 'tizen', 'windows']:
225         liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c')
226
227 if target_os in ['linux']:
228     # Linux uses a Shared library because SCons chooses the shared library on Linux
229     # when only 'octbstack' is added to the LIBS.
230     # TODO: Switch Linux to use a Static library for testing like every other OS.
231     test_liboctbstack = liboctbstack_env.SharedLibrary('octbstack_test', liboctbstack_src)
232 else:
233     test_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_test', liboctbstack_src)
234
235 octbstack_libs = Flatten(test_liboctbstack)
236
237 if target_os in ['windows', 'msys_nt']:
238     # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
239     static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
240 else:
241     static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
242
243 octbstack_libs += Flatten(static_liboctbstack)
244
245 if target_os not in ['arduino','darwin','ios'] :
246     shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
247     octbstack_libs += Flatten(shared_liboctbstack)
248     liboctbstack_env.UserInstallTargetHeader('include/ocstack.h', 'resource', 'ocstack.h')
249     liboctbstack_env.UserInstallTargetHeader('include/ocpresence.h', 'resource', 'ocpresence.h')
250
251 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
252 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
253
254 liboctbstack_env.UserInstallTargetHeader('include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
255 liboctbstack_env.UserInstallTargetHeader('include/ocpayload.h', 'resource', 'ocpayload.h')