Skip to content

Can't get recent versions of cprnc to build on my Mac due to problems finding netcdf #29

Description

@billsacks

On my Mac, where I have software installed via homebrew, I am having problems building cprnc with the CMake-based build.

cmake runs fine, but when I run make, I get:

/Users/sacks/cprnc/cprnc0/filestruct.F90:2:7:

    2 |   use netcdf
      |       1
Fatal Error: Cannot open module file 'netcdf.mod' for reading at (1): No such file or directory

Adding some debugging messages in the CMakeLists.txt, I see that I'm getting into this block (where NetCDF_FOUND is true but TARGET NetCDF::NetCDF_Fortran is false):

cprnc/CMakeLists.txt

Lines 84 to 88 in cfd4a76

# We used an old-school find netcdf module. Make the target here
add_library(netcdf_cprnc INTERFACE)
target_link_libraries(netcdf_cprnc INTERFACE ${NetCDF_Fortran_LIBRARIES};${NetCDF_C_LIBRARIES})
target_include_directories(netcdf_cprnc INTERFACE ${NetCDF_Fortran_INCLUDE_DIRS};${NetCDF_C_INCLUDE_DIRS})
set(CPRNC_NETCDF_FORTRAN_LIB netcdf_cprnc)

but the various variables there (e.g., NetCDF_Fortran_INCLUDE_DIRS) seem to be undefined.

In my CMakeCache.txt I see:

NetCDF_DIR:PATH=/opt/homebrew/lib/cmake/netCDF

and after the find_package, when I print the value of NetCDF_CONFIG, I see that it is /opt/homebrew/lib/cmake/netCDF/netCDFConfig.cmake.

The contents of that file are:

Contents of /opt/homebrew/lib/cmake/netCDF/netCDFConfig.cmake
# NetCDF Configuration Summary
#
# General
#

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was netCDFConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

set(NetCDFVersion "4.9.3")
set_and_check(netCDF_INSTALL_PREFIX "/opt/homebrew/Cellar/netcdf/4.9.3")
set_and_check(netCDF_INCLUDE_DIR "/opt/homebrew/Cellar/netcdf/4.9.3/include")
set_and_check(netCDF_LIB_DIR "/opt/homebrew/Cellar/netcdf/4.9.3/lib")
set(netCDF_LIBRARIES netCDF::netcdf)

# include target information
include("${CMAKE_CURRENT_LIST_DIR}/netCDFTargets.cmake")



# Compiling Options
#
set(netCDF_C_COMPILER "clang")
set(netCDF_C_COMPILER_FLAGS " -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG")
set(netCDF_C_CPP_FLAGS " ")
set(netCDF_LDFLAGS " ")
set(netCDF_AM_CFLAGS "")
set(netCDF_AM_CPPFLAGS "")
set(netCDF_AM_LDFLAGS "")
set(netCDF_SHARED yes)
set(netCDF_STATIC no)

# Features:
#
set(netCDF_HAS_NC2 yes)
set(netCDF_HAS_NC4 yes)
set(netCDF_HAS_HDF4 no)
set(netCDF_HAS_HDF5 yes)
set(netCDF_HAS_PNETCDF no)
set(netCDF_HAS_PARALLEL no)
set(netCDF_HAS_DAP yes)
set(netCDF_HAS_DAP2 yes)
set(netCDF_HAS_DAP4 yes)
set(netCDF_HAS_DISKLESS yes)
set(netCDF_HAS_MMAP yes)
if (netCDF_HAS_HDF4 OR netCDF_HAS_HDF5)
  include(CMakeFindDependencyMacro)
  find_dependency(HDF5)
endif ()

if (no)
  include(CMakeFindDependencyMacro)
  find_dependency(MPI  EXACT)
endif()

The last commit that works for me is f4979ab. This is before the changes in #23 (as well as the following changes in #25 ).

I don't understand CMake well enough to know where to go from here to try to fix this, but I'm happy to work with someone who understands this better. @jgfouca @bartgol @jedwards4b ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions