Skip to content

Commit f3c29ec

Browse files
Jan200101jpakkane
authored andcommitted
add unittest for cmake preprocessing
it uses the existing 14 configure file test case to configure config 7 and 10 with cmake and meson and then compares the relevant output to see if they are equal
1 parent c8432df commit f3c29ec

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project("configure file test" LANGUAGES C)
4+
5+
set("var1" "foo")
6+
set("var2" "bar")
7+
configure_file("config7.h.in" "config7.h")
8+
9+
set("var" "foo")
10+
configure_file("config10.h.in" "config10.h")

unittests/allplatformstests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,47 @@ def check_formats(confdata, result):
222222
confdata.values = {'VAR': (['value'], 'description')}
223223
self.assertRaises(MesonException, conf_str, ['#mesondefine VAR'], confdata, 'meson')
224224

225+
def test_cmake_configuration(self):
226+
if self.backend is not Backend.ninja:
227+
raise SkipTest('ninja backend needed to configure with cmake')
228+
229+
cmake = ExternalProgram('cmake')
230+
if not cmake.found():
231+
raise SkipTest('cmake not available')
232+
233+
cmake_version = cmake.get_version()
234+
if not version_compare(cmake_version, '>=3.13.5'):
235+
raise SkipTest('cmake is too old')
236+
237+
with tempfile.TemporaryDirectory() as tmpdir:
238+
srcdir = os.path.join(tmpdir, 'src')
239+
240+
shutil.copytree(os.path.join(self.src_root, 'test cases', 'common', '14 configure file'), srcdir)
241+
self.init(srcdir)
242+
243+
cmake_builddir = os.path.join(srcdir, "cmake_builddir")
244+
self.assertNotEqual(self.builddir, cmake_builddir)
245+
self._run([cmake.path, '-G', 'Ninja', '-S', srcdir, '-B', cmake_builddir])
246+
247+
header_list = [
248+
'config7.h',
249+
'config10.h',
250+
]
251+
252+
for header in header_list:
253+
meson_header = ""
254+
cmake_header = ""
255+
256+
with open(os.path.join(self.builddir, header), encoding='utf-8') as f:
257+
meson_header = f.read()
258+
259+
cmake_header_path = os.path.join(cmake_builddir, header)
260+
with open(os.path.join(cmake_builddir, header), encoding='utf-8') as f:
261+
cmake_header = f.read()
262+
263+
self.assertTrue(cmake_header, f'cmake generated header {header} is empty')
264+
self.assertEqual(cmake_header, meson_header)
265+
225266
def test_absolute_prefix_libdir(self):
226267
'''
227268
Tests that setting absolute paths for --prefix and --libdir work. Can't

0 commit comments

Comments
 (0)