Merge branch 'cloud-interface'
[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 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 liboctbstack_env.PrependUnique(CPPPATH = [
46                 '../../extlibs/cjson/',
47                 '../../extlibs/timer/',
48                 'logger/include',
49                 'stack/include',
50                 'stack/include/internal',
51                 '../oc_logger/include',
52                 'connectivity/lib/libcoap-4.1.1',
53                 'connectivity/common/inc',
54                 'connectivity/inc',
55                 'connectivity/api',
56                 'connectivity/external/inc',
57                 'security/include',
58                 'security/include/internal',
59                 'security/provisioning/include',
60                 ])
61
62 if 'SUB' in with_mq:
63         liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
64 if 'PUB' in with_mq:
65         liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
66 if 'BROKER' in with_mq:
67         liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
68
69 if target_os not in ['arduino', 'windows']:
70         liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX'])
71         liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
72
73 if liboctbstack_env.get('ROUTING') == 'GW':
74         liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
75 elif liboctbstack_env.get('ROUTING') == 'EP':
76         liboctbstack_env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
77
78 if target_os not in ['windows']:
79         liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
80
81 liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
82
83 liboctbstack_env.PrependUnique(LIBS = ['ocsrm', 'coap'])
84 if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
85         liboctbstack_env.PrependUnique(LIBS = ['connectivity_abstraction'])
86
87         if with_ra_ibb:
88                 liboctbstack_env.AppendUnique(LIBS = liboctbstack_env['RALIBS'], LIBPATH = liboctbstack_env['RALIBPATH'], RPATH = liboctbstack_env['RARPATH'])
89         else :
90                 if with_ra:
91                         liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
92
93 if target_os in ['windows', 'msys_nt']:
94         liboctbstack_env.AppendUnique(CPPDEFINES  = ['OC_EXPORT_DLL'])
95         liboctbstack_env.AppendUnique(LIBS = ['ws2_32', 'advapi32', 'iphlpapi'])
96 else:
97         liboctbstack_env.AppendUnique(LIBS = ['m'])
98
99 if target_os in ['tizen', 'linux']:
100         liboctbstack_env.ParseConfig("pkg-config --cflags --libs uuid")
101
102 if target_os == 'arduino':
103         liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
104 elif target_os not in ['darwin','ios', 'msys_nt', 'windows']:
105         liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
106 if target_os in ['darwin', 'ios']:
107         env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
108         liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
109         liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
110 if target_os not in ['arduino', 'windows']:
111         liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
112 if target_os == 'android':
113     liboctbstack_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboctbstack.so'])
114
115 if env.get('SECURED') == '1':
116         liboctbstack_env.AppendUnique(LIBS = ['tinydtls'])
117
118 if env.get('LOGGING'):
119         liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
120
121 if env.get('DTLS_WITH_X509') == '1':
122         liboctbstack_env.AppendUnique(CPPDEFINES = ['__WITH_X509__'])
123
124 if env.get('WITH_RD') == '1':
125         liboctbstack_env.PrependUnique(CPPPATH = ['../../service/resource-directory/include'])
126         liboctbstack_env.PrependUnique(LIBPATH = [env.get('BUILD_DIR') + 'service/resource-directory/include'])
127         liboctbstack_env.AppendUnique(CPPDEFINES = ['-DWITH_RD'])
128         liboctbstack_env.AppendUnique(LIBS = ['resource_directory'])
129
130 liboctbstack_env.Append(LIBS = ['c_common'])
131
132 if liboctbstack_env.get('ROUTING') in ['GW', 'EP']:
133         liboctbstack_env.Prepend(LIBS = ['routingmanager'])
134
135 ######################################################################
136 # Source files and Targets
137 ######################################################################
138 OCTBSTACK_SRC = 'stack/src/'
139 liboctbstack_src = [
140         '../../extlibs/cjson/cJSON.c',
141         '../../extlibs/timer/timer.c',
142         OCTBSTACK_SRC + 'ocstack.c',
143         OCTBSTACK_SRC + 'ocpayload.c',
144         OCTBSTACK_SRC + 'ocpayloadparse.c',
145         OCTBSTACK_SRC + 'ocpayloadconvert.c',
146         OCTBSTACK_SRC + 'occlientcb.c',
147         OCTBSTACK_SRC + 'ocresource.c',
148         OCTBSTACK_SRC + 'ocobserve.c',
149         OCTBSTACK_SRC + 'ocserverrequest.c',
150         OCTBSTACK_SRC + 'occollection.c',
151         OCTBSTACK_SRC + 'oicgroup.c',
152         OCTBSTACK_SRC + "rdpayload.c"
153         ]
154
155 if with_tcp == True:
156         liboctbstack_src.append(OCTBSTACK_SRC + 'oickeepalive.c')
157
158 liboctbstack_src.extend(env['cbor_files'])
159
160 if target_os == 'windows':
161         liboctbstack_env.AppendUnique(CPPDEFINES = ['CBOR_API=__declspec(dllexport)',
162                                                     'CBOR_PRIVATE_API=__declspec(dllexport)'
163     ])
164
165 static_liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
166 octbstack_libs = Flatten(static_liboctbstack)
167
168 if target_os not in ['arduino','darwin','ios'] :
169         shared_liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
170         octbstack_libs += Flatten(shared_liboctbstack)
171         liboctbstack_env.UserInstallTargetHeader('stack/include/ocstack.h', 'resource', 'ocstack.h')
172         liboctbstack_env.UserInstallTargetHeader('stack/include/ocpresence.h', 'resource', 'ocpresence.h')
173
174 liboctbstack_env.InstallTarget(octbstack_libs, 'octbstack')
175 liboctbstack_env.UserInstallTargetLib(octbstack_libs, 'octbstack')
176
177 liboctbstack_env.UserInstallTargetHeader('stack/include/ocstackconfig.h', 'resource', 'ocstackconfig.h')
178 liboctbstack_env.UserInstallTargetHeader('stack/include/octypes.h', 'resource', 'octypes.h')