diff --git a/meson_options.txt b/meson_options.txt
index 7a9aecfc..6a0bd0be 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -63,3 +63,8 @@ option('pycamera',
         type : 'feature',
         value : 'disabled',
         description : 'Enable libcamera Python bindings (experimental)')
+
+option('disable-vcs-versioning',
+        type : 'boolean',
+        value : false,
+        description : 'Disable automatic libcamera library versioning with the git hash')
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index ce1f0f2f..6fd6f084 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -121,14 +121,27 @@ endforeach
 
 libcamera_sources += control_sources
 
-gen_version = meson.project_source_root() / 'utils' / 'gen-version.sh'
-
-# Use vcs_tag() and not configure_file() or run_command(), to ensure that the
-# version gets updated with every ninja build and not just at meson setup time.
-version_cpp = vcs_tag(command : [gen_version, meson.project_build_root(), meson.project_source_root()],
-                      input : 'version.cpp.in',
-                      output : 'version.cpp',
-                      fallback : meson.project_version())
+if get_option('disable-vcs-versioning')
+    cdata = configuration_data()
+    cdata.set('VCS_TAG', meson.project_version())
+
+    # For some reason using 'version.cpp' as output file works fine for generation
+    # but causes meson to delete the file before build. Any other file name
+    # seems to work.
+    version_cpp = configure_file(input : 'version.cpp.in',
+                                 output : 'version_static.cpp',
+                                 configuration : cdata)
+
+else
+    gen_version = meson.project_source_root() / 'utils' / 'gen-version.sh'
+
+    # Use vcs_tag() and not configure_file() or run_command(), to ensure that the
+    # version gets updated with every ninja build and not just at meson setup time.
+    version_cpp = vcs_tag(command : [gen_version, meson.project_build_root(), meson.project_source_root()],
+                          input : 'version.cpp.in',
+                          output : 'version.cpp',
+                          fallback : meson.project_version())
+endif
 
 libcamera_sources += version_cpp
 
