Skip to content

Could our long nightmare with finding netcdf with cmake be nearly over??? #663

@jgfouca

Description

@jgfouca

I'm trying to build scorpio on a generic linux machine (ubuntu). I have installed the various netcdf packages with apt-get. My package manager did install a file that would allow a CMake user to do find_package(netCDF ...):

/usr/lib/x86_64-linux-gnu/cmake/netCDF/netCDFConfig.cmake

I tested this with a simple program and it seems to work:

find_package(netCDF REQUIRED C)

# Add an executable target
add_executable(my_netcdf_app main.c)

# Link the NetCDF library to the executable
# The netCDF::netcdf target is an imported target defined by find_package(netCDF)
target_link_libraries(my_netcdf_app PRIVATE netCDF::netcdf)

The version of netcdf that I have is 4.8.1. I don't know when proper CMake support was finally added. AI is telling me this support was added in 4.3, which is older than our minimum required version, so perhaps this is a feature we can rely on? If not, it might be worth bumping the minimum netcdf to something newer just to avoid dealing with the current hellscape of netcdf integration with our cmake projects.

As I understand it, most of E3SM is currently relying on scorpio to find the netcdf cmake package. Due to historical lack of a reliable find module for netcdf, scorpio supplies its own module scorpio/cmake/FindNetCDF.cmake. We have used various homegrown modules over the years, all of which use "old-school" cmake style the predates object-oriented targets.

I will note that I currently cannot build eamxx/scorpio on my generic linux machine due to the scorpio FindNetCDF not finding netcdf. I can't even force it to use the module that my package manager gave me due to the capitalization being different NetCDF vs. netCDF (we also have NETCDF in many places as well, so three different ways to capitalize "netcdf", what fun!).

CMake Error at /home/jfoucar/E3SM/externals/scorpio/src/clib/CMakeLists.txt:245 (message):
  Could not find PnetCDF and NetCDF libraries.  SCORPIO requires PnetCDF
  and/or NetCDF C libraries

I think it would be great for the project to finally move past the era of home-rolled find modules for netcdf, so I have marked this as "high priority". Feel free to overrule me.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions