Merge test folder of test branch
[iotivity.git] / test / build / windows / SConscriptIUT
1 '''
2 ******************************************************************
3 *
4 * Copyright 2017 Granite River Labs 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 ##
23 # Build script for Windows
24 #
25 ##
26
27 print '\n---------------Started Building Conformance Test App for Windows---------------\n'
28
29 Import('env_windows')
30 import os
31
32
33 env_windows['CC'] = 'cl'
34
35 iotivity_root = env_windows.get('IOTIVITY_ROOT')
36 iotivity_lib_path = env_windows.get('IOTIVITY_LIB_PATH')
37 iotivity_test_root = env_windows.get('IOTIVITY_TEST_ROOT')
38 variant_dir = env_windows.get('VARIANT_DIR')
39 install_dir = env_windows.get('INSTALL_DIR')
40 test_src_root = iotivity_test_root + '/' + variant_dir
41 secured = env_windows.get('SECURED')
42 common_windows_cppflags = env_windows.get('COMMON_WINDOWS_CPPFLAGS')
43
44 install_targets = []
45 default_targets = []
46
47 if env_windows.get('RELEASE'):
48     target_release = 'release'
49 else:
50     target_release = 'debug'
51
52 print "target build is --------------------------------" + target_release
53 # TODO: re-enable warnings, especially: 4244, 4267, 4365
54 env_windows.AppendUnique(CXXFLAGS=[
55     '/wd4244',   # C4244 conversion from one type to another type results in a possible loss of data.
56     '/wd4267',   # C4267 conversion from size_t to a smaller type.
57     '/wd4355',   # C4355 'this' used in base member initializer list.
58     '/wd4800',   # C4800 forcing value to bool 'true' or 'false'.
59     '/wd4996',   # C4996 deprecated declaration.
60     '/wd4820',   # C4820 added padding to the end of a struct.
61     '/wd4514',   # C4514 unreferenced inline function has been removed
62     '/wd4365',   # C4365 signed/unsigned mismatch
63     '/wd4503'])  # C4503 decorated name length exceeded, name was truncated
64
65 env_windows.AppendUnique(CCFLAGS=['-D__WINDOWS__','/EHsc'])
66
67 vs_version = env_windows['MSVC_VERSION']
68
69 # Set release/debug flags
70 #env_windows.AppendUnique(CCFLAGS = ['/MDd', '/Od', '/ZI', '/RTC1', '/Gm'])
71 if env_windows.get('RELEASE'):
72     env_windows.AppendUnique(CCFLAGS = ['/MD','/O2', '/GF'])
73     env_windows.AppendUnique(CPPDEFINES = ['NDEBUG'])
74 elif env_windows.get('TARGET_ARCH') in ['x86', 'x86_64'] or "14.0" in vs_version:
75     env_windows.AppendUnique(CCFLAGS = ['/Od', '/ZI', '/RTC1', '/Gm'])
76     env_windows.AppendUnique(LINKFLAGS = ['/debug'])
77 else:
78     env_windows.AppendUnique(CCFLAGS = ['/Od', '/Zi', '/RTC1', '/Gm'])
79     env_windows.AppendUnique(LINKFLAGS = ['/debug'])
80     env_windows.AppendUnique(LIBPATH = [env_windows.get('BUILD_DIR')])
81     env_windows.AppendUnique(PATH = os.environ['PATH'])
82
83 cppflags = Split('-D__WINDOWS__ -D_WIN32 -DHAVE_STRUCT_TIMESPEC -D_MSC_VER=1900-DBOOST_ASIO_WINDOWS_RUNTIME')
84
85 if secured == '1':
86     cppflags.append('-D__SECURED__')
87     cppflags.append('-D__WITH_DTLS__')
88
89 include_paths = [
90     iotivity_test_root + '/include',
91     iotivity_root + '/resource/include',
92     iotivity_root + '/resource/csdk/include',
93     iotivity_root + '/resource/csdk/connectivity/api',
94     iotivity_root + '/resource/csdk/stack/include',
95     iotivity_root + '/resource/csdk/security/include',
96     iotivity_root + '/resource/csdk/ocsocket/include',
97     iotivity_root + '/resource/csdk/ocrandom/include',
98     iotivity_root + '/resource/csdk/logger/include',
99     iotivity_root + '/resource/c_common/',
100     iotivity_root + '/resource/oc_logger/include',
101     iotivity_root + '/extlibs/cereal/include/',
102     iotivity_root + '/extlibs/timer/',
103     iotivity_root + '/extlibs/tinycbor/tinycbor/src/',
104     iotivity_root + '/extlibs/mbedtls/mbedtls/include',
105     iotivity_root + '/extlibs/timer/',
106     iotivity_root + '/extlibs/boost/boost'
107 ]
108
109 libs = Split('connectivity_abstraction mbedx509 mbedtls mbedcrypto octbstack coap oc oc_logger logger c_common win_helper bcrypt iphlpapi Ws2_32')
110 env_windows.AppendUnique(LIBS = ['bcrypt', 'Ws2_32', 'advapi32', 'iphlpapi', 'crypt32', 'kernel32'])
111
112 src = [
113     test_src_root + '/common/commonutil/c_cpp/ResourceHelper.cpp',
114     test_src_root + '/common/commonutil/c_cpp/ResourceServer.cpp',
115     test_src_root + '/common/commonutil/c_cpp/SampleResource.cpp',
116     test_src_root + '/testapp/IUTSimulatorApp/c_cpp/IUTSimulator.cpp',
117 ]
118
119 iut_app = env_windows.Program(source = src, target = 'IUTSimulator', CPPPATH = include_paths,
120                 LIBS = libs, LIBPATH = iotivity_lib_path, RPATH = iotivity_lib_path, CPPFLAGS = cppflags + common_windows_cppflags)
121 install_targets += [iut_app]
122
123 default_targets += env_windows.Command('copy_justworks_dat_file', [], Copy('.', iotivity_root + '/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat'))
124 default_targets += env_windows.Command('copy_randompin_dat_file', [], Copy('.', iotivity_root + '/resource/csdk/security/provisioning/sample/oic_svr_db_server_randompin.dat'))
125 default_targets += env_windows.Command('copy_mfg_dat_file', [], Copy('.', iotivity_root + '/resource/csdk/security/provisioning/sample/oic_svr_db_server_mfg.dat'))
126
127 install_bin = env_windows.Install(iotivity_test_root + '/' + install_dir, install_targets)
128
129 delete_bin = []
130 i = 0
131 for delete_target in install_targets:
132     delete_bin.append(Command(str(i), [], Delete(delete_target)))
133     i = i + 1
134
135 default_targets += install_bin + delete_bin
136
137 env_windows.Default(default_targets)