Skip to content
Merged
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
31 changes: 23 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,32 @@ if (NetCDF_FOUND)
set(CPRNC_NETCDF_FORTRAN_LIB netcdf_cprnc)
endif()
else ()
message(STATUS "NetCDF was not found, falling back on pkg-config")
find_package(PkgConfig REQUIRED)
# If netcdf is not installed as a CMake pkg, the find_package above will fail,
# but netcdf may still be installed in the <PackageName>_ROOT folders
find_library(NetCDF_C_LIBRARIES netcdf HINTS ${NetCDF_C_ROOT} PATH_SUFFIXES lib lib64)
find_library(NetCDF_Fortran_LIBRARIES netcdff HINTS ${NetCDF_Fortran_ROOT} PATH_SUFFIXES lib lib64)
find_path(NetCDF_C_INCLUDE_DIRS netcdf.h HINTS ${NetCDF_C_ROOT} PATH_SUFFIXES include)
find_path(NetCDF_Fortran_INCLUDE_DIRS netcdf.mod HINTS ${NetCDF_Fortran_ROOT} PATH_SUFFIXES include)

if (NetCDF_C_LIBRARIES AND NetCDF_Fortran_LIBRARIES AND
NetCDF_C_INCLUDE_DIRS AND NetCDF_Fortran_INCLUDE_DIRS)
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)
else()
message(STATUS "NetCDF was not found, falling back on pkg-config")
find_package(PkgConfig REQUIRED)

#===== NetCDF =====
pkg_check_modules(NetCDF REQUIRED IMPORTED_TARGET netcdf)
#===== NetCDF =====
pkg_check_modules(NetCDF REQUIRED IMPORTED_TARGET netcdf)

#===== NetCDF-Fortran =====
pkg_check_modules(NetCDF_Fortran REQUIRED IMPORTED_TARGET netcdf-fortran)
#===== NetCDF-Fortran =====
pkg_check_modules(NetCDF_Fortran REQUIRED IMPORTED_TARGET netcdf-fortran)

set(CPRNC_NETCDF_FORTRAN_LIB PkgConfig::NetCDF_Fortran)
set(CPRNC_NETCDF_C_LIB PkgConfig::NetCDF)
set(CPRNC_NETCDF_FORTRAN_LIB PkgConfig::NetCDF_Fortran)
set(CPRNC_NETCDF_C_LIB PkgConfig::NetCDF)
endif()
endif()

add_executable (cprnc ${CPRNC_Fortran_SRCS} ${CPRNC_GenF90_SRCS})
Expand Down