Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Modernize CMake, remove object libraries, build Simulink MEX #1555

Merged
merged 5 commits into from
May 4, 2023

Conversation

deslaughter
Copy link
Collaborator

This pull request is ready to be merged.

Related issue, if one exists
This PR addresses issue #1551 where compilation fails on an M1 mac.

Impacted areas of the software

  • All CMakeLists.txt files
  • automated-dev-tests.yml - updated to Ubuntu 22.04 and gcc-12
  • CMake 3.15 is needed (which is about 4 years old)

Additional supporting information
This PR, #1535, and #1530 address issues created by PR #1010 which used CMake object libraries to statically link the Simulink MEX file. These object libraries created a lot of complexity in the build system and made the module dependencies confusing. This PR removes the object libraries and uses CMake's matlab_add_mex function (https://cmake.org/cmake/help/latest/module/FindMatlab.html#command:matlab_add_mex) to build the MEX file directly, instead of relying on create_FAST_SFunc.m. The MEX file links against openfast_prelib and recompiles parts of openfast_postlib with COMPILE_SIMULINK defined. This these libraries are statically linked, it should solve the problems that PR #1010 were originally trying to solve. It also makes the process of build the MEX file easier when using CMake. create_FAST_SFunc.m should still be used when building with Visual Studio on Windows.

Various other improvements were made to the CMake build system:

  • use target_include_directories to specify includes per target
  • use target_compile_definitions to reduce the scope of preprocessor defines
  • use target PUBLIC_HEADER property to define installation of header files
  • remove FindMatlab.cmake since it's included in CMake
  • consolidate OpenMP flag management into main CMakeLists.txt

Test results, if applicable
All tests are passing when compiled with gfortran and ifort

This commit undoes most of the changes in PR OpenFAST#1010 which introduced
object libraries into the build system to produce a statically linked
MEX file for Simulink. The Object Libraries were somewhat complex and
didn't behave the same as normal libraries. While trying to debug a
compilation issue on an M1 mac the CMake `matlab_add_mex` function was
discovered which could build a static mex file within CMake. The build
system was reworked to use this feature.
There was some duplication in processing of OpenMP flags between
FAST.Farm and openfastcpp which caused compile issues. Finding the
package and adding flags were moved to the main CMakeLists.txt. This also sets
the LINKER_LANGUAGE to Fortran for openfastlib and fixes a typo in the
VersionInfo CMake file.
Also set number of parallel builds using CMAKE_BUILD_PARALLEL_LEVEL
environment variable instead of specifying -j.
Total action run time reduced by 10-15 minutes
@deslaughter deslaughter changed the base branch from rc-3.5.0 to dev May 4, 2023 17:47
@deslaughter deslaughter merged commit bb72d26 into OpenFAST:dev May 4, 2023
@deslaughter deslaughter deleted the bug/cmake-undef branch May 4, 2023 18:39
deslaughter added a commit that referenced this pull request May 9, 2023
The module name was incorrectly changed to `versioninfolib` when the
CMakeLists.txt files were revised in PR #1555.
@andrew-platt andrew-platt mentioned this pull request May 12, 2023
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants