ecmwf / ecbuild

A CMake-based build system, consisting of a collection of CMake macros and functions that ease the managing of software build systems
https://ecbuild.readthedocs.io
Apache License 2.0
26 stars 25 forks source link

Cannot find NetCDF when components are installed in different places #46

Closed DJDavies2 closed 1 year ago

DJDavies2 commented 2 years ago

I have NetCDF C, Fortran and C++ components installed in different locations. Trying to link a package to multiple components (e.g. C and C++) results in this:

CMake Error at /home/h01/frwd/cylc-run/mi-be204/share/installs/ecbuild/share/ecbuild/cmake/ecbuild_log.cmake:190 (message):
  CRITICAL - Feature NETCDF cannot be enabled -- following required
  packages weren't found: NetCDF
Call Stack (most recent call first):
  /home/h01/frwd/cylc-run/mi-be204/share/installs/ecbuild/share/ecbuild/cmake/ecbuild_add_option.cmake:269 (ecbuild_critical)

where I am trying to find the NetCDF with this:

ecbuild_add_option( FEATURE NETCDF
                    DESCRIPTION "...."
                    REQUIRED_PACKAGES "NetCDF COMPONENTS C CXX" )

and invoking ecbuild with -DNETCDF_PATH=... and putting the /bin directories of the different NetCDF install dirs in $PATH for the *-config scripts.

DJDavies2 commented 2 years ago

I don't have permission to create a branch, but looking at FindNetCDF.cmake there is this:

  find_path(NetCDF_${_comp}_INCLUDE_DIR

    NAMES ${NetCDF_${_comp}_INCLUDE_NAME}
    DOC "netcdf ${_comp} include directory"
    HINTS ${_search_hints_${_comp}} ${_search_hints}
    PATH_SUFFIXES include ../../include
  )
  mark_as_advanced(NetCDF_${_comp}_INCLUDE_DIR)

  ## Find libraries for each component
  string( TOUPPER "${_comp}" _COMP )

  find_library(NetCDF_${_comp}_LIBRARY
    NAMES ${NetCDF_${_comp}_LIBRARY_NAME}
    DOC "netcdf ${_comp} library"
    HINTS ${_search_hints}                                 <-------- is this correct?
    PATH_SUFFIXES lib ../../lib
  )

From the code it looks like one should be able to pass component specific paths to ecbuild via -DNetCDF_<component>_ROOT and friends. However it doesn't find the library, perhaps because the component specific paths are not searched for the library? If I update the above to this:

  find_path(NetCDF_${_comp}_INCLUDE_DIR
    NAMES ${NetCDF_${_comp}_INCLUDE_NAME}
    DOC "netcdf ${_comp} include directory"
    HINTS ${_search_hints_${_comp}} ${_search_hints}
    PATH_SUFFIXES include ../../include
  )
  mark_as_advanced(NetCDF_${_comp}_INCLUDE_DIR)

  ## Find libraries for each component
  string( TOUPPER "${_comp}" _COMP )

  find_library(NetCDF_${_comp}_LIBRARY
    NAMES ${NetCDF_${_comp}_LIBRARY_NAME}
    DOC "netcdf ${_comp} library"
    HINTS ${_search_hints_${_comp}} ${_search_hints}
    PATH_SUFFIXES lib ../../lib
  )

then passing -DNetCDF_<component>_ROOT in addition to -DNETCDF_PATH does in fact work.

DJDavies2 commented 2 years ago

Sorry, I don't know how to get the code snippets to appear asis.

wdeconinck commented 2 years ago

Thanks for this issue report. We will fix it as soon as possible.

Sorry, I don't know how to get the code snippets to appear asis.

To get code snippets you have to use "single ticks". See https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks. I have edited your comments/description to add the ticks.

DJDavies2 commented 2 years ago

Thanks for this issue report. We will fix it as soon as possible.

Sorry, I don't know how to get the code snippets to appear asis.

To get code snippets you have to use "single ticks". See https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks. I have edited your comments/description to add the ticks.

Thanks.

wdeconinck commented 1 year ago

This was fixed with PR #47