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

Us nc-config as intended for static NetCDF #60

Merged
merged 3 commits into from
Mar 14, 2022

Conversation

climbfuji
Copy link
Collaborator

The way we have used FindNetCDF.cmake for static libraries is not how it is intended, I think. nc-config accepts a number of flags, for example --libs to obtain the NetCDF library for linking. In addition to --libs, one can pass --static, which, according to the nc-config documentation and the code in nc-config itself, adds the additional static libraries that are required for static linking (called libsprivate in nc-config).

The current FindNetCDF.cmake does not use --static anywhere in the macro. Instead, it relies on the static flags being part of the default --libs result. This is incorrect. Consider a case where both the dynamic and the static library are being built, and the application decides which one to use. In this case, --libs should only return the libraries required for dynamic linking, and --libs --static the ones for static linking. This is the case on gaea with the new spack-stack, and I've tested it successfully there with the ufs-weather-model (which looks for the static libraries).

Note 1. The --static line does not contain the paths to the static libraries. Is this because of how we call ./configure? It's not a problem as long as we load the modules for the dependencies (zlib, hdf5, parallel-netcdf, ...) which we do anyway as part of our codes, and which get loaded automatically when using the spack-stack modules.

Note 2. I've added a few formatting updates that will allow us to make the FindNetCDF.cmake identical between CMakeModules (EMC) and jedi-cmake (JCSDA). In the long run - outside of the scope of this PR - we should consider consolidating the cmake modules into one repository that gets built as part of spack-stack. (Currently, jedi-cmake is, but it contains more stuff and I think we should reorganize this).

@@ -183,7 +194,7 @@ else()
endif()

if(NetCDF_PARALLEL)
find_package(MPI)
find_package(MPI REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had an issue with requiring MPI here, so we made it optional.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the problem? Seems weird to make it optional when you are using a parallel build of netcdf.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#50

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright ... I'll change it back. Thanks for the explanation.

Comment on lines +174 to +183
function(netcdf_config2 exec flag1 flag2 output_var)
set(${output_var} False PARENT_SCOPE)
if( exec )
execute_process( COMMAND ${exec} ${flag1} ${flag2} RESULT_VARIABLE _ret OUTPUT_VARIABLE _val)
if( _ret EQUAL 0 )
string( STRIP ${_val} _val )
set( ${output_var} ${_val} PARENT_SCOPE )
endif()
endif()
endfunction()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can netcdf_config be replaced by this? If not, a more descriptive name would be useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying this now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, doesn't work:

CMake Error at CMakeModules/Modules/FindNetCDF.cmake:186 (netcdf_config):
  netcdf_config Function invoked with incorrect arguments for function named:
  netcdf_config
Call Stack (most recent call first):
  CMakeLists.txt:111 (find_package)

So I'll add a one-line documentation above each of the two functions. There is a generic option to have optional arguments, but the syntax looks cryptic and it would require if statements inside the functions.

@climbfuji climbfuji marked this pull request as ready for review March 14, 2022 15:24
@climbfuji climbfuji requested a review from kgerheiser March 14, 2022 15:24
@kgerheiser kgerheiser merged commit 0065b18 into NOAA-EMC:develop Mar 14, 2022
@edwardhartnett
Copy link

This is a really good change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants