Skip to content

Commit c04bf08

Browse files
authored
Merge pull request #2621 from andrew-platt/b/SFunc_build
Bugfix: Update create_FAST_SFunc.m for Windows, update docs on Simulink MEX building
2 parents a94481c + 72bc705 commit c04bf08

File tree

3 files changed

+55
-47
lines changed

3 files changed

+55
-47
lines changed

docs/source/install/index.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,19 +460,26 @@ The CMake options specific to OpenFAST and their default settings are:
460460
BUILD_DOCUMENTATION - Build documentation (Default: OFF)
461461
BUILD_FASTFARM - Enable FAST.Farm capabilities (Default: OFF)
462462
BUILD_OPENFAST_CPP_API - Enable building OpenFAST - C++ API (Default: OFF)
463+
BUILD_OPENFAST_CPP_DRIVER - Enable building OpenFAST C++ driver using C++ CFD API (Default: OFF)
464+
BUILD_OPENFAST_LIB_DRIVER - Enable building OpenFAST driver using C++ Library API (Default: OFF)
463465
BUILD_OPENFAST_SIMULINK_API - Enable building OpenFAST for use with Simulink (Default: OFF)
464466
BUILD_SHARED_LIBS - Enable building shared libraries (Default: OFF)
465467
BUILD_TESTING - Build the testing tree (Default: OFF)
468+
BUILD_UNIT_TESTING - Enable unit testing (Default: ON)
466469
CMAKE_BUILD_TYPE - Choose the build type: Debug Release (Default: Release)
467470
CMAKE_Fortran_MODULE_DIRECTORY - Set the Fortran Modules directory
468471
CMAKE_INSTALL_PREFIX - Install path prefix, prepended onto install directories.
469-
CODECOV - Enable infrastructure for measuring code coverage (Default: OFF)
472+
CMAKE_MACOSX_RPATH - Use RPATH runtime linking (Default: ON)
473+
CODECOVERAGE - Enable infrastructure for measuring code coverage (Default: OFF)
470474
DOUBLE_PRECISION - Treat REAL as double precision (Default: ON)
471475
FPE_TRAP_ENABLED - Enable Floating Point Exception (FPE) trap in compiler options (Default: OFF)
472476
GENERATE_TYPES - Use the openfast-registry to autogenerate types modules (Default: OFF)
473477
OPENMP - Enable OpenMP support (Default: OFF)
474-
ORCA_DLL_LOAD - Enable OrcaFlex library load (Default: OFF)
478+
ORCA_DLL_LOAD - Enable OrcaFlex library load (Default: ON)
475479
USE_DLL_INTERFACE - Enable runtime loading of dynamic libraries (Default: ON)
480+
USE_LOCAL_STATIC_LAPACK - Enable downloading and building static LAPACK and BLAS libs (Default: OFF)
481+
VARIABLE_TRACKING - Enables variable tracking for better runtime debugging output. May increase compile time. Valid only for GNU. (Defualt: ON)
482+
476483

477484
Additional system-specific options may exist for a given system, but those
478485
should not impact the OpenFAST configuration. As mentioned above, the
@@ -754,6 +761,27 @@ through the Intel oneAPI distributions.
754761

755762
.. _installation_appendix:
756763

764+
Simulink
765+
~~~~~~~~
766+
To build the MEX function for coupling OpenFAST into Simulink, there are two
767+
options depending on platform.
768+
769+
Windows with Visual Studio
770+
--------------------------
771+
For Windows, build with the `Release_Matlab` option from the Visual Studio
772+
project in `vs-build/FAST/FAST.sln`. Then run
773+
`glue-codes/simulink/src/create_FAST_SFunc.m` from MATLAB (instructions at the
774+
top of this file).
775+
776+
CMake
777+
-----
778+
For CMake builds on all platforms, enable the `-DBUILD_OPENFAST_SIMULINK_API=On`
779+
option in CMake and build the `FAST_SFunc` target. This will place the
780+
resulting `FAST_SFunc.mexXXXX` in
781+
`<build-dir>/glue-codes/simulink/FAST_SFunc.mexXXXX` (and in the install
782+
directory at `install/bin/FAST_SFunc.mexXXXX` if `make install` was called).
783+
784+
757785
Appendix
758786
~~~~~~~~
759787
The following are additional methods for installation which may not be fully

glue-codes/simulink/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ endif()
8484
install(TARGETS FAST_SFunc
8585
EXPORT "${CMAKE_PROJECT_NAME}Libraries"
8686
RUNTIME DESTINATION bin
87-
LIBRARY DESTINATION lib
87+
LIBRARY DESTINATION bin
8888
ARCHIVE DESTINATION lib
8989
)
Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
%% 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).
54
%
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).
916
% - If the Visual Studio Solution file contained in the vs-build directory was used to create the DLL on Windows,
1017
% make sure `built_with_visualStudio` is set to true.
1118
% - The name of the library that was generated must match the `libname` variable below
1219
% and should be located in the directory specified by `libDir`.
1320
% - 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"
1622
%
1723
% Run `mex -setup` in Matlab to configure a C compiler if you have not already done so.
1824

1925
mexname = 'FAST_SFunc'; % base name of the resulting mex file
2026

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
2228

2329

2430
if (ispc && built_with_visualStudio)
@@ -42,28 +48,19 @@
4248
else
4349
%% defaults for cmake builds:
4450

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' );
5654

57-
libDir = fullfile(installDir, 'lib');
58-
includeDir = fullfile(installDir, 'include');
59-
libName = 'openfastlib_mex';
6055
end
6156

62-
%% BUILD COMMAND
63-
fprintf( '\n----------------------------\n' );
64-
fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] );
57+
6558

6659
if ispc () % Windows PC
60+
%% BUILD COMMAND
61+
fprintf( '\n----------------------------\n' );
62+
fprintf( 'Creating %s\n\n', [outDir filesep mexname '.' mexext] );
63+
6764

6865
mex('-largeArrayDims', ...
6966
... % '-v', ... %add this line for "verbose" output (for debugging)
@@ -72,27 +69,10 @@
7269
['-I' includeDir], ...
7370
'-I../../../modules/supercontroller/src', ... % needed for visual studio builds to find "SuperController_Types.h"
7471
'-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"
7573
'-outdir', outDir, ...
7674
['COMPFLAGS=$COMPFLAGS -MT -DS_FUNCTION_NAME=' mexname], ...
7775
'-output', mexname, ...
7876
'FAST_SFunc.c');
7977

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-
9878
end

0 commit comments

Comments
 (0)