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

CMake Better nf-config libdir detection #2161

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmake/modules/FindnetCDF-Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ else()
endforeach()


# A bug in previous netcdf-fortran cmake builds, extract from flibs
string( REGEX MATCH "^-L([^ ]*)" netCDF-Fortran_LIBRARY_LINK_LOCATION ${netCDF-Fortran_FLIBS} )
set( netCDF-Fortran_LIBRARY_DIR ${CMAKE_MATCH_1} )
# A bug in previous netcdf-fortran cmake builds, extract from prefix, flibs, or include in priority order
if( NOT "${netCDF-Fortran_PREFIX}" STREQUAL "" )
# fall back to the prefix
set( netCDF-Fortran_LIBRARY_DIR ${netCDF-Fortran_PREFIX} )
elseif ( NOT "${netCDF-Fortran_FLIBS}" STREQUAL "" )
# flibs valid
string( REGEX MATCH "^-L([^ ]*)" netCDF-Fortran_LIBRARY_LINK_LOCATION ${netCDF-Fortran_FLIBS} )
set( netCDF-Fortran_LIBRARY_DIR ${CMAKE_MATCH_1} )
else()
# fall back EVEN further to include
string( REGEX MATCH "^([^ ]*)/include" netCDF-Fortran_LIBRARY_LINK_LOCATION ${netCDF-Fortran_INCLUDE_DIR} )
set( netCDF-Fortran_LIBRARY_DIR ${CMAKE_MATCH_1} )
endif()

set( netCDF-Fortran_DEFINITIONS )
set( netCDF-Fortran_LIBRARIES
Expand All @@ -99,6 +109,9 @@ else()
netcdff
PATHS ${netCDF-Fortran_LIBRARY_DIR}
NO_DEFAULT_PATH
PATH_SUFFIXES
lib/
lib64/
)
endif()

Expand All @@ -110,6 +123,7 @@ find_package_handle_standard_args(
netCDF-Fortran
FOUND_VAR netCDF-Fortran_FOUND
REQUIRED_VARS
netCDF-Fortran_LIBRARY
netCDF-Fortran_INCLUDE_DIRS
netCDF-Fortran_LIBRARIES
netCDF-Fortran_VERSION
Expand Down