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