2 # 'googletest' script to check if Google Unit Test library is installed. If not,
3 # get it and install it
11 target_os = env.get('TARGET_OS')
12 src_dir = env.get('SRC_DIR')
14 targets_need_gtest = ['darwin','linux', 'msys_nt', 'windows']
15 gtest_dir = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0')
16 gtest_zip_file = os.path.join(src_dir, 'extlibs', 'gtest', 'gtest-1.7.0.zip')
17 gtest_url = 'https://googletest.googlecode.com/files/gtest-1.7.0.zip'
19 if target_os in targets_need_gtest:
20 print '*** Checking for installation of google unit test 1.7.0 ***'
21 if not os.path.exists(gtest_dir):
22 # If the gtest zip file is not already present, download it
23 if not os.path.exists(gtest_zip_file):
24 gtest_zip = env.Download(gtest_zip_file, gtest_url)
26 gtest_zip = gtest_zip_file
29 if not os.path.exists(os.path.join(gtest_dir, 'configure')):
30 print 'Unzipping google unit test'
31 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
37 gtest_lib_dir = gtest_dir + '/lib'
38 gtest_dotlib_dir = gtest_lib_dir + '/.libs'
40 if not os.path.exists(gtest_lib_dir):
41 # print 'Create a directory'
42 # os.mkdir(gtest_lib_dir)
45 print 'Invoke cmake command to generate appropriate make files'
46 env.Configure(gtest_dir, './configure')
49 print 'Making google unit test'
50 env.Configure(gtest_dir, 'make')
52 # print 'Create a directory'
53 # os.mkdir(gtest_dotlib_dir)
55 print 'Change to a directory'
56 os.chdir(gtest_dotlib_dir)
58 ## print 'Change to a directory'
59 # os.chdir(gtest_lib_dir)
61 print 'Create hard links pointing to gtest libraries'
62 os.link('libgtest.a', gtest_lib_dir + 'libgtest.a')
63 os.link('libgtest_main.a', gtest_lib_dir + 'libgtest_main.a')
64 print 'Create hard links pointing to gtest libraries - DONE'
67 elif target_os == 'linux':
68 if os.path.exists(gtest_dir):
69 if not os.path.exists(gtest_dir + "/lib"):
70 # Run configure on gtest
71 print 'Configuring google unit test'
72 if env.get('CROSS_COMPILE'):
73 env.Configure(gtest_dir, './configure --disable-shared --host=' + env['CROSS_COMPILE'])
75 env.Configure(gtest_dir, './configure --disable-shared')
77 print 'Making google unit test'
78 env.Configure(gtest_dir, 'make')
81 elif target_os == 'msys_nt':
82 if os.path.exists(gtest_dir):
83 gtest_lib_dir = gtest_dir + '/lib'
84 gtest_dotlib_dir = gtest_lib_dir + '/.libs'
85 if not os.path.exists(gtest_lib_dir):
87 os.mkdir(gtest_lib_dir)
88 os.mkdir(gtest_dotlib_dir)
90 # Run configure on gtest
91 print 'Configuring google unit test for compilation'
92 env.Configure(gtest_dir, 'cmake -G "Unix Makefiles" .')
95 print 'Making google unit test'
96 env.Configure(gtest_dir, 'make')
98 print 'Moving libraries to lib folder'
99 env.Configure(gtest_dir, 'cp libgtest.a lib')
100 env.Configure(gtest_dir, 'mv libgtest.a lib/.libs')
101 env.Configure(gtest_dir, 'cp libgtest_main.a lib')
102 env.Configure(gtest_dir, 'mv libgtest_main.a lib/.libs')
104 elif target_os == 'windows':
105 if os.path.exists(gtest_dir):
106 gtest_lib_dir = os.path.join(gtest_dir, 'lib')
107 gtest_dotlib_dir = os.path.join(gtest_lib_dir, '.libs')
108 if env.get('RELEASE'):
109 output_dir = os.path.join(gtest_dir, 'Release') + os.sep
111 output_dir = os.path.join(gtest_dir, 'Debug') + os.sep
113 # Three parts to the gtest config string...
114 # 1. "Visual Studio" toolchain name.
115 # 2. VS Version + Year ("14 2015", "12 2013").
116 # 3. Target Architecture ("Win64", "Win32").
119 vs_num = env['MSVC_VERSION']
121 vs_version_year = "Visual Studio 12 2013"
122 elif "14.0" in vs_num:
123 vs_version_year = "Visual Studio 14 2015"
125 print "Error: unknown Visual Studio version %s" % vs_num
127 vs_arch = env['TARGET_ARCH']
128 if "amd64" in vs_arch:
129 vs_target_arch = "Win64"
130 elif "x86" in vs_arch:
133 print "Error: unknown Visual Studio target arch %s" % vs_arch
135 vs_target_string = vs_version_year + " " + vs_target_arch
137 # Exit if we didn't get a match for one of the above.
138 if not vs_version_year or not vs_target_arch:
141 if not env.WhereIs('cmake', env.get('PATH')):
142 print '''*********************** Error ************************
144 * Please make sure that CMake is in your System PATH *
146 * You can download CMake from: *
147 * https://cmake.org/download/ *
149 ******************************************************
153 if not os.path.exists(gtest_lib_dir):
155 os.mkdir(gtest_lib_dir)
156 os.mkdir(gtest_dotlib_dir)
158 # Run configure on gtest
159 print 'Configuring google unit test for compilation'
160 env.Configure(gtest_dir, 'cmake . -G"'+vs_target_string+'" -Dgtest_force_shared_crt=ON')
163 print 'Making google unit test'
164 env.Configure(gtest_dir, 'msbuild gtest.vcxproj')
165 env.Configure(gtest_dir, 'msbuild gtest_main.vcxproj')
167 print 'Moving libraries to lib folder'
168 env.Configure(gtest_dir, 'copy '+output_dir+'gtest.lib %s' % gtest_lib_dir)
169 env.Configure(gtest_dir, 'move '+output_dir+'gtest.lib %s' % gtest_dotlib_dir )
170 env.Configure(gtest_dir, 'copy '+output_dir+'gtest_main.lib %s' % gtest_lib_dir)
171 env.Configure(gtest_dir, 'move '+output_dir+'gtest_main.lib %s' % gtest_dotlib_dir)