From 6af56f9de7c94f472ef43cbdcd35e84c0ed8cdf3 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 27 May 2022 19:06:30 -0400 Subject: [PATCH] FindNetCDF: imported targets interface prereq libs --- cmake/Modules/FindNetCDF.cmake | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmake/Modules/FindNetCDF.cmake b/cmake/Modules/FindNetCDF.cmake index 8f74bc8..0742dce 100644 --- a/cmake/Modules/FindNetCDF.cmake +++ b/cmake/Modules/FindNetCDF.cmake @@ -62,8 +62,6 @@ if(NOT NetCDF_C_LIBRARY) return() endif() -find_package(ZLIB) - set(CMAKE_REQUIRED_FLAGS) set(CMAKE_REQUIRED_INCLUDES ${NetCDF_C_INCLUDE_DIR}) @@ -72,10 +70,7 @@ if(ZLIB_FOUND) list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARIES}) endif() -list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS}) - -find_package(Threads) -list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) +list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}) if(UNIX) list(APPEND CMAKE_REQUIRED_LIBRARIES m) @@ -149,6 +144,10 @@ endfunction(netcdf_fortran) #============================================================ # main program +find_package(ZLIB) +find_package(Threads) +# top scope so can be reused + netcdf_c() set(_ncdf_req ${NetCDF_C_LIBRARY}) @@ -182,6 +181,7 @@ if(NetCDF_FOUND) ) target_link_libraries(NetCDF::NetCDF_C INTERFACE + $<$:${ZLIB_LIBRARIES}> ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} $<$:m> @@ -199,6 +199,7 @@ if(NetCDF_FOUND) ) target_link_libraries(NetCDF::NetCDF_Fortran INTERFACE + $<$:${ZLIB_LIBRARIES}> ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} $<$:m>