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