Copying files from WRF build, unfortunately
[WPS.git] / cmake / modules / FindnetCDF.cmake
blobf9051f0792cfec2adfd10caef75e7bf2b985293c
1 # Find netcdf
2 # Eventually replace with netCDF's actual config if using that
3 # Once found this file will define:
4 #  netCDF_FOUND - System has netcdf
5 #  netCDF_INCLUDE_DIRS - The netcdf include directories
6 #  netCDF_LIBRARIES - The libraries needed to use netcdf
7 #  netCDF_DEFINITIONS - Compiler switches required for using netcdf
9 # list( REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} )
10 # find_package( netCDF )
11 # list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} )
13 # Use nc-config
14 find_program( 
15                 NETCDF_PROGRAM
16                 nc-config
17                 QUIET
18                 )
20 if ( ${NETCDF_PROGRAM} MATCHES "-NOTFOUND$" )
21   message( STATUS "No nc-config found" )
22 else()
23   message( STATUS "Found NETCDF_PROGRAM : ${NETCDF_PROGRAM}" )
25   execute_process( COMMAND ${NETCDF_PROGRAM} --includedir   OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_INCLUDE_DIR )
26   execute_process( COMMAND ${NETCDF_PROGRAM} --libdir       OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_LIBRARY_DIR )
27   execute_process( COMMAND ${NETCDF_PROGRAM} --prefix       OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_PREFIX )
28   execute_process( COMMAND ${NETCDF_PROGRAM} --libs         OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_CLIBS   )
29   execute_process( COMMAND ${NETCDF_PROGRAM} --cxx4libs     OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_CXXLIBS )
30   execute_process( COMMAND ${NETCDF_PROGRAM} --flibs        OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_FLIBS   )
31   execute_process( COMMAND ${NETCDF_PROGRAM} --version      OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_VERSION_RAW )
32   execute_process( COMMAND ${NETCDF_PROGRAM} --has-nc4      OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_NC4_YES )
33   execute_process( COMMAND ${NETCDF_PROGRAM} --has-pnetcdf  OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_PNETCDF_YES )
34   execute_process( COMMAND ${NETCDF_PROGRAM} --has-parallel OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE netCDF_PARALLEL_YES )
37   # Sanitize version
38   string( REPLACE " " ";" netCDF_VERSION_LIST ${netCDF_VERSION_RAW} )
39   list( GET netCDF_VERSION_LIST -1 netCDF_VERSION )
41   # Convert to YES/NO - Note cannot be generator expression if you want to use it during configuration time
42   string( TOUPPER ${netCDF_NC4_YES}      netCDF_NC4      )
43   string( TOUPPER ${netCDF_PNETCDF_YES}  netCDF_PNETCDF  )
44   string( TOUPPER ${netCDF_PARALLEL_YES} netCDF_PARALLEL )
46   set( netCDF_DEFINITIONS  )
48   set( netCDF_LIBRARIES
49       $<$<LINK_LANGUAGE:C>:${netCDF_CLIBS}>
50       $<$<LINK_LANGUAGE:CXX>:${netCDF_CXXLIBS}> 
51       $<$<LINK_LANGUAGE:Fortran>:${netCDF_FLIBS}>
52       )
53   set( netCDF_INCLUDE_DIRS ${netCDF_INCLUDE_DIR} )
54 endif()
56 find_package( PkgConfig )
58 include(FindPackageHandleStandardArgs)
60 # handle the QUIETLY and REQUIRED arguments and set netCDF_FOUND to TRUE
61 # if all listed variables are TRUE
62 find_package_handle_standard_args( netCDF  DEFAULT_MSG
63                                   netCDF_INCLUDE_DIRS
64                                   netCDF_LIBRARY_DIR
65                                   netCDF_CLIBS
66                                   netCDF_CXXLIBS
67                                   netCDF_FLIBS
68                                   netCDF_VERSION
69                                   )
71 mark_as_advanced( netCDF_CLIBS netCDF_CXXLIBS netCDF_FLIBS netCDF_PREFIX netCDF_LIBRARY_DIR )