Skip to content

Commit 6af56f9

Browse files
committed
FindNetCDF: imported targets interface prereq libs
1 parent 5a0508c commit 6af56f9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cmake/Modules/FindNetCDF.cmake

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ if(NOT NetCDF_C_LIBRARY)
6262
return()
6363
endif()
6464

65-
find_package(ZLIB)
66-
6765
set(CMAKE_REQUIRED_FLAGS)
6866
set(CMAKE_REQUIRED_INCLUDES ${NetCDF_C_INCLUDE_DIR})
6967

@@ -72,10 +70,7 @@ if(ZLIB_FOUND)
7270
list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARIES})
7371
endif()
7472

75-
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
76-
77-
find_package(Threads)
78-
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
73+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
7974

8075
if(UNIX)
8176
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
@@ -149,6 +144,10 @@ endfunction(netcdf_fortran)
149144
#============================================================
150145
# main program
151146

147+
find_package(ZLIB)
148+
find_package(Threads)
149+
# top scope so can be reused
150+
152151
netcdf_c()
153152

154153
set(_ncdf_req ${NetCDF_C_LIBRARY})
@@ -182,6 +181,7 @@ if(NetCDF_FOUND)
182181
)
183182

184183
target_link_libraries(NetCDF::NetCDF_C INTERFACE
184+
$<$<BOOL:${ZLIB_FOUND}>:${ZLIB_LIBRARIES}>
185185
${CMAKE_THREAD_LIBS_INIT}
186186
${CMAKE_DL_LIBS}
187187
$<$<BOOL:${UNIX}>:m>
@@ -199,6 +199,7 @@ if(NetCDF_FOUND)
199199
)
200200

201201
target_link_libraries(NetCDF::NetCDF_Fortran INTERFACE
202+
$<$<BOOL:${ZLIB_FOUND}>:${ZLIB_LIBRARIES}>
202203
${CMAKE_THREAD_LIBS_INIT}
203204
${CMAKE_DL_LIBS}
204205
$<$<BOOL:${UNIX}>:m>

0 commit comments

Comments
 (0)