[Win32] Modify SConscripts to prepare for VS
[platform/upstream/iotivity.git] / resource / csdk / security / unittest / SConscript
1 # //******************************************************************
2 # //
3 # // Copyright 2015 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 Import('env')
23 import os
24 import os.path
25 srmtest_env = env.Clone()
26
27 src_dir = srmtest_env.get('SRC_DIR')
28 target_os = env.get('TARGET_OS')
29
30 ######################################################################
31 # Build flags
32 ######################################################################
33 srmtest_env.PrependUnique(CPPPATH = [
34         '../../ocmalloc/include',
35                 '../../connectivity/inc',
36                 '../../connectivity/api',
37                 '../../connectivity/external/inc',
38                 '../../connectivity/lib/libcoap-4.1.1',
39                 '../include',
40                 '../include/internal',
41                 '../../logger/include',
42                 '../../ocmalloc/include',
43                 '../../stack/include',
44                 '../../stack/include/internal',
45                 '../../../oc_logger/include',
46                 '../../../../extlibs/gtest/gtest-1.7.0/include',
47                 '../../../../extlibs/cjson/',
48                 '../provisioning/include',
49 #               '../../../../extlibs/tinydtls/',
50                 '../include'
51                 ])
52
53 srmtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
54 srmtest_env.AppendUnique(LIBS = ['-lpthread'])
55 srmtest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
56 srmtest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
57 srmtest_env.PrependUnique(LIBS = ['ocsrm',
58                                     'octbstack',
59                                     'oc_logger',
60                                     'connectivity_abstraction',
61                                     'coap',
62                                     'gtest',
63                                     'gtest_main'])
64
65 if env.get('SECURED') == '1':
66     srmtest_env.AppendUnique(LIBS = ['tinydtls', 'timer'])
67
68 if env.get('LOGGING'):
69         srmtest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
70
71 if target_os == 'windows':
72         srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
73         srmtest_env.AppendUnique(LIBS = ['advapi32', 'kernel32', 'ws2_32', 'iphlpapi'])
74 else:
75         # TODO: Implement feature check.
76         srmtest_env.AppendUnique(CPPDEFINES = ['HAVE_LOCALTIME_R'])
77
78 ######################################################################
79 # Source files and Targets
80 ######################################################################
81 unittest = srmtest_env.Program('unittest', ['aclresourcetest.cpp',
82                                             'amaclresourcetest.cpp',
83                                             'pstatresource.cpp',
84                                             'doxmresource.cpp',
85                                             'policyengine.cpp',
86                                             'securityresourcemanager.cpp',
87                                             'credentialresource.cpp',
88                                             'srmutility.cpp',
89                                             'iotvticalendartest.cpp',
90                                             'base64tests.cpp',
91                                             'svcresourcetest.cpp',
92                                             'srmtestcommon.cpp',
93                                             'directpairingtest.cpp'])
94
95 Alias("test", [unittest])
96
97 unittest_src_dir = src_dir + '/resource/csdk/security/unittest/'
98 unittest_build_dir = os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk', 'security', 'unittest') + os.sep
99
100 srmtest_env.AppendUnique(CPPDEFINES = ['SECURITY_BUILD_UNITTEST_DIR='+unittest_build_dir.encode('string_escape')])
101
102 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
103     unittest_src_dir + 'oic_unittest.json'))
104 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
105     unittest_src_dir + 'oic_unittest_acl1.json'))
106 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
107     unittest_src_dir + 'oic_unittest_default_acl.json'))
108
109 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
110     unittest_src_dir + 'oic_unittest.dat'))
111 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
112     unittest_src_dir + 'oic_unittest_acl1.dat'))
113 srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
114     unittest_src_dir + 'oic_unittest_default_acl.dat'))
115
116 env.AppendTarget('test')
117 if env.get('TEST') == '1':
118         target_os = env.get('TARGET_OS')
119         if target_os in ['linux', 'windows']:
120                 out_dir = env.get('BUILD_DIR')
121                 result_dir = env.get('BUILD_DIR') + '/test_out/'
122                 if not os.path.isdir(result_dir):
123                         os.makedirs(result_dir)
124                 srmtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
125                 srmtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
126                 srmtest_env.AppendENVPath('PATH', [os.path.join(out_dir, 'resource', 'csdk')])
127                 srmtest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
128                 ut = srmtest_env.Command ('ut', None, out_dir + '/resource/csdk/security/unittest/unittest')
129                 AlwaysBuild ('ut')