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

Make CMake module libs STATIC #1630

Merged
merged 1 commit into from
Jun 20, 2023
Merged

Conversation

deslaughter
Copy link
Collaborator

@deslaughter deslaughter commented Jun 15, 2023

This pull request is ready to be merged.

Feature or improvement description
This PR changes the CMakeLists.txt files in each module so that the module libraries are built as STATIC even if CMake is configured with -DBUILD_SHARED_LIBS=ON. Interface libraries (C-Bindings) and openfastlib are always built as shared libraries so this change will not affect downstream users. This option is part of CMake: BUILD_SHARED_LIBS

Impacted areas of the software
CMakeLists.txt files of all modules

Additional supporting information
This change arose from a problem installing WEIS which built OpenFAST with -DBUILD_SHARED_LIBS=ON. At one point, the only way to build openfastlib as a shared library was to set -DBUILD_SHARED_LIBS=ON. This library is currently always built as shared but many users still set BUILD_SHARED_LIBS=ON which causes all module libraries to be created as shared libraries so they are dynamically loaded at run time. This commit changes the CMakeLists.txt files to build all module libs as STATIC regardless of how BUILD_SHARED_LIBS is set. As a result, all module libraries will be statically linked into openfast, openfastlib and FAST.Farm which should improve performance and reduce complexity. This also prevents a problem with building the Simulink MEX file which wouldn't work if BUILD_SHARED_LIBS=ON.

In the past, the only way to build openfastlib as a shared library
was to set -DBUILD_SHARED=ON. This library is now always built as shared
but many users still set BUILD_SHARED which causes all module libraries
to be created as shared which means that all must be dynamically loaded
at run time. This commit changes the CMakeLists.txt files to build all
module libs as STATIC regardless of BUILD_SHARED. This means that all
module libraries will be statically linked into openfast, openfastlib
and FAST.Farm which should improve performance and reduce complexity
@andrew-platt
Copy link
Collaborator

Should we get rid of the -DBUILD_SHARED=ON flag, or is it still used somewhere?

@deslaughter
Copy link
Collaborator Author

@andrew-platt , BUILD_SHARED_LIBS is a CMake option, https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html, which it looks like is duplicated in the main CMakeLists.txt file. So it could still be set even if it was removed. In this PR all the libraries except openfastcpplib are set to SHARED or STATIC. I wasn't sure which way that library should be built, though I expect it needs to be SHARED for the downstream applications. I'm open to removing it and seeing if it causes any issues. Let me know what you think.

@deslaughter
Copy link
Collaborator Author

I've decided to leave this PR as is and revisit removing the BUILD_SHARED_LIBS option from the main CMakeLists.txt file in the future.

@andrew-platt andrew-platt merged commit e182063 into OpenFAST:dev Jun 20, 2023
@deslaughter deslaughter deleted the f/cmake-static branch June 20, 2023 16:28
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