Skip to content

Commit

Permalink
FindNetCDF: imported targets interface prereq libs
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 27, 2022
1 parent 5a0508c commit 6af56f9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cmake/Modules/FindNetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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)
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -182,6 +181,7 @@ if(NetCDF_FOUND)
)

target_link_libraries(NetCDF::NetCDF_C INTERFACE
$<$<BOOL:${ZLIB_FOUND}>:${ZLIB_LIBRARIES}>
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
$<$<BOOL:${UNIX}>:m>
Expand All @@ -199,6 +199,7 @@ if(NetCDF_FOUND)
)

target_link_libraries(NetCDF::NetCDF_Fortran INTERFACE
$<$<BOOL:${ZLIB_FOUND}>:${ZLIB_LIBRARIES}>
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
$<$<BOOL:${UNIX}>:m>
Expand Down

0 comments on commit 6af56f9

Please sign in to comment.