python/swig: Check swig version to determine whether -py3 is needed
authorMartin Belanger <martin.belanger@dell.com>
Thu, 27 Apr 2023 15:36:11 +0000 (11:36 -0400)
committerDaniel Wagner <wagi@monom.org>
Fri, 28 Apr 2023 06:15:49 +0000 (08:15 +0200)
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
libnvme/meson.build

index eaf5194820b6b0fb1b431d6ea9a25b6ab32ba693..12a601e88a5b07906f341f3aa9f11e4a3d7a158c 100644 (file)
@@ -8,7 +8,7 @@
 want_python = get_option('python')
 if want_python.disabled()
     build_python_bindings = false
-    py3_dep = dependency('', required: false)
+    py3_dep = dependency('', required: false)  # Needed for muon
 else
     python3 = import('python').find_installation('python3')
     py3_dep = python3.dependency(required: want_python)
@@ -18,11 +18,19 @@ else
 endif
 
 if build_python_bindings
+    r = run_command(swig, ['-version'], check: true)  # Returns: "\nSWIG Version 4.1.1\n\nCompiled with ..."
+    swig_version = r.stdout().split('\n')[1].split()[2].strip()
+    if swig_version.version_compare('<4.1.0')
+        swig_cmd = [swig, '-python', '-py3', '-o', '@OUTPUT1@', '@INPUT0@']
+    else
+        swig_cmd = [swig, '-python', '-o', '@OUTPUT1@', '@INPUT0@']
+    endif
+
     pymod_swig = custom_target(
         'nvme.py',
         input:   ['nvme.i'],
         output:  ['nvme.py', 'nvme_wrap.c'],
-        command: [swig, '-python', '-py3', '-o', '@OUTPUT1@', '@INPUT0@'],
+        command: swig_cmd,
         install: true,
         install_dir: [python3.get_install_dir(pure: false, subdir: 'libnvme'), false],
     )