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} )
20 if ( ${NETCDF_PROGRAM} MATCHES "-NOTFOUND$" )
21 message( STATUS "No nc-config found" )
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 )
36 # check for large file support
37 find_file( netCDF_INCLUDE_FILE netcdf.inc ${netCDF_INCLUDE_DIR} )
38 file( READ ${netCDF_INCLUDE_FILE} netCDF_INCLUDE_FILE_STR )
39 string( FIND "${netCDF_INCLUDE_FILE_STR}" "nf_format_64bit" netCDF_LARGE_FILE_SUPPORT_FOUND )
40 if ( ${netCDF_LARGE_FILE_SUPPORT_FOUND} EQUAL -1 )
41 set( netCDF_LARGE_FILE_SUPPORT "NO" )
43 set( netCDF_LARGE_FILE_SUPPORT "YES" )
47 string( REPLACE " " ";" netCDF_VERSION_LIST ${netCDF_VERSION_RAW} )
48 list( GET netCDF_VERSION_LIST -1 netCDF_VERSION )
50 # Convert to YES/NO - Note cannot be generator expression if you want to use it during configuration time
51 string( TOUPPER ${netCDF_NC4_YES} netCDF_NC4 )
52 string( TOUPPER ${netCDF_PNETCDF_YES} netCDF_PNETCDF )
53 string( TOUPPER ${netCDF_PARALLEL_YES} netCDF_PARALLEL )
55 set( netCDF_DEFINITIONS )
58 $<$<LINK_LANGUAGE:C>:${netCDF_CLIBS}>
59 $<$<LINK_LANGUAGE:CXX>:${netCDF_CXXLIBS}>
60 $<$<LINK_LANGUAGE:Fortran>:${netCDF_FLIBS}>
62 set( netCDF_INCLUDE_DIRS ${netCDF_INCLUDE_DIR} )
65 find_package( PkgConfig )
67 include(FindPackageHandleStandardArgs)
69 # handle the QUIETLY and REQUIRED arguments and set netCDF_FOUND to TRUE
70 # if all listed variables are TRUE
71 find_package_handle_standard_args( netCDF DEFAULT_MSG
80 mark_as_advanced( netCDF_CLIBS netCDF_CXXLIBS netCDF_FLIBS netCDF_PREFIX netCDF_LIBRARY_DIR )