Merge test folder of test branch
[iotivity.git] / test / build / linux / SConscriptCS
1 '''
2 /******************************************************************
3 *
4 * Copyright 2018 Samsung Electronics All Rights Reserved.
5 *
6 *
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 ******************************************************************/
21 '''
22 print '\n---------------Started Building CS Module for Linux---------------\n'
23
24 Import('env_linux')
25 import os
26
27 env_linux['CC'] = 'g++'
28
29 iotivity_root = env_linux.get('IOTIVITY_ROOT')
30 iotivity_lib_path = env_linux.get('IOTIVITY_LIB_PATH')
31 iotivity_test_root = env_linux.get('IOTIVITY_TEST_ROOT')
32 variant_dir = env_linux.get('VARIANT_DIR')
33 install_dir = env_linux.get('INSTALL_DIR')
34 test_src_root = iotivity_test_root + '/' + variant_dir
35 test = env_linux.get('TEST')
36 sdk = env_linux.get('SDK')
37 tls_mode = env_linux.get('TLS_MODE')
38 cloud_service_build = env_linux.get('CLOUD_SERVICE')
39 kafka_root = env_linux.get('KAFKA_ROOT')
40 common_linux_cppflags = env_linux.get('COMMON_LINUX_CPPFLAGS')
41 common_rpath = [iotivity_lib_path, '.', '/usr/local/lib']
42
43 install_targets = []
44 default_targets = []
45
46 # Features Configuration
47 CERT_ENABLED = 1
48 CLOUD_ENABLED = 1
49
50 iotivity_include_paths = [
51     iotivity_root + '/resource/csdk',
52     iotivity_root + '/resource/csdk/include',
53     iotivity_root + '/resource/csdk/security/include',
54     iotivity_root + '/resource/csdk/security/include/internal',
55     iotivity_root + '/resource/csdk/security/provisioning/include',
56     iotivity_root + '/resource/csdk/security/provisioning/include/internal',
57     iotivity_root + '/resource/csdk/security/provisioning/include/oxm',
58     iotivity_root + '/resource/csdk/security/provisioning/include/cloud',
59     iotivity_root + '/resource/include',
60     iotivity_root + '/resource/csdk/stack/include',
61     iotivity_root + '/resource/csdk/ocrandom/include',
62     iotivity_root + '/resource/csdk/logger/include',
63     iotivity_root + '/resource/csdk/logger/include/experimental',
64     iotivity_root + '/resource/csdk/connectivity/inc',
65     iotivity_root + '/resource/csdk/connectivity/inc/pkix',
66     iotivity_root + '/resource/csdk/connectivity/common/inc',
67     iotivity_root + '/resource/csdk/connectivity/lib/libcoap-4.1.1',
68     iotivity_root + '/resource/csdk/connectivity/api',
69     iotivity_root + '/resource/c_common/oic_malloc/include',
70     iotivity_root + '/resource/c_common',
71     iotivity_root + '/resource/c_common/octhread/include',
72     iotivity_root + '/resource/c_common/oic_string/include',
73     iotivity_root + '/resource/c_common/oic_string/include',
74     iotivity_root + '/resource/c_common/ocrandom/include',
75     iotivity_root + '/resource/csdk/stack/include/experimental',
76     iotivity_root + '/resource/csdk/logger/include/experimental',
77     iotivity_root + '/resource/oc_logger/include',
78     iotivity_root + '/resource/csdk/connectivity/lib/libcoap-4.1.1/include/',
79     iotivity_root + '/resource/csdk/resource-directory/include',
80     iotivity_root + '/extlibs/cjson',
81     iotivity_root + '/extlibs/base64',
82     iotivity_root + '/extlibs/tinycbor/tinycbor/src',
83     iotivity_root + '/extlibs/mbedtls/mbedtls/include',
84     iotivity_root + '/extlibs/mbedtls/mbedtls/include/mbedtls',
85     iotivity_root + '/extlibs/tinydtls',
86     iotivity_lib_path + '/resource/c_common'
87 ]
88
89 csdk_tc_include_paths = [
90     iotivity_test_root + '/include',
91     test_src_root + '/tc/cs/gtest/csdk/include',
92     iotivity_test_root + '/extlibs/gtest-1.7.0/include',
93 ]
94
95 cpp_tc_include_paths = [
96     iotivity_test_root + '/include',
97     test_src_root + '/tc/cs/gtest/cpp/include',
98     iotivity_test_root + '/extlibs/gtest-1.7.0/include',
99 ]
100
101 csdk_tc_src = [
102     Glob(test_src_root + '/tc/cs/gtest/csdk/src/helper/*.cpp'),
103     Glob(test_src_root + '/tc/cs/gtest/csdk/src/btc/*.cpp'),
104     Glob(test_src_root + '/tc/cs/gtest/csdk/src/stc/*.cpp'),
105     Glob(test_src_root + '/common/commonutil/c_cpp/ResourceServer.cpp'),
106     Glob(test_src_root + '/common/commonutil/c_cpp/SampleResource.cpp'),
107     Glob(test_src_root + '/common/commonutil/c_cpp/ResourceHelper.cpp')
108 ]
109
110 csdk_app_include_paths = [
111     iotivity_test_root + '/include',
112     test_src_root + '/tc/cs/gtest/csdk/include',
113     iotivity_test_root + '/extlibs/gtest-1.7.0/include',
114 ]
115
116 csdk_app_src = [
117     Glob(test_src_root + '/iBtestapp/modules/cs/c_cpp/csdk/*.cpp'),
118     Glob(test_src_root + '/tc/cs/gtest/csdk/src/helper/*.cpp'),
119     Glob(test_src_root + '/common/commonutil/c_cpp/ResourceServer.cpp'),
120     Glob(test_src_root + '/common/commonutil/c_cpp/SampleResource.cpp'),
121     Glob(test_src_root + '/common/commonutil/c_cpp/ResourceHelper.cpp')
122 ]
123
124 cpp_tc_src = [
125     Glob(test_src_root + '/tc/cs/gtest/cpp/src/helper/*.cpp'),
126     Glob(test_src_root + '/tc/cs/gtest/cpp/src/btc/*.cpp'),
127     Glob(test_src_root + '/tc/cs/gtest/cpp/src/stc/*.cpp')
128 ]
129
130 lib_paths = [
131     '.',
132     iotivity_lib_path,
133     iotivity_lib_path + '/resource/csdk/logger',
134     iotivity_lib_path + '/resource/csdk/security/provisioning/ck_manager',
135     iotivity_lib_path + '/resource/csdk/security',
136     iotivity_lib_path + '/resource/c_common/',
137     iotivity_lib_path + '/resource/csdk/routing/',
138     iotivity_test_root + '/extlibs/gtest-1.7.0/bin/linux/',
139     iotivity_root + '/extlibs/mbedtls/'
140 ]
141
142 simulator_src = [
143     test_src_root + '/testapp/cs/iotivity_cs_server.cpp'
144 ]
145
146 cppflags = Split('-s -pthread -march=native -std=gnu++0x -pthread -D__SECURED__ -D__CLOUD__ -DCA_DBUS_GATT_SERVICE_NAME -DROUTING_EP -DGLIB_VERSION_MIN_REQUIRED -DGLIB_VERSION_2_32 -DWITH_BWT -DTB_LOG -DIP_ADAPTER -DLE_ADAPTER -DNO_EDR_ADAPTER -DHAVE_SYS_TIME_H -DDTLSV12 -DRD_CLIENT -DWITH_CLOUD -D_ENABLE_MULTIPLE_OWNER_ -DWITH_POSIX -DNDEBUG -DTCP_ADAPTER -fpermissive -D__WITH_DTLS__ -D__WITH_TLS__ -DWITH_TCP')
147 cxxflags = ['-c', '-Os', '-Wall', '-Wextra', '-fPIC', '-pthread',
148                '-DWITH_SHA256', '-DDTLS_CHECK_CONTENTTYPE', '-DSHA2_USE_INTTYPES_H', '-DROUTING_EP', '-DWITH_BWT',
149                '-D__WITH_DTLS__', '-DTB_LOG', '-ftest-coverage', '-fprofile-arcs' , '-D__SECURED__']
150 lib_list = Split('boost_system boost_filesystem boost_thread c_common coap connectivity_abstraction dl expat gcov gio-2.0 gobject-2.0 glib-2.0 m oc cloud oc_logger logger octbstack ocpmapi ocprovision ocsrm octbstack rt uuid  mbedtls mbedcrypto mbedx509 resource_directory cloud_util common_util dl curl boost_system boost_filesystem boost_thread pthread')
151
152 if 'tc' in test:
153
154     csdk_target_binary = 'iotivity_cs_csdk_tlsoff_test'
155     cpp_target_binary = 'iotivity_cs_cpp_tlsoff_test'
156     if tls_mode:
157         cppflags.append(['-D__TLS_ON__'])
158         csdk_target_binary = 'iotivity_cs_csdk_tlson_test'
159         cpp_target_binary = 'iotivity_cs_cpp_tlson_test'
160
161     if 'csdk' in sdk:
162         csdk_tc = env_linux.Program(source = csdk_tc_src,
163                                  target = csdk_target_binary,
164                                  CPPPATH = iotivity_include_paths + csdk_tc_include_paths,
165                                  LIBS = lib_list + ['gtest', 'tc_util', 'dl'],
166                                  LIBPATH = lib_paths + ['.', '/usr/local/lib'],
167                                  RPATH = common_rpath,
168                                  CPPFLAGS = cppflags + common_linux_cppflags,
169                                  CXXFLAGS = cxxflags)
170         install_targets += csdk_tc
171
172     if 'cpp' in sdk:
173         cpp_tc = env_linux.Program(source = cpp_tc_src,
174                             target = cpp_target_binary,
175                             CPPPATH = iotivity_include_paths + cpp_tc_include_paths,
176                             LIBS=lib_list + ['gtest', 'tc_util', 'dl'],
177                             LIBPATH = lib_paths + ['.', '/usr/local/lib'],
178                             RPATH = common_rpath,
179                             CPPFLAGS = cppflags + common_linux_cppflags,
180                             CXXFLAGS = cxxflags)
181         install_targets += cpp_tc
182
183 if 'app' in test:
184     csdk_target_binary = 'iotivity_cs_csdk_tlsoff_app'
185     cpp_target_binary = 'iotivity_cs_cpp_tlsoff_app'
186     if tls_mode:
187         cppflags.append(['-D__TLS_ON__'])
188         csdk_target_binary = 'iotivity_cs_csdk_tlson_app'
189         cpp_target_binary = 'iotivity_cs_cpp_tlson_app'
190
191     if 'csdk' in sdk:
192         csdk_tc = env_linux.Program(source = csdk_app_src,
193                                  target = csdk_target_binary,
194                                  CPPPATH = iotivity_include_paths + csdk_app_include_paths,
195                                  LIBS = lib_list,
196                                  LIBPATH = lib_paths + ['.', '/usr/local/lib'],
197                                  RPATH = common_rpath,
198                                  CPPFLAGS = cppflags + common_linux_cppflags,
199                                  CXXFLAGS = cxxflags)
200         install_targets += csdk_tc
201
202 if 'tc' in test or 'simulator' in test:
203     csc_simulator = env_linux.Program(source = simulator_src,
204                                       target = 'iotivity_cs_server',
205                                       CPPPATH = iotivity_include_paths + csdk_tc_include_paths,
206                                       LIBS = lib_list,
207                                       LIBPATH = lib_paths + ['.', '/usr/local/lib'],
208                                       RPATH = common_rpath,
209                                       CPPFLAGS = cppflags + common_linux_cppflags,
210                                       CXXFLAGS = cxxflags)
211     install_targets += csc_simulator
212
213 if 'tc' in test or 'app' in test:
214     cs_resource_path = iotivity_test_root + '/res/cloud_resource'
215     cs_resource_list = Glob(cs_resource_path + '/*.*')
216     common_resource_list = Glob(iotivity_test_root + '/res/common/*.*')
217     cs_dat_file = iotivity_root + '/resource/provisioning/examples/cloud.dat'
218     cs_crt_file = iotivity_root + '/resource/provisioning/examples/rootca.crt'
219
220 install_bin = env_linux.Install(iotivity_test_root + '/' + install_dir, install_targets)
221 install_res = env_linux.Install(iotivity_test_root + '/' + install_dir, cs_dat_file)
222 install_res += env_linux.Install(iotivity_test_root + '/bin', cs_dat_file)
223 install_res += env_linux.Install(iotivity_test_root + '/' + install_dir + '/rootca.crt', cs_crt_file)
224 install_res += env_linux.Install(iotivity_test_root + '/bin/rootca.crt', cs_crt_file)
225 install_res += env_linux.Install(iotivity_test_root + '/' + install_dir, common_resource_list)
226 install_res += env_linux.Install(iotivity_test_root + '/bin', common_resource_list)
227 install_res += env_linux.Install(iotivity_test_root + '/' + install_dir, cs_resource_list)
228 install_res += env_linux.Install(iotivity_test_root + '/bin', cs_resource_list)
229
230 if cloud_service_build:
231     build_command = 'bash ' + iotivity_test_root + '/res/cloud_resource/cloud_build.sh ' + kafka_root + ' ' + iotivity_root
232     cloud_build = env_linux.Command('cloud_build', None, build_command)
233     default_targets += [cloud_build]
234
235 delete_bin = []
236 i = 0
237 for delete_target in install_targets:
238     delete_bin.append(Command(str(i), [], Delete(delete_target)))
239     i = i +1
240
241 default_targets += install_bin + install_res + delete_bin
242
243 env_linux.Default(default_targets)