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