From 7e1563fdbbdacbb7ec2b0ea57bb754f0911aa6ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 18 Sep 2020 15:00:00 +0200
Subject: [PATCH] Allow 'use_dll' option to be specified on the command line

Ref. Enteprise/dynare#4
---
 src/DynareMain.cc | 10 +++++++++-
 src/ModFile.hh    |  3 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index a03a386c..6715c6ac 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -57,7 +57,7 @@ usage()
        << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=matlab|julia]"
        << " [params_derivs_order=0|1|2] [transform_unary_ops] [exclude_eqs=<equation_tag_list_or_file>] [include_eqs=<equation_tag_list_or_file>]"
        << " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]"
-       << " [mexext=<extension>] [matlabroot=<path>] [onlymodel] [notime]"
+       << " [mexext=<extension>] [matlabroot=<path>] [onlymodel] [notime] [use_dll]"
        << endl;
   exit(EXIT_FAILURE);
 }
@@ -166,6 +166,7 @@ main(int argc, char **argv)
   dynareroot = dynareroot.parent_path();
   dynareroot = dynareroot / ".." / "..";
   bool onlymodel = false;
+  bool use_dll = false;
 
   for (auto s : options)
     {
@@ -400,6 +401,8 @@ main(int argc, char **argv)
         onlymodel = true;
       else if (s == "gui")
         gui = true;
+      else if (s == "use_dll")
+        use_dll = true;
       else
         {
           cerr << "Unknown option: " << s << endl;
@@ -454,6 +457,11 @@ main(int argc, char **argv)
 
   // Do parsing and construct internal representation of mod file
   unique_ptr<ModFile> mod_file = p.parse(macro_output, debug);
+
+  // Handle use_dll option specified on the command line
+  if (use_dll)
+    mod_file->use_dll = true;
+
   if (json == JsonOutputPointType::parsing)
     mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
 
diff --git a/src/ModFile.hh b/src/ModFile.hh
index 16a3b3d2..fbcaaa13 100644
--- a/src/ModFile.hh
+++ b/src/ModFile.hh
@@ -85,7 +85,8 @@ public:
   //! Is the model stored in bytecode format (bytecode=true) or in a M-file (bytecode=false)
   bool bytecode{false};
 
-  //! Is the model stored in a MEX file ? (option "use_dll" of "model")
+  /*! Is the model stored in a MEX file ? (option “use_dll”, either in the
+    “model” block or on the preprocessor command line) */
   bool use_dll{false};
 
   //! Is the static model have to computed (no_static=false) or not (no_static=true). Option of 'model'
-- 
GitLab