1 # -*- mode: python; python-indent-offset: 4; indent-tabs-mode: nil -*-
3 # 'googletest' script to check if Google Unit Test library is installed.
4 # If not, get it and install it
12 gtest_env = env.Clone()
13 target_os = gtest_env.get('TARGET_OS')
14 src_dir = gtest_env.get('SRC_DIR')
16 targets_need_gtest = ['darwin','linux', 'msys_nt', 'windows']
17 gtest_dir = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0')
18 gtest_lib_dir = os.path.join(gtest_dir,'lib')
19 gtest_dotlib_dir = os.path.join(gtest_lib_dir, '.libs')
20 gtest_zip_file = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0.zip')
21 gtest_url = 'http://pkgs.fedoraproject.org/repo/pkgs/gtest/gtest-1.7.0.zip/2d6ec8ccdf5c46b05ba54a9fd1d130d7/gtest-1.7.0.zip'
23 if target_os in targets_need_gtest:
24 print '*** Checking for installation of google unit test 1.7.0 ***'
25 if not os.path.exists(os.path.join(gtest_dir, 'configure')):
26 # If the gtest zip file is not already present, download it
27 if not os.path.exists(gtest_zip_file):
28 gtest_zip = gtest_env.Download(gtest_zip_file, gtest_url)
30 gtest_zip = gtest_zip_file
31 print 'Unzipping to : ' + gtest_dir
32 gtest_env.UnpackAll(gtest_dir, gtest_zip)
34 if target_os == 'darwin':
35 if os.path.exists(gtest_dir):
36 # Build gtest and store it at a temporary directory
38 if not os.path.exists(gtest_lib_dir):
39 # print 'Create a directory'
40 # os.mkdir(gtest_lib_dir)
43 print 'Invoke cmake command to generate appropriate make files'
44 gtest_env.Configure(gtest_dir, './configure')
47 print 'Making google unit test'
48 gtest_env.Configure(gtest_dir, 'make')
50 # print 'Create a directory'
51 # os.mkdir(gtest_dotlib_dir)
53 print 'Change to a directory'
54 os.chdir(gtest_dotlib_dir)
56 ## print 'Change to a directory'
57 # os.chdir(gtest_lib_dir)
59 print 'Create hard links pointing to gtest libraries'
60 os.link('libgtest.a', gtest_lib_dir + 'libgtest.a')
61 os.link('libgtest_main.a', gtest_lib_dir + 'libgtest_main.a')
62 print 'Create hard links pointing to gtest libraries - DONE'
65 elif target_os in ['linux']:
66 if os.path.exists(gtest_dir):
67 if not os.path.exists(gtest_lib_dir):
68 # Run configure on gtest
69 print 'Configuring google unit test'
70 if env.get('CROSS_COMPILE'):
71 env.Configure(gtest_dir, './configure --disable-shared --host=' + env['CROSS_COMPILE'])
73 env.Configure(gtest_dir, './configure --disable-shared')
75 print 'Making google unit test'
76 gtest_env.Configure(gtest_dir, 'make')
78 elif target_os == 'msys_nt':
79 if os.path.exists(gtest_dir):
80 if not os.path.exists(gtest_lib_dir):
82 os.mkdir(gtest_lib_dir)
83 os.mkdir(gtest_dotlib_dir)
85 # Run configure on gtest
86 print 'Configuring google unit test for compilation'
87 gtest_env.Configure(gtest_dir, 'cmake -G "Unix Makefiles" .')
90 print 'Making google unit test'
91 gtest_env.Configure(gtest_dir, 'make')
93 print 'Moving libraries to lib folder'
94 gtest_env.Configure(gtest_dir, 'cp libgtest.a lib')
95 gtest_env.Configure(gtest_dir, 'mv libgtest.a lib/.libs')
96 gtest_env.Configure(gtest_dir, 'cp libgtest_main.a lib')
97 gtest_env.Configure(gtest_dir, 'mv libgtest_main.a lib/.libs')
99 elif target_os == 'windows':
100 if os.path.exists(gtest_dir):
101 if gtest_env.get('RELEASE'):
102 output_dir = os.path.join(gtest_dir, 'Release') + os.sep
104 output_dir = os.path.join(gtest_dir, 'Debug') + os.sep
106 # Three parts to the gtest config string...
107 # 1. "Visual Studio" toolchain name.
108 # 2. VS Version + Year ("14 2015", "12 2013").
109 # 3. Target Architecture ("Win64", "Win32").
112 vs_num = env['MSVC_VERSION']
114 vs_version_year = "Visual Studio 12 2013"
115 elif "14.0" in vs_num:
116 vs_version_year = "Visual Studio 14 2015"
118 print "Error: unknown Visual Studio version %s" % vs_num
120 vs_arch = env['TARGET_ARCH']
121 if "amd64" in vs_arch:
122 vs_target_arch = "Win64"
123 elif "x86" in vs_arch:
126 print "Error: unknown Visual Studio target arch %s" % vs_arch
128 vs_target_string = vs_version_year + " " + vs_target_arch
130 # Exit if we didn't get a match for one of the above.
131 if not vs_version_year or not vs_target_arch:
134 if not gtest_env.WhereIs('cmake', gtest_env.get('PATH')):
135 print '''*********************** Error ************************
137 * Please make sure that CMake is in your System PATH *
139 * You can download CMake from: *
140 * https://cmake.org/download/ *
142 ******************************************************
146 if not os.path.exists(gtest_lib_dir):
148 os.mkdir(gtest_lib_dir)
149 os.mkdir(gtest_dotlib_dir)
151 # Run configure on gtest
152 print 'Configuring google unit test for compilation'
153 gtest_env.Configure(gtest_dir, 'cmake . -G"' + vs_target_string + '" -Dgtest_force_shared_crt=ON')
156 print 'Making google unit test'
157 gtest_env.Configure(gtest_dir, 'msbuild gtest.vcxproj')
158 gtest_env.Configure(gtest_dir, 'msbuild gtest_main.vcxproj')
160 print 'Moving libraries to lib folder'
161 gtest_env.Configure(gtest_dir, 'copy '+output_dir+'gtest.lib %s' % gtest_lib_dir)
162 gtest_env.Configure(gtest_dir, 'move '+output_dir+'gtest.lib %s' % gtest_dotlib_dir )
163 gtest_env.Configure(gtest_dir, 'copy '+output_dir+'gtest_main.lib %s' % gtest_lib_dir)
164 gtest_env.Configure(gtest_dir, 'move '+output_dir+'gtest_main.lib %s' % gtest_dotlib_dir)
166 # Export flags once for all
167 if target_os in targets_need_gtest:
168 gtest_env.AppendUnique(LIBPATH = [gtest_dotlib_dir])
169 gtest_env.PrependUnique(CPPPATH = [os.path.join(gtest_dir, 'include')])
170 gtest_env.AppendENVPath('LD_LIBRARY_PATH', gtest_dotlib_dir)
171 if 'g++' in gtest_env.get('CXX'):
172 gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
173 gtest_env.AppendUnique(CXXFLAGS = ['-Wall'])
174 # Note: 'pthread' for android is in bionic
175 # On other platform, if use new gcc(>4.9?) it isn't required, otherwise, it's required
176 if target_os not in ['android']:
177 gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
178 gtest_env.PrependUnique(LIBS = ['pthread'])
179 gtest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])