Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / extlibs / gtest / SConscript
1 ##
2 # 'googletest' script to check if Google Unit Test library is installed.  If not,
3 # get it and install it
4 #
5 ##
6
7 import os
8
9 Import('env')
10
11 target_os = env.get('TARGET_OS')
12 src_dir = env.get('SRC_DIR')
13
14 targets_need_gtest = ['darwin','linux']
15 gtest_dir      = src_dir + '/extlibs/gtest/gtest-1.7.0'
16 gtest_zip_file = src_dir + '/extlibs/gtest/gtest-1.7.0.zip'
17 gtest_url      = 'https://googletest.googlecode.com/files/gtest-1.7.0.zip'
18
19 if target_os in targets_need_gtest:
20         print '*** Checking for installation of google unit test 1.7.0 ***'
21
22         if not os.path.exists(gtest_dir):
23                 # If the gtest zip file is not already present, download it
24                 if not os.path.exists(gtest_zip_file):
25                         gtest_zip = env.Download(gtest_zip_file, gtest_url)
26                 else:
27                         gtest_zip = gtest_zip_file
28
29                 # Unzip gtest
30                 print 'Unzipping google unit test'
31                 env.UnpackAll(gtest_dir, gtest_zip)
32
33
34 if target_os == 'darwin':
35         if os.path.exists(gtest_dir):
36                 # Build gtest and store it at a temporary directory
37                 gtest_lib_dir = gtest_dir + '/lib'
38                 gtest_dotlib_dir = gtest_lib_dir + '/.libs'
39
40                 if not os.path.exists(gtest_lib_dir):
41                         print 'Create a directory'
42                         os.mkdir(gtest_lib_dir)
43
44                         print 'Change to a directory'
45                         os.chdir(gtest_lib_dir)
46
47                         print 'Invoke cmake command to generate appropriate make files'
48                         env.Configure(gtest_lib_dir, 'cmake -G"Unix Makefiles" ..')
49
50                         # Run make on gtest
51                         print 'Making google unit test'
52                         env.Configure(gtest_lib_dir, 'make')
53
54                         print 'Create a directory'
55                         os.mkdir(gtest_dotlib_dir)
56
57                         print 'Change to a directory'
58                         os.chdir(gtest_dotlib_dir)
59
60                         print 'Create hard links pointing to gtest libraries'
61                         os.link('../' + 'libgtest.a', 'libgtest.a')
62                         os.link('../' + 'libgtest_main.a', 'libgtest_main.a')
63                         print 'Create hard links pointing to gtest libraries - DONE'
64
65
66 elif target_os == 'linux':
67         if os.path.exists(gtest_dir):
68                 if not os.path.exists(gtest_dir + "/lib"):
69                         # Run configure on gtest
70                         print 'Configuring google unit test'
71                         if env.get('CROSS_COMPILE'): 
72                                 env.Configure(gtest_dir, './configure --host=' + env['CROSS_COMPILE'])
73                         else:
74                                 env.Configure(gtest_dir, './configure')
75
76                         # Run make on gtest
77                         print 'Making google unit test'
78                         env.Configure(gtest_dir, 'make')
79
80