Imported Upstream version 1.0.0
[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
93 ######################################################################
94 # Build Test Expiry Timer and primitive Resource
95 ######################################################################
96 if target_os == 'linux':
97         rcs_common_test_env = rcs_common_env.Clone();
98
99         rcs_common_test_env.PrependUnique(CPPPATH = [
100                 env.get('SRC_DIR')+'/extlibs/hippomocks-master',
101                 gtest_dir + '/include',
102                 'utils/include'
103                 ])
104
105         gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
106         gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
107
108         rcs_common_test_env.PrependUnique(LIBS = [
109                 'octbstack',
110                 'oc_logger',
111                 'connectivity_abstraction',
112                 'coap',
113                 'rcs_common',
114                 gtest,
115                 gtest_main,
116                 'pthread'
117                 ])
118
119         rcs_common_test_src = [
120                 env.Glob('primitiveResource/unittests/*.cpp'),
121                 'expiryTimer/unittests/ExpiryTimerTest.cpp'
122                 ]
123
124         rcs_common_test = rcs_common_test_env.Program('rcs_common_test', rcs_common_test_src)
125         Alias("rcs_common_test", rcs_common_test)
126         env.AppendTarget('rcs_common_test')
127
128         if env.get('TEST') == '1':
129                 from tools.scons.RunTest import *
130                 run_test(rcs_common_test_env, '',
131                         'service/resource-encapsulation/src/common/rcs_common_test')