IOT-1583: Removing /W3 warnings inside resource/csdk/stack/
[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         '#/extlibs/timer/',
60         '#resource/csdk/logger/include',
61         '#resource/csdk/include',
62         'include',
63         'include/internal',
64         '#resource/oc_logger/include',
65         '#resource/csdk/connectivity/common/inc',
66         '#resource/csdk/connectivity/inc',
67         '#resource/csdk/connectivity/inc/pkix',
68         '#resource/csdk/connectivity/api',
69         '#resource/csdk/connectivity/external/inc',
70         '#resource/csdk/security/include',
71         '#resource/csdk/security/include/internal',
72         '#resource/csdk/security/provisioning/include',
73         ])
74
75 if 'SUB' in with_mq:
76     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
77 if 'PUB' in with_mq:
78     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
79 if 'BROKER' in with_mq:
80     liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
81
82 if target_os not in ['arduino', 'windows']:
83     liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX', '_GNU_SOURCE'])
84     liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
85
86 if liboctbstack_env.get('ROUTING') == 'GW':
87     liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
88 elif liboctbstack_env.get('ROUTING') == 'EP':
89     liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
90
91 if target_os not in ['windows']:
92     liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
93
94 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
95
96 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap', 'timer'])
97
98 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
99     liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
100
101 if env.get('SECURED') == '1':
102     liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto', 'tinydtls'])
103
104 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
105     liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
106
107     if with_ra_ibb:
108         liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
109     else :
110         if with_ra:
111             liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
112
113 if target_os not in ['windows', 'msys_nt']:
114     liboctbstack_env.AppendUnique(LIBS = ['m'])
115 else:
116     liboctbstack_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
117     # octbstack.def specifies the list of functions exported by octbstack.dll.
118     liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
119
120     if env.get('SECURED') != '1':
121         liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def')])
122     else:
123         # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
124         liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
125
126         if with_tcp == True:
127             liboctbstack_env.Textfile(target = 'octbstack_temp.def', source = [File('octbstack_product.def'), File('octbstack_product_with_tcp.def')])
128         else:
129             liboctbstack_env.Textfile(target = 'octbstack_temp.def', source = [File('octbstack_product.def')])
130
131         if env.get('MULTIPLE_OWNER') == '1':
132             liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp.def'), File('octbstack_product_secured.def'), File('octbstack_product_secured_mot.def')])
133         else:
134             liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_temp.def'), File('octbstack_product_secured.def')])
135
136 if target_os in ['tizen', 'linux']:
137     liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
138     liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
139
140 if target_os == 'arduino':
141     liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
142 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
143     liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
144 if target_os in ['darwin', 'ios']:
145     env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
146     liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
147     liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
148 if target_os not in ['arduino', 'windows']:
149     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
150 if target_os == 'android':
151     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
152
153 if env.get('LOGGING'):
154     liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
155
156 liboctbstack_env.Append(LIBS = ['c_common'])
157
158 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
159     liboctbstack_env.Prepend(LIBS = ['routingmanager'])
160
161 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
162     liboctbstack_env.PrependUnique(CPPPATH = ['#resource/csdk/resource-directory/include'])
163
164     if target_os in ['windows']:
165         liboctbstack_env.AppendUnique(LIBS = ['sqlite3'])
166
167     if 'CLIENT' in rd_mode:
168         liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
169
170     if 'SERVER' in rd_mode:
171         liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
172         if target_os in ['tizen']:
173             liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
174         else:
175             liboctbstack_env.AppendUnique(CPPPATH = ['#extlibs/sqlite3'])
176
177 ######################################################################
178 # Source files and Targets
179 ######################################################################
180 OCTBSTACK_SRC = 'src/'
181 liboctbstack_src = [
182     OCTBSTACK_SRC + 'ocstack.c',
183     OCTBSTACK_SRC + 'ocpayload.c',
184     OCTBSTACK_SRC + 'ocpayloadparse.c',
185     OCTBSTACK_SRC + 'ocpayloadconvert.c',
186     OCTBSTACK_SRC + 'occlientcb.c',
187     OCTBSTACK_SRC + 'ocresource.c',
188     OCTBSTACK_SRC + 'ocobserve.c',
189     OCTBSTACK_SRC + 'ocserverrequest.c',
190     OCTBSTACK_SRC + 'occollection.c',
191     OCTBSTACK_SRC + 'oicgroup.c',
192     OCTBSTACK_SRC + 'ocendpoint.c'
193     ]
194
195 if with_tcp == True:
196     liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
197     if with_cloud == True:
198         liboctbstack_src.append(OCTBSTACK_SRC + 'occonnectionmanager.c')
199
200 if 'SERVER' in rd_mode:
201     liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
202     if target_os not in ['linux', 'tizen', 'windows']:
203         liboctbstack_src.append('#extlibs/sqlite3/sqlite3.c')
204
205 if target_os in ['linux']:
206     # Linux uses a Shared library because SCons chooses the shared library on Linux
207     # when only 'octbstack' is added to the LIBS.
208     # TODO: Switch Linux to use a Static library for testing like every other OS.
209     test_liboctbstack = liboctbstack_env.SharedLibrary('octbstack_test', liboctbstack_src)
210 else:
211     test_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_test', liboctbstack_src)
212
213 octbstack_libs = Flatten(test_liboctbstack)
214
215 if target_os in ['windows', 'msys_nt']:
216     # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
217     static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
218 else:
219     static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
220
221 octbstack_libs += Flatten(static_liboctbstack)
222
223 if target_os not in ['arduino','darwin','ios'] :
224     shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
225     octbstack_libs += Flatten(shared_liboctbstack)
226     liboctbstack_env.UserInstallTargetHeader('include/ocstack.h', 'resource', 'ocstack.h')
227     liboctbstack_env.UserInstallTargetHeader('include/ocpresence.h', 'resource', 'ocpresence.h')
228
229 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
230 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
231
232 liboctbstack_env.UserInstallTargetHeader('include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
233 liboctbstack_env.UserInstallTargetHeader('include/ocpayload.h', 'resource', 'ocpayload.h')