Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / extlibs / gtest / SConscript
1 ##
2 # 'googletest' script to check if Google Unit Test library is installed.
3 # If not, get it and install it
4 #
5 ##
6
7 import os
8
9 Import('env')
10
11 gtest_env = env.Clone()
12 target_os = gtest_env.get('TARGET_OS')
13 src_dir = gtest_env.get('SRC_DIR')
14
15 targets_need_gtest = ['darwin','linux']
16 gtest_dir      = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0')
17 gtest_lib_dir = os.path.join(gtest_dir,'lib')
18 gtest_dotlib_dir =  os.path.join(gtest_lib_dir, '.libs')
19 gtest_zip_file = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0.zip')
20 gtest_url      = 'https://googletest.googlecode.com/files/gtest-1.7.0.zip'
21
22 if target_os in targets_need_gtest:
23         print '*** Checking for installation of google unit test 1.7.0 ***'
24         if not os.path.exists(os.path.join(gtest_dir, 'configure')):
25                 # If the gtest zip file is not already present, download it
26                 if not os.path.exists(gtest_zip_file):
27                         gtest_zip = gtest_env.Download(gtest_zip_file, gtest_url)
28                 else:
29                         gtest_zip = gtest_zip_file
30                 print 'Unzipping to : ' + gtest_dir
31                 gtest_env.UnpackAll(gtest_dir, gtest_zip)
32
33 if target_os == 'darwin':
34         if os.path.exists(gtest_dir):
35                 # Build gtest and store it at a temporary directory
36
37                 if not os.path.exists(gtest_lib_dir):
38 #                       print 'Create a directory'
39 #                       os.mkdir(gtest_lib_dir)
40
41
42                         print 'Invoke cmake command to generate appropriate make files'
43                         gtest_env.Configure(gtest_dir, './configure')
44
45                         # Run make on gtest
46                         print 'Making google unit test'
47                         gtest_env.Configure(gtest_dir, 'make')
48
49 #                       print 'Create a directory'
50 #                       os.mkdir(gtest_dotlib_dir)
51
52                         print 'Change to a directory'
53                         os.chdir(gtest_dotlib_dir)
54
55 ##                      print 'Change to a directory'
56 #                       os.chdir(gtest_lib_dir)
57
58                         print 'Create hard links pointing to gtest libraries'
59                         os.link('libgtest.a', gtest_lib_dir + 'libgtest.a')
60                         os.link('libgtest_main.a', gtest_lib_dir +  'libgtest_main.a')
61                         print 'Create hard links pointing to gtest libraries - DONE'
62
63
64 elif target_os in ['linux']:
65         if os.path.exists(gtest_dir):
66                 if not os.path.exists(gtest_lib_dir):
67                         # Run configure on gtest
68                         print 'Configuring google unit test'
69                         if env.get('CROSS_COMPILE'):
70                                 env.Configure(gtest_dir, './configure --disable-shared --host=' + env['CROSS_COMPILE'])
71                         else:
72                                 env.Configure(gtest_dir, './configure --disable-shared')
73                         # Run make on gtest
74                         print 'Making google unit test'
75                         gtest_env.Configure(gtest_dir, 'make')
76
77
78 # Export flags once for all
79 if target_os in targets_need_gtest:
80         gtest_env.AppendUnique(LIBPATH = [gtest_dotlib_dir])
81         gtest_env.PrependUnique(CPPPATH = [os.path.join(gtest_dir, 'include')])
82         gtest_env.AppendENVPath('LD_LIBRARY_PATH', gtest_dotlib_dir)
83         if 'g++' in gtest_env.get('CXX'):
84                 gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
85                 gtest_env.AppendUnique(CXXFLAGS = ['-Wall'])
86 # Note: 'pthread' for android is in bionic 
87 # On other platform, if use new gcc(>4.9?) it isn't required, otherwise, it's required
88                 if target_os not in ['android']:
89                         gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
90                         gtest_env.PrependUnique(LIBS = ['pthread'])
91         gtest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])
92
93 Return('gtest_env')