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

Restructure netCDF find modules to use modern import target #2054

Merged
merged 15 commits into from
Oct 14, 2024

Conversation

islas
Copy link
Collaborator

@islas islas commented May 28, 2024

TYPE: enhancement

KEYWORDS: netCDF, cmake, compilation

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
The current iteration of the cmake build uses the old-style of finding modules. This limits the usability of transitive properties as well as the native netCDF cmake build which provide imported targets.

See https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules for more information on module writing.

Solution:
Augment the output of the provided find module to supply an imported target that fully describes the netCDF library. Additionally, in rewriting how targets in WRF reference netCDF remove unnecessary linking to the library. Ensure the provided import target and flags of the find module matches the netCDF[-Fortran].cmake.in outputs verbatim thus emulating the native netCDF build for additional robustness.

LIST OF MODIFIED FILES:
M CMakeLists.txt
M cmake/modules/FindnetCDF-Fortran.cmake
M cmake/modules/FindnetCDF.cmake
M external/CMakeLists.txt
M external/RSL_LITE/CMakeLists.txt
M external/atm_ocn/CMakeLists.txt
M external/esmf_time_f90/CMakeLists.txt
M external/fftpack/fftpack5/CMakeLists.txt
M external/io_adios2/CMakeLists.txt
M external/io_esmf/CMakeLists.txt
M external/io_grib1/CMakeLists.txt
M external/io_grib1/MEL_grib1/CMakeLists.txt
M external/io_grib1/WGRIB/CMakeLists.txt
M external/io_grib1/grib1_util/CMakeLists.txt
M external/io_grib2/bacio-1.3/CMakeLists.txt
M external/io_grib2/g2lib/CMakeLists.txt
M external/io_grib_share/CMakeLists.txt
M external/io_netcdf/CMakeLists.txt
M external/io_netcdfpar/CMakeLists.txt

RELEASE NOTE:
Restructure netCDF find modules to use modern import target

@islas islas requested review from a team as code owners May 28, 2024 18:24
@islas islas force-pushed the cmake-restructure-netCDF branch from b863a08 to c6d2c7e Compare August 6, 2024 02:31
@islas islas requested review from a team as code owners August 6, 2024 02:31
@islas islas changed the base branch from develop to release-v4.6.1 August 6, 2024 02:41
@islas
Copy link
Collaborator Author

islas commented Aug 6, 2024

Requires #2056 and #2053

@amstokely
Copy link
Collaborator

I think it would be a good idea to use ecbuild's FindNetCDF.cmake as it will allow WRF to be used with ecbuild, which is very commonly used for managing cmake packages in the atmosphere science community.

@islas
Copy link
Collaborator Author

islas commented Sep 3, 2024

I think it would be a good idea to use ecbuild's FindNetCDF.cmake as it will allow WRF to be used with ecbuild, which is very commonly used for managing cmake packages in the atmosphere science community.

I think we had discussed that module in an MPAS context. My take is that there are a few outstanding issues with that particular module that make it unattractive to use. Most notably it deviates from the UniData netCDF target names, making it unable to be a drop-in replacement with netCDF's native CMake builds - as well as introduces two "standard" naming conventions for netCDF in CMake. Additionally, it doesn't look like it queries the library features which affect WRF compilation.

@amstokely amstokely self-requested a review September 18, 2024 22:59
amstokely
amstokely previously approved these changes Sep 18, 2024
@islas islas force-pushed the cmake-restructure-netCDF branch from c6d2c7e to 9e6f9a4 Compare October 14, 2024 20:49
@amstokely amstokely self-requested a review October 14, 2024 21:08
@islas islas merged commit 1e96a7e into wrf-model:release-v4.6.1 Oct 14, 2024
0 of 2 checks passed
islas added a commit that referenced this pull request Oct 16, 2024
TYPE: bug fix

KEYWORDS: compilation, cmake, netcdf

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
PR #2054 changes the netCDF target linking for WRF targets generated
through CMake. When used with any other software relying on the package
config generated from `cmake/template/WRFConfig.cmake`, there must be a
way to find non-CMake supported packages like netCDF. WRF provides these
find modules in `<install dir>/share` but does not use them within its
own package config. WPS also has a FindnetCDF.cmake and
FindnetCDF-Fortran.cmake, but these use the classic variable approach
instead of an import target.

Thus, when building WPS referencing WRF with the changes of #2054, it
will use the WPS netCDF find modules instead of WRF's. This will result
in an error like:
```
CMake Error at /home/aislas/wrf-model/wrf/install/lib/cmake/WRF/WRFTargets.cmake:111 (set_target_properties):
  The link interface of target "WRF::io_netcdf" contains:

    netCDF::netcdff
```

Solution:
Adjust the generated package config file to use WRF's find modules and
give them precedence over WPS for WRF's imported targets specifically.
Additionally, move imported target inclusion to after dependencies have
been resolved so that WRF package finding precedence is used.

TESTS CONDUCTED: 
1. Tested with gcc/OpenMPI to build WRF and WPS (v4.6.0) together
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