Merge branch 'master' into extended-easysetup
[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', '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'
18
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)
25                 else:
26                         gtest_zip = gtest_zip_file
27
28                 # Unzip gtest
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)
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
45                         print 'Invoke cmake command to generate appropriate make files'
46                         env.Configure(gtest_dir, './configure')
47
48                         # Run make on gtest
49                         print 'Making google unit test'
50                         env.Configure(gtest_dir, 'make')
51
52 #                       print 'Create a directory'
53 #                       os.mkdir(gtest_dotlib_dir)
54
55                         print 'Change to a directory'
56                         os.chdir(gtest_dotlib_dir)
57
58 ##                      print 'Change to a directory'
59 #                       os.chdir(gtest_lib_dir)
60
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'
65
66
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'])
74                         else:
75                                 env.Configure(gtest_dir, './configure --disable-shared')
76                         # Run make on gtest
77                         print 'Making google unit test'
78                         env.Configure(gtest_dir, 'make')
79
80
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):
86                         # Create lib dir
87                         os.mkdir(gtest_lib_dir)
88                         os.mkdir(gtest_dotlib_dir)
89
90                         # Run configure on gtest
91                         print 'Configuring google unit test for compilation'
92                         env.Configure(gtest_dir, 'cmake -G "Unix Makefiles" .')
93
94                         # Run make on gtest
95                         print 'Making google unit test'
96                         env.Configure(gtest_dir, 'make')
97
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')
103
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
110                 else:
111                         output_dir = os.path.join(gtest_dir, 'Debug') + os.sep
112
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").
117                 vs_version_year = ""
118                 vs_target_arch  = ""
119                 vs_num = env['MSVC_VERSION']
120                 if "12.0" in vs_num:
121                         vs_version_year = "Visual Studio 12 2013"
122                 elif "14.0" in vs_num:
123                         vs_version_year = "Visual Studio 14 2015"
124                 else:
125                         print "Error: unknown Visual Studio version %s" % vs_num
126
127                 vs_arch = env['TARGET_ARCH']
128                 if "amd64" in vs_arch:
129                         vs_target_arch = "Win64"
130                 elif "x86" in vs_arch:
131                         vs_target_arch = ""
132                 else:
133                         print "Error: unknown Visual Studio target arch %s" % vs_arch
134
135                 vs_target_string = vs_version_year + " " + vs_target_arch
136
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:
139                         Exit(1)
140
141                 if not env.WhereIs('cmake', env.get('PATH')):
142                         print '''*********************** Error ************************
143 *                                                    *
144 * Please make sure that CMake is in your System PATH *
145 *                                                    *
146 * You can download CMake from:                       *
147 *            https://cmake.org/download/             *
148 *                                                    *
149 ******************************************************
150 '''
151                         Exit(1)
152
153                 if not os.path.exists(gtest_lib_dir):
154                         # Create lib dir
155                         os.mkdir(gtest_lib_dir)
156                         os.mkdir(gtest_dotlib_dir)
157
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')
161
162                         # Run make on gtest
163                         print 'Making google unit test'
164                         env.Configure(gtest_dir, 'msbuild gtest.vcxproj')
165                         env.Configure(gtest_dir, 'msbuild gtest_main.vcxproj')
166
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)
172