diff --git a/src/meson.build b/src/meson.build
index 4dd87161f9049d43bf97c849b5f51b8c696672cc..4b8276920dc25765e4dee742f9d7df11225ba977 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -13,8 +13,13 @@ flex_src = flex_gen.process('macro/Tokenizer.ll', 'DynareFlex.ll')
 # flex is typically provided by the system of the build machine)
 if not cpp_compiler.has_header('FlexLexer.h')
   message('FlexLexer.h cannot be found by the compiler, it will be manually copied to the build directory')
+  copy = find_program('copy.py')
   fs = import('fs')
-  flexlexer_h = fs.copyfile(fs.parent(fs.parent(flex_exe.full_path())) / 'include' / 'FlexLexer.h', 'FlexLexer.h')
+  run_command(
+	  copy,
+    	  fs.parent(fs.parent(flex_exe.full_path())) / 'include' / 'FlexLexer.h', 
+    	  'FlexLexer.h'
+	  )
 else
   flexlexer_h = []
 endif