riscv64: Add support for RISC-V
[platform/upstream/iotivity.git] / extlibs / gtest / SConscript
1 # -*- mode: python; python-indent-offset: 4; indent-tabs-mode: nil -*-
2 ##
3 # 'googletest' script to check if Google Unit Test library is installed.
4 # If not, get it and install it
5 #
6 ##
7
8 import os
9 import shutil
10
11 Import('env')
12
13 gtest_env = env.Clone()
14 target_os = gtest_env.get('TARGET_OS')
15 src_dir = gtest_env.get('SRC_DIR')
16
17 targets_need_gtest = ['darwin','linux', 'msys_nt', 'windows']
18 gtest_dir      = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0')
19 gtest_lib_dir = os.path.join(gtest_dir,'lib')
20 gtest_dotlib_dir =  os.path.join(gtest_lib_dir, '.libs')
21 gtest_zip_file = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0.zip')
22 gtest_url = 'http://pkgs.fedoraproject.org/repo/pkgs/gtest/gtest-1.7.0.zip/2d6ec8ccdf5c46b05ba54a9fd1d130d7/gtest-1.7.0.zip'
23
24 if target_os in targets_need_gtest:
25         print '*** Checking for installation of google unit test 1.7.0 ***'
26         env_lib_path = env.get('LIBPATH')
27         if gtest_lib_dir in env_lib_path:
28                 print '*** Found google unit test, set environments ***'
29                 gtest_env.AppendUnique(LIBPATH = [gtest_dotlib_dir])
30                 gtest_env.PrependUnique(CPPPATH = [os.path.join(gtest_dir, 'include')])
31                 gtest_env.AppendENVPath('LD_LIBRARY_PATH', gtest_dotlib_dir)
32                 if 'g++' in gtest_env.get('CXX'):
33                         gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
34                         gtest_env.AppendUnique(CXXFLAGS = ['-Wall'])
35                         if target_os not in ['android']:
36                                 gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
37                                 gtest_env.PrependUnique(LIBS = ['pthread'])
38                 gtest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])
39                 if target_os in ['windows']:
40                         gtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
41                 Return('gtest_env')
42         else:
43                 print '*** Prepare to build google unit test 1.7.0 ***'
44                 if os.path.exists(gtest_dir):
45                         shutil.rmtree(gtest_dir)
46                 # If the gtest zip file is not already present, download it
47                 if not os.path.exists(gtest_zip_file):
48                         gtest_zip = gtest_env.Download(gtest_zip_file, gtest_url)
49                 else:
50                         gtest_zip = gtest_zip_file
51                 print 'Unzipping to : ' + gtest_dir
52                 gtest_env.UnpackAll(gtest_dir, gtest_zip)
53
54 if target_os == 'darwin':
55         if os.path.exists(gtest_dir):
56                 # Build gtest and store it at a temporary directory
57
58                 if not os.path.exists(gtest_lib_dir):
59 #                       print 'Create a directory'
60 #                       os.mkdir(gtest_lib_dir)
61
62
63                         print 'Invoke cmake command to generate appropriate make files'
64                         gtest_env.Configure(gtest_dir, './configure')
65
66                         # Run make on gtest
67                         print 'Making google unit test'
68                         gtest_env.Configure(gtest_dir, 'make')
69
70 #                       print 'Create a directory'
71 #                       os.mkdir(gtest_dotlib_dir)
72
73                         print 'Change to a directory'
74                         os.chdir(gtest_dotlib_dir)
75
76 ##                      print 'Change to a directory'
77 #                       os.chdir(gtest_lib_dir)
78
79                         print 'Create hard links pointing to gtest libraries'
80                         os.link('libgtest.a', gtest_lib_dir + 'libgtest.a')
81                         os.link('libgtest_main.a', gtest_lib_dir +  'libgtest_main.a')
82                         print 'Create hard links pointing to gtest libraries - DONE'
83
84
85 elif target_os in ['linux']:
86         if os.path.exists(gtest_dir):
87                 if not os.path.exists(gtest_lib_dir):
88                         # Run configure on gtest
89                         print 'Configuring google unit test'
90                         if env.get('CROSS_COMPILE'):
91                                 env.Configure(gtest_dir, './configure --disable-shared --host=' + env['CROSS_COMPILE'])
92                         else:
93                                 env.Configure(gtest_dir, './configure --disable-shared')
94                         # Run make on gtest
95                         print 'Making google unit test'
96                         gtest_env.Configure(gtest_dir, 'make')
97                 env.AppendUnique(LIBPATH = [gtest_lib_dir])
98
99 elif target_os == 'msys_nt':
100         if os.path.exists(gtest_dir):
101                 if not os.path.exists(gtest_lib_dir):
102                         # Create lib dir
103                         os.mkdir(gtest_lib_dir)
104                         os.mkdir(gtest_dotlib_dir)
105
106                         # Run configure on gtest
107                         print 'Configuring google unit test for compilation'
108                         gtest_env.Configure(gtest_dir, 'cmake -G "Unix Makefiles" .')
109
110                         # Run make on gtest
111                         print 'Making google unit test'
112                         gtest_env.Configure(gtest_dir, 'make')
113
114                         print 'Moving libraries to lib folder'
115                         gtest_env.Configure(gtest_dir, 'cp libgtest.a lib')
116                         gtest_env.Configure(gtest_dir, 'mv libgtest.a lib/.libs')
117                         gtest_env.Configure(gtest_dir, 'cp libgtest_main.a lib')
118                         gtest_env.Configure(gtest_dir, 'mv libgtest_main.a lib/.libs')
119
120 elif target_os == 'windows':
121         # Avoid building the same StaticLibrary in more than one environment, by using the
122         # IOTIVITY_GTEST_HAS_BEEN_BUILT environment variable
123         if not env.has_key('IOTIVITY_GTEST_HAS_BEEN_BUILT'):
124                 gtest_env.Append(CPPPATH = [ gtest_dir ])
125                 gtest = gtest_env.StaticLibrary(target = 'gtest', source = [ '%s/src/gtest-all.cc' % gtest_dir ])
126                 gtest_main = gtest_env.StaticLibrary(target = 'gtest_main', source = [ '%s/src/gtest_main.cc' % gtest_dir ])
127                 gtest_env.InstallTarget(gtest, 'gtest')
128                 gtest_env.InstallTarget(gtest_main, 'gtest_main')
129
130                 vars = Variables();
131                 vars.AddVariables(('IOTIVITY_GTEST_HAS_BEEN_BUILT', '', '1'))
132                 vars.Update(env)
133
134 # Export flags once for all
135 if target_os in targets_need_gtest:
136         gtest_env.AppendUnique(LIBPATH = [gtest_dotlib_dir])
137         gtest_env.PrependUnique(CPPPATH = [os.path.join(gtest_dir, 'include')])
138         gtest_env.AppendENVPath('LD_LIBRARY_PATH', gtest_dotlib_dir)
139         if 'g++' in gtest_env.get('CXX'):
140                 gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
141                 gtest_env.AppendUnique(CXXFLAGS = ['-Wall'])
142 # Note: 'pthread' for android is in bionic 
143 # On other platform, if use new gcc(>4.9?) it isn't required, otherwise, it's required
144                 if target_os not in ['android']:
145                         gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
146                         gtest_env.PrependUnique(LIBS = ['pthread'])
147         gtest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])
148         if target_os in ['windows']:
149                 gtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
150
151 Return('gtest_env')