From bf89cedd88eef94b9e45ebf7a0a43574a1e4a16a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 24 Apr 2019 14:08:32 +0200 Subject: [PATCH] fix compilation of static/dynamic files on macOS --- src/DynamicModel.cc | 15 +++++++++++++-- src/StaticModel.cc | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index f9c4665d..c69aee76 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -1720,8 +1720,14 @@ DynamicModel::writeDynamicCFile(const string &basename, const int order) const if (external_functions_table.get_total_number_of_unique_model_block_external_functions()) // External Matlab function, implies Dynamic function will call mex - mDynamicModelFile << "#include " << endl // For MATLAB ≤ R2011a - << R"(#include "mex.h")" << endl; + mDynamicModelFile +#ifndef __APPLE__ + << "#include " << endl // For MATLAB ≤ R2011a +#else + << "typedef uint_least16_t char16_t;" << endl + << "typedef uint_least32_t char32_t;" << endl // uchar.h does not exist on macOS +#endif + << R"(#include "mex.h")" << endl; mDynamicModelFile << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl; @@ -1757,7 +1763,12 @@ DynamicModel::writeDynamicCFile(const string &basename, const int order) const << " */" << endl << endl << "#include " << endl +#ifndef __APPLE__ << "#include " << endl // For MATLAB ≤ R2011a +#else + << "typedef uint_least16_t char16_t;" << endl + << "typedef uint_least32_t char32_t;" << endl // uchar.h does not exist on macOS +#endif << R"(#include "mex.h")" << endl << endl << "void dynamic_resid_tt(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);" << endl diff --git a/src/StaticModel.cc b/src/StaticModel.cc index 99949fd2..ccc97562 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -1952,8 +1952,14 @@ StaticModel::writeStaticCFile(const string &basename) const if (external_functions_table.get_total_number_of_unique_model_block_external_functions()) // External Matlab function, implies Static function will call mex - output << "#include " << endl // For MATLAB ≤ R2011a - << R"(#include "mex.h")" << endl; + output +#ifndef __APPLE__ + << "#include " << endl // For MATLAB ≤ R2011a +#else + << "typedef uint_least16_t char16_t;" << endl + << "typedef uint_least32_t char32_t;" << endl // uchar.h does not exist on macOS +#endif + << R"(#include "mex.h")" << endl; output << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl; @@ -1988,7 +1994,12 @@ StaticModel::writeStaticCFile(const string &basename) const << " */" << endl << endl << "#include " << endl +#ifndef __APPLE__ << "#include " << endl // For MATLAB ≤ R2011a +#else + << "typedef uint_least16_t char16_t;" << endl + << "typedef uint_least32_t char32_t;" << endl // uchar.h does not exist on macOS +#endif << R"(#include "mex.h")" << endl << endl << "void static_resid_tt(const double *y, const double *x, int nb_row_x, const double *params, double *T);" << endl