|
1 | 1 | %% INSTRUCTIONS |
2 | | -% This script is used to manually build a Simulink mex file which uses the openfastlib shared library (.dll, .so, .dylib). |
3 | | -% If you are building OpenFAST with CMake on linux or macOS or windows, you can automatically generate the mex file |
4 | | -% by specifying -DBUILD_OPENFAST_SIMULINK_API=ON when running cmake, you do not need to use this script. |
| 2 | +% This script is used to manually build a Simulink mex file on Windows with Visual Studio. It uses the openfastlib shared |
| 3 | +% library (.dll). |
5 | 4 | % |
6 | | -% Before running this script, you must have compiled OpenFAST for Simulink to create a DLL (i.e., a shared library like .so, .dylib, .lib, etc.). |
7 | | -% - If cmake was used, make sure the install directory is specified properly in the `installDir` variable below, |
8 | | -% and if using Windows, set `built_with_visualStudio` to false. |
| 5 | +% If you are using Windows and building with CMake, do not use this script. Instead use cmake to build the FAST_SFunc.mexXXXX directly. |
| 6 | +% |
| 7 | +% If you are not using Windows, do not use this script. Instead use cmake to build the FAST_SFunc.mexXXXX directly. |
| 8 | +% |
| 9 | +% Alternative building with CMAKE: |
| 10 | +% specify -DBUILD_OPENFAST_SIMULINK_API=ON when running cmake |
| 11 | +% - "make FAST_SFunc" will place the resulting mex file at <build-dir>/glue-codes/simulink/FAST_SFunc.mexXXXX |
| 12 | +% - "make install" will place the resulting mex file at install/bin/FAST_SFunc.mexXXXX |
| 13 | +% |
| 14 | +% |
| 15 | +% Before running this script, you must have compiled OpenFAST for Simulink to create a DLL (i.e., a shared library .lib). |
9 | 16 | % - If the Visual Studio Solution file contained in the vs-build directory was used to create the DLL on Windows, |
10 | 17 | % make sure `built_with_visualStudio` is set to true. |
11 | 18 | % - The name of the library that was generated must match the `libname` variable below |
12 | 19 | % and should be located in the directory specified by `libDir`. |
13 | 20 | % - The `includeDir` variable must specify the directory that contains the following header files: |
14 | | -% "FAST_Library.h", "OpenFOAM_Types.h", and "SuperController_Types.h" |
15 | | -% - The `outDir` variable indicates where the resulting mex file will reside. |
| 21 | +% "FAST_Library.h", "OpenFOAM_Types.h", "SuperController_Types.h", and "ExtLoadsDX_Types.h" |
16 | 22 | % |
17 | 23 | % Run `mex -setup` in Matlab to configure a C compiler if you have not already done so. |
18 | 24 |
|
19 | 25 | mexname = 'FAST_SFunc'; % base name of the resulting mex file |
20 | 26 |
|
21 | | -built_with_visualStudio = false; %if the libraries were built with cmake, set to false |
| 27 | +built_with_visualStudio = true; %if the libraries were built with cmake, set to false |
22 | 28 |
|
23 | 29 |
|
24 | 30 | if (ispc && built_with_visualStudio) |
|
42 | 48 | else |
43 | 49 | %% defaults for cmake builds: |
44 | 50 |
|
45 | | - if ( ismac ) % Apple MacOS |
46 | | - installDir = '../../../install'; |
47 | | - outDir = fullfile(installDir, 'lib'); |
48 | | - elseif ( ispc ) % Windows PC |
49 | | - installDir = '../../../install'; |
50 | | - outDir = fullfile(installDir, 'lib'); |
51 | | - % If there are shared libraries does it work for outDir to be the local directory? |
52 | | - else |
53 | | - installDir = '../../../install'; |
54 | | - outDir = '.'; |
55 | | - end |
| 51 | + fprintf( '\n----------------------------\n' ); |
| 52 | + fprintf( 'Do not use this script with Mac/Linux. Follow the CMake instructions at the top of the script instead.' ); |
| 53 | + fprintf( '\n----------------------------\n' ); |
56 | 54 |
|
57 | | - libDir = fullfile(installDir, 'lib'); |
58 | | - includeDir = fullfile(installDir, 'include'); |
59 | | - libName = 'openfastlib_mex'; |
60 | 55 | end |
61 | 56 |
|
62 | | -%% BUILD COMMAND |
63 | | -fprintf( '\n----------------------------\n' ); |
64 | | -fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] ); |
| 57 | + |
65 | 58 |
|
66 | 59 | if ispc () % Windows PC |
| 60 | + %% BUILD COMMAND |
| 61 | + fprintf( '\n----------------------------\n' ); |
| 62 | + fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] ); |
| 63 | + |
67 | 64 |
|
68 | 65 | mex('-largeArrayDims', ... |
69 | 66 | ... % '-v', ... %add this line for "verbose" output (for debugging) |
|
72 | 69 | ['-I' includeDir], ... |
73 | 70 | '-I../../../modules/supercontroller/src', ... % needed for visual studio builds to find "SuperController_Types.h" |
74 | 71 | '-I../../../modules/externalinflow/src', ... % needed for visual studio builds to find "ExternalInflow_Types.h" |
| 72 | + '-I../../../modules/extloads/src', ... % needed for visual studio builds to find "ExtLoadsDX_Types.h" |
75 | 73 | '-outdir', outDir, ... |
76 | 74 | ['COMPFLAGS=$COMPFLAGS -MT -DS_FUNCTION_NAME=' mexname], ... |
77 | 75 | '-output', mexname, ... |
78 | 76 | 'FAST_SFunc.c'); |
79 | 77 |
|
80 | | -else % mac/unix |
81 | | - |
82 | | - mex('-largeArrayDims', ... |
83 | | - ... '-v', ... %add this line for "verbose" output (for debugging) |
84 | | - ['-L', libDir], ... |
85 | | - ['-l', libName], ... |
86 | | - '-lgfortran', ... |
87 | | - '-lquadmath', ... |
88 | | - '-llapack', ... |
89 | | - '-lblas', ... |
90 | | - '-ldl', ... |
91 | | - ['-I', includeDir], ... |
92 | | - '-outdir', outDir, ... |
93 | | - ['CFLAGS=$CFLAGS -DS_FUNCTION_NAME=' mexname], ... |
94 | | - ... ['CXXFLAGS=$CXXFLAGS -DS_FUNCTION_NAME=' mexname], ... |
95 | | - '-output', mexname, ... |
96 | | - 'FAST_SFunc.c'); |
97 | | - |
98 | 78 | end |
0 commit comments