tizen: Link to systemwide's sqlite
[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 liboctbstack_env.PrependUnique(CPPPATH = [
47                 '../../extlibs/cjson/',
48                 '../../extlibs/timer/',
49                 'logger/include',
50                 'stack/include',
51                 'stack/include/internal',
52                 '../oc_logger/include',
53                 'connectivity/lib/libcoap-4.1.1',
54                 'connectivity/common/inc',
55                 'connectivity/inc',
56                 'connectivity/inc/pkix',
57                 'connectivity/api',
58                 'connectivity/external/inc',
59                 'security/include',
60                 'security/include/internal',
61                 'security/provisioning/include',
62                 ])
63
64 if 'SUB' in with_mq:
65         liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
66 if 'PUB' in with_mq:
67         liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
68 if 'BROKER' in with_mq:
69         liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
70
71 if target_os not in ['arduino', 'windows']:
72         liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX'])
73         liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
74
75 if liboctbstack_env.get('ROUTING') == 'GW':
76         liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
77 elif liboctbstack_env.get('ROUTING') == 'EP':
78         liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
79
80 if target_os not in ['windows']:
81         liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
82
83 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
84
85 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
86
87 if target_os in ['linux'] and liboctbstack_env.get('SIMULATOR', False):
88     liboctbstack_env.Append( RPATH = liboctbstack_env.Literal('\\$$ORIGIN'))
89
90 if env.get('SECURED') == '1':
91         liboctbstack_env.AppendUnique(LIBS = ['tinydtls'])
92         if env.get('WITH_TCP') == True:
93                 liboctbstack_env.AppendUnique(LIBS = ['mbedtls','mbedx509','mbedcrypto'])
94
95 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
96         liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
97
98         if with_ra_ibb:
99                 liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
100         else :
101                 if with_ra:
102                         liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
103
104 if target_os in ['windows', 'msys_nt']:
105         # octbstack.dll is exporting ocpmapi APIs on Windows - there is no ocpmapi.dll.
106         liboctbstack_env.PrependUnique(LIBS = ['ocpmapi'])
107
108         # octbstack.def specifies the list of functions exported by octbstack.dll.
109         liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
110         if env.get('TEST') == '1':
111                 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def'), File('octbstack_test.def')])
112         else:
113                 liboctbstack_env.Textfile(target = 'octbstack.def', source = [File('octbstack_product.def')])
114
115         liboctbstack_env.AppendUnique(LIBS = ['ws2_32', 'advapi32', 'iphlpapi'])
116 else:
117         liboctbstack_env.AppendUnique(LIBS = ['m'])
118
119 if target_os in ['tizen', 'linux']:
120         liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
121 if target_os in ['tizen']:
122         liboctbstack_env.ParseConfig('pkg-config --cflags --libs sqlite3')
123
124 if target_os == 'arduino':
125         liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
126 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
127         liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
128 if target_os in ['darwin', 'ios']:
129         env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
130         liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
131         liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
132 if target_os not in ['arduino', 'windows']:
133         liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
134 if target_os == 'android':
135     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
136
137 if env.get('LOGGING'):
138         liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
139
140 if env.get('DTLS_WITH_X509') == '1':
141         liboctbstack_env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
142
143 liboctbstack_env.Append(LIBS = ['c_common'])
144
145 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
146         liboctbstack_env.Prepend(LIBS = ['routingmanager'])
147
148 ######################################################################
149 # Source files and Targets
150 ######################################################################
151 OCTBSTACK_SRC = 'stack/src/'
152 liboctbstack_src = [
153         '../../extlibs/cjson/cJSON.c',
154         '../../extlibs/timer/timer.c',
155         OCTBSTACK_SRC + 'ocstack.c',
156         OCTBSTACK_SRC + 'ocpayload.c',
157         OCTBSTACK_SRC + 'ocpayloadparse.c',
158         OCTBSTACK_SRC + 'ocpayloadconvert.c',
159         OCTBSTACK_SRC + 'occlientcb.c',
160         OCTBSTACK_SRC + 'ocresource.c',
161         OCTBSTACK_SRC + 'ocobserve.c',
162         OCTBSTACK_SRC + 'ocserverrequest.c',
163         OCTBSTACK_SRC + 'occollection.c',
164         OCTBSTACK_SRC + 'oicgroup.c'
165         ]
166
167 if 'CLIENT' in rd_mode or 'SERVER' in rd_mode:
168         liboctbstack_src.append(OCTBSTACK_SRC + 'rdpayload.c')
169         liboctbstack_src.append(OCTBSTACK_SRC + 'oicresourcedirectory.c')
170         if 'CLIENT' in rd_mode:
171                 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
172         if 'SERVER' in rd_mode:
173                 liboctbstack_env.AppendUnique(CPPDEFINES = ['RD_SERVER'])
174
175 if with_tcp == True:
176         liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
177
178 liboctbstack_src.extend(env['cbor_files'])
179
180 # Insert a hack for Arduino, whose compiler may not support all defines expected
181 # by tinycbor
182 if target_os in ['arduino']:
183         liboctbstack_env.AppendUnique(CPPDEFINES = ['INT64_MAX=0x7FFFFFFFFFFFFFFF'])
184
185 if target_os in ['windows', 'msys_nt']:
186         # Avoid a name conflict with the octbstack.lib target of the SharedLibrary.
187         static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack_static', liboctbstack_src)
188 else:
189         static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
190
191 octbstack_libs = Flatten(static_liboctbstack)
192
193 if target_os not in ['arduino','darwin','ios'] :
194         shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
195         octbstack_libs += Flatten(shared_liboctbstack)
196         liboctbstack_env.UserInstallTargetHeader('stack/include/ocstack.h', 'resource', 'ocstack.h')
197         liboctbstack_env.UserInstallTargetHeader('stack/include/ocpresence.h', 'resource', 'ocpresence.h')
198
199 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
200 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
201
202 liboctbstack_env.UserInstallTargetHeader('stack/include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
203 liboctbstack_env.UserInstallTargetHeader('stack/include/octypes.h', 'resource', 'octypes.h')
204 liboctbstack_env.UserInstallTargetHeader('stack/include/ocpayload.h', 'resource', 'ocpayload.h')