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