tFindNetCDF.cmake - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
 (HTM) git clone git://src.adamsgaard.dk/pism
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tFindNetCDF.cmake (3766B)
       ---
            1 # - Find NetCDF
            2 # Find the native NetCDF includes and library
            3 #
            4 #  NETCDF_INCLUDES    - where to find netcdf.h, etc
            5 #  NETCDF_LIBRARIES   - Link these libraries when using NetCDF
            6 #  NETCDF_FOUND       - True if NetCDF found including required interfaces (see below)
            7 #
            8 # Your package can require certain interfaces to be FOUND by setting these
            9 #
           10 #  NETCDF_CXX         - require the C++ interface and link the C++ library
           11 #  NETCDF_F77         - require the F77 interface and link the fortran library
           12 #  NETCDF_F90         - require the F90 interface and link the fortran library
           13 #
           14 # The following are not for general use and are included in
           15 # NETCDF_LIBRARIES if the corresponding option above is set.
           16 #
           17 #  NETCDF_LIBRARIES_C    - Just the C interface
           18 #  NETCDF_LIBRARIES_CXX  - C++ interface, if available
           19 #  NETCDF_LIBRARIES_F77  - Fortran 77 interface, if available
           20 #  NETCDF_LIBRARIES_F90  - Fortran 90 interface, if available
           21 #
           22 # Normal usage would be:
           23 #  set (NETCDF_F90 "YES")
           24 #  find_package (NetCDF REQUIRED)
           25 #  target_link_libraries (uses_f90_interface ${NETCDF_LIBRARIES})
           26 #  target_link_libraries (only_uses_c_interface ${NETCDF_LIBRARIES_C})
           27 
           28 if (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
           29   # Already in cache, be silent
           30   set (NETCDF_FIND_QUIETLY TRUE)
           31 endif (NETCDF_INCLUDES AND NETCDF_LIBRARIES)
           32 
           33 find_path (NETCDF_INCLUDES netcdf.h
           34   HINTS "${NETCDF_ROOT}/include" "$ENV{NETCDF_ROOT}/include")
           35 
           36 string(REGEX REPLACE "/include/?$" "/lib"
           37   NETCDF_LIB_HINT ${NETCDF_INCLUDES})
           38 
           39 find_library (NETCDF_LIBRARIES_C
           40   NAMES netcdf
           41   HINTS ${NETCDF_LIB_HINT})
           42 mark_as_advanced(NETCDF_LIBRARIES_C)
           43 
           44 if ((NOT NETCDF_LIBRARIES_C) OR (NOT NETCDF_INCLUDES))
           45   message(STATUS "Trying to find NetCDF using LD_LIBRARY_PATH (we're desperate)...")
           46 
           47   file(TO_CMAKE_PATH "$ENV{LD_LIBRARY_PATH}" LD_LIBRARY_PATH)
           48 
           49   find_library(NETCDF_LIBRARIES_C
           50     NAMES netcdf
           51     HINTS ${LD_LIBRARY_PATH})
           52 
           53   if (NETCDF_LIBRARIES_C)
           54     get_filename_component(NETCDF_LIB_DIR ${NETCDF_LIBRARIES_C} PATH)
           55     string(REGEX REPLACE "/lib/?$" "/include"
           56       NETCDF_H_HINT ${NETCDF_LIB_DIR})
           57 
           58     find_path (NETCDF_INCLUDES netcdf.h
           59       HINTS ${NETCDF_H_HINT}
           60       DOC "Path to netcdf.h")
           61   endif()
           62 endif()
           63 
           64 set (NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces
           65 set (NetCDF_libs "${NETCDF_LIBRARIES_C}")
           66 
           67 get_filename_component (NetCDF_lib_dirs "${NETCDF_LIBRARIES_C}" PATH)
           68 
           69 macro (NetCDF_check_interface lang header libs)
           70   if (NETCDF_${lang})
           71     find_path (NETCDF_INCLUDES_${lang} NAMES ${header}
           72       HINTS "${NETCDF_INCLUDES}" NO_DEFAULT_PATH)
           73     find_library (NETCDF_LIBRARIES_${lang} NAMES ${libs}
           74       HINTS "${NetCDF_lib_dirs}" NO_DEFAULT_PATH)
           75     mark_as_advanced (NETCDF_INCLUDES_${lang} NETCDF_LIBRARIES_${lang})
           76     if (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
           77       list (INSERT NetCDF_libs 0 ${NETCDF_LIBRARIES_${lang}}) # prepend so that -lnetcdf is last
           78     else (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
           79       set (NetCDF_has_interfaces "NO")
           80       message (STATUS "Failed to find NetCDF interface for ${lang}")
           81     endif (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang})
           82   endif (NETCDF_${lang})
           83 endmacro (NetCDF_check_interface)
           84 
           85 NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++)
           86 NetCDF_check_interface (F77 netcdf.inc  netcdff)
           87 NetCDF_check_interface (F90 netcdf.mod  netcdff)
           88 
           89 set (NETCDF_LIBRARIES "${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level")
           90 
           91 # handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if
           92 # all listed variables are TRUE
           93 include (FindPackageHandleStandardArgs)
           94 find_package_handle_standard_args (NetCDF DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDES NetCDF_has_interfaces)
           95 
           96 mark_as_advanced (NETCDF_LIBRARIES NETCDF_INCLUDES)