[IOT-2259] Windows: Handle Persistent Storage for UWP Apps
[platform/upstream/iotivity.git] / resource / c_common / SConscript
1 #******************************************************************
2 #
3 # Copyright 2014 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 datetime
25
26 target_os = env.get('TARGET_OS')
27 target_arch = env.get('TARGET_ARCH')
28 src_dir = env.get('SRC_DIR')
29
30 ######################################################################
31 # Generate iotivity_config.h using presence of headers
32 ######################################################################
33 config_h_file_path = os.path.join(src_dir, 'resource', 'c_common', 'iotivity_config.h')
34
35 if (os.path.exists(config_h_file_path)) and (env.GetOption('clean')):
36     os.remove(config_h_file_path)
37
38 if (not os.path.isfile(config_h_file_path)) and (not env.GetOption('clean')):
39     conf = Configure(env.Clone(LIBS = []))
40
41     config_h_header = '''
42 /* ****************************************************************************
43  * iotivity_config.h - IoTivity platform-specific configuration header.
44  *
45  * Auto-generated code for the %s %s platform.
46  *
47  *************************************************************************** */
48
49 #ifndef IOTIVITY_CONFIG_H__
50 #define IOTIVITY_CONFIG_H__
51
52 ''' % (str(target_os), str(target_arch))
53
54     config_h_body = ''
55
56     config_h_footer = '''
57
58 #include "platform_features.h"
59
60 #endif // IOTIVITY_CONFIG_H__
61
62 '''
63
64     cxx_headers = ['arpa/inet.h',
65                    'fcntl.h',
66                    'grp.h',
67                    'in6addr.h',
68                    'linux/limits.h',
69                    'memory.h',
70                    'net/if.h',
71                    'netdb.h',
72                    'netinet/in.h',
73                    'pthread.h',
74                    'pwd.h',
75                    'stdlib.h',
76                    'string.h',
77                    'strings.h',
78                    'sys/ioctl.h',
79                    'sys/poll.h',
80                    'sys/select.h',
81                    'sys/socket.h',
82                    'sys/stat.h',
83                    'sys/time.h',
84                    'sys/types.h',
85                    'sys/unistd.h',
86                    'syslog.h',
87                    'time.h',
88                    'unistd.h',
89                    'uuid/uuid.h',
90                    'windows.h',
91                    'winsock2.h',
92                    'ws2tcpip.h']
93
94     cxx_functions = ['strptime']
95
96     if target_os == 'arduino':
97         # Detection of headers on the Arduino platform is currently broken.
98         cxx_headers = []
99
100     if target_os == 'msys_nt':
101         # WinPThread provides a pthread.h, but we want to use native threads.
102         cxx_headers.remove('pthread.h')
103
104     def get_define_from_string(header_file):
105         header_file_converted = header_file.replace("/","_").replace(".","_").upper()
106         return "HAVE_" + header_file_converted
107
108     for header_file_name in cxx_headers:
109         if conf.CheckCXXHeader(header_file_name):
110             config_h_body += "#define %s 1\n\n" % get_define_from_string(header_file_name)
111
112     for function_name in cxx_functions:
113         if conf.CheckFunc(function_name):
114             config_h_body += "#define %s 1\n\n" % get_define_from_string(function_name)
115     conf.Finish()
116
117     # Autoconf feature doesn't work with Jenkins' arduino toolchain, so hardcode it here.
118     if target_os == 'arduino':
119         config_h_body += "#define HAVE_ARDUINO_TIME_H\n\n"
120
121     # Generate the file
122     if os.path.exists(config_h_file_path):
123         os.remove(config_h_file_path)
124     config_h_file = open(config_h_file_path, "w")
125     config_h_file.write(config_h_header + config_h_body + config_h_footer)
126     config_h_file.close()
127
128 # Sanity check to ensure that the above block created the file.
129 if (not os.path.exists(config_h_file_path)) and (not env.GetOption('clean')):
130     print "Error: iotivity_config.h file not created!"
131     Exit(1)
132
133 # iotivity_config.h should be copied to the build dir
134 env.UserInstallTargetHeader(config_h_file_path, 'c_common', 'iotivity_config.h')
135
136 # Use the generated file internally
137 env.AppendUnique(CPPPATH = [os.path.join(src_dir, 'resource', 'c_common')])
138
139 ######################################################################
140
141 env.AppendUnique(CPPPATH = [
142     os.path.join(Dir('.').abspath, 'oic_malloc', 'include'),
143     os.path.join(Dir('.').abspath, 'oic_string', 'include'),
144     os.path.join(Dir('.').abspath, 'oic_time', 'include'),
145     os.path.join(Dir('.').abspath, 'ocatomic', 'include'),
146     os.path.join(Dir('.').abspath, 'ocrandom', 'include'),
147     os.path.join(Dir('.').abspath, 'octhread', 'include'),
148     os.path.join(Dir('.').abspath, 'oic_platform', 'include'),
149     os.path.join(Dir('.').abspath, 'octimer', 'include'),
150    '#/extlibs/mbedtls/mbedtls/include'
151 ])
152
153 if target_os not in ['tizen']:
154     env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'c_common')])
155
156 if target_os in ['tizen', 'linux']:
157     env.ParseConfig("pkg-config --cflags --libs uuid")
158
159 common_env = env.Clone()
160
161 ######################################################################
162 # Enable treating all warnings as errors
163 ######################################################################
164
165 if target_os in ['windows', 'msys_nt']:
166     common_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
167
168 ######################################################################
169 # Add platform-specific helper library
170 ######################################################################
171
172 if target_os in ['windows', 'msys_nt']:
173     SConscript('windows/SConscript', 'common_env')
174
175 ######################################################################
176 # Source files and Targets
177 ######################################################################
178 common_src = [
179     'oic_string/src/oic_string.c',
180     'oic_malloc/src/oic_malloc.c',
181     'oic_time/src/oic_time.c',
182     'ocrandom/src/ocrandom.c',
183     'oic_platform/src/oic_platform.c'
184 ]
185
186 if env['POSIX_SUPPORTED']:
187     common_src.append('octhread/src/posix/octhread.c')
188 elif target_os  in ['windows']:
189     common_src.append('octhread/src/windows/octhread.c')
190 else:
191     common_src.append('octhread/src/noop/octhread.c')
192
193 if target_os in ['windows', 'msys_nt']:
194     common_src.append('ocatomic/src/windows/ocatomic.c')
195 elif target_os in ['arduino']:
196     common_src.append('ocatomic/src/arduino/ocatomic.c')
197 else:
198     common_src.append('ocatomic/src/others/ocatomic.c')
199
200 if target_os in ['windows']:
201     common_src.append('oic_platform/src/windows/oic_winplatform.cpp')
202 else:
203     common_src.append('oic_platform/src/others/oic_otherplatforms.c')
204
205 # C++ Arduino's <Timer.h> is included so use C++ compiler/flags
206 if target_os in ['arduino']:
207     octimer_env = common_env.Clone()
208     octimer_env.Replace(CC = env.get('CXX'))
209     octimer_env.Replace(CFLAGS = env.get('CXXFLAGS'))
210     octimer = octimer_env.Object('octimer/src/octimer.c')
211     common_src.append(octimer)
212 else:
213     common_src.append('octimer/src/octimer.c')
214
215 common_env.AppendUnique(LIBS = ['logger'])
216 common_env.AppendUnique(CPPPATH = ['#resource/csdk/logger/include'])
217 commonlib = common_env.StaticLibrary('c_common', common_src)
218 common_env.InstallTarget(commonlib, 'c_common')
219 common_env.UserInstallTargetLib(commonlib, 'c_common')
220 common_env.UserInstallTargetHeader('iotivity_debug.h', 'c_common', 'iotivity_debug.h')
221 common_env.UserInstallTargetHeader('platform_features.h', 'c_common', 'platform_features.h')
222
223 Clean(commonlib, config_h_file_path)
224
225 # c_common calls into logger.
226 env.PrependUnique(LIBS = ['c_common', 'logger'])