fix errata and revise build script
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / common / SConscript
1 #******************************************************************
2 #
3 # Copyright 2015 Samsung Electronics 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 # rcs_common (primitiveResource and expiryTimer) build script
23 ##
24 import os
25 Import('env')
26
27 # Add third party libraries
28 lib_env = env.Clone()
29 SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
30
31 src_dir = lib_env.get('SRC_DIR')
32
33 gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
34
35 rcs_common_env = lib_env.Clone()
36 target_os = env.get('TARGET_OS')
37
38 release = env.get('RELEASE')
39
40 ######################################################################
41 # Build flags
42 ######################################################################
43 rcs_common_env.AppendUnique(CPPPATH = [
44     env.get('SRC_DIR')+'/extlibs',
45     '../../include',
46     'primitiveResource/include'])
47
48 rcs_common_env.AppendUnique(CPPPATH = [
49     'expiryTimer/include',
50     'expiryTimer/src'])
51
52 rcs_common_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
53
54 if target_os not in ['windows', 'winrt']:
55     rcs_common_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
56     if target_os != 'android':
57         rcs_common_env.AppendUnique(CXXFLAGS = ['-pthread'])
58         rcs_common_env.AppendUnique(LIBS = ['pthread'])
59
60 if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
61     rcs_common_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
62
63 if target_os == 'android':
64     rcs_common_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
65     rcs_common_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
66
67 rcs_common_env.AppendUnique(LIBS = ['dl', 'oc'])
68
69 if not release:
70     rcs_common_env.AppendUnique(CXXFLAGS = ['--coverage'])
71     rcs_common_env.PrependUnique(LIBS = ['gcov'])
72
73 ######################################################################
74 # Source files and Targets
75 ######################################################################
76 TIMER_SRC_DIR = 'expiryTimer/src/'
77 RESOURCE_SRC = 'primitiveResource/src/'
78 rcs_common_src = [
79         TIMER_SRC_DIR + 'ExpiryTimerImpl.cpp',
80                 TIMER_SRC_DIR + 'ExpiryTimer.cpp',
81                 RESOURCE_SRC + 'PresenceSubscriber.cpp',
82                 RESOURCE_SRC + 'PrimitiveResource.cpp',
83                 RESOURCE_SRC + 'RCSException.cpp',
84                 RESOURCE_SRC + 'RCSAddress.cpp',
85                 RESOURCE_SRC + 'RCSResourceAttributes.cpp',
86                 RESOURCE_SRC + 'ResponseStatement.cpp'
87         ]
88
89 rcs_common_static = rcs_common_env.StaticLibrary('rcs_common', rcs_common_src)
90 rcs_common_shared = rcs_common_env.SharedLibrary('rcs_common', rcs_common_src)
91 rcs_common_env.InstallTarget([rcs_common_static,rcs_common_shared], 'rcs_common')
92 rcs_common_env.UserInstallTargetLib([rcs_common_static,rcs_common_shared], 'rcs_common')
93
94 ######################################################################
95 # Build Test Expiry Timer and primitive Resource
96 ######################################################################
97 if target_os == 'linux':
98         rcs_common_test_env = rcs_common_env.Clone();
99
100         rcs_common_test_env.PrependUnique(CPPPATH = [
101                 env.get('SRC_DIR')+'/extlibs/hippomocks-master',
102                 gtest_dir + '/include',
103                 'utils/include'
104                 ])
105
106         gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
107         gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
108
109         rcs_common_test_env.PrependUnique(LIBS = [
110                 'octbstack',
111                 'oc_logger',
112                 'connectivity_abstraction',
113                 'coap',
114                 'rcs_common',
115                 gtest,
116                 gtest_main,
117                 'pthread'
118                 ])
119
120         rcs_common_test_src = [
121                 env.Glob('primitiveResource/unittests/*.cpp'),
122                 'expiryTimer/unittests/ExpiryTimerTest.cpp'
123                 ]
124
125         rcs_common_test = rcs_common_test_env.Program('rcs_common_test', rcs_common_test_src)
126         Alias("rcs_common_test", rcs_common_test)
127         env.AppendTarget('rcs_common_test')
128
129         if env.get('TEST') == '1':
130                 from tools.scons.RunTest import *
131                 run_test(rcs_common_test_env, '',
132                         'service/resource-encapsulation/src/common/rcs_common_test')