| 1 |
# -*- mode: cmake -*- |
| 2 |
# @HEADER |
| 3 |
# ***************************************************************************** |
| 4 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 5 |
# |
| 6 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 7 |
# SPDX-License-Identifier: BSD-3-Clause |
| 8 |
# ***************************************************************************** |
| 9 |
# @HEADER |
| 10 |
# |
| 11 |
# Based on the MSTK PNetCDF Find Module |
| 12 |
# |
| 13 |
# Usage: |
| 14 |
# Control the search through PNetCDF_DIR or setting environment variable |
| 15 |
# PNetCDF_ROOT to the PNetCDF installation prefix. |
| 16 |
# |
| 17 |
# This module does not search default paths! |
| 18 |
# |
| 19 |
# Following variables are set: |
| 20 |
# PNetCDF_FOUND (BOOL) Flag indicating if PNetCDF was found |
| 21 |
# PNetCDF_INCLUDE_DIR (PATH) Path to the PNetCDF include file |
| 22 |
# PNetCDF_INCLUDE_DIRS (LIST) List of all required include files |
| 23 |
# PNetCDF_LIBRARY_DIR (PATH) Path to the PNetCDF library |
| 24 |
# PNetCDF_LIBRARY (FILE) PNetCDF library |
| 25 |
# PNetCDF_LIBRARIES (LIST) List of all required PNetCDF libraries |
| 26 |
# |
| 27 |
# ############################################################################# |
| 28 |
|
| 29 |
# Standard CMake modules see CMAKE_ROOT/Modules |
| 30 |
include(FindPackageHandleStandardArgs) |
| 31 |
|
| 32 |
# MSTK CMake functions see <root>/cmake/modules for source |
| 33 |
include(AddPackageDependency) |
| 34 |
|
| 35 |
if ( PNetCDF_LIBRARIES AND PNetCDF_INCLUDE_DIRS ) |
| 36 |
|
| 37 |
# Do nothing. Variables are set. No need to search again |
| 38 |
|
| 39 |
else(PNetCDF_LIBRARIES AND PNetCDF_INCLUDE_DIRS) |
| 40 |
|
| 41 |
# If NetCDF_ROOT was defined in the environment, use it. |
| 42 |
# Definition from the command line will take precedence. |
| 43 |
if (NOT PNetCDF_ROOT AND NOT $ENV{PNetCDF_ROOT} STREQUAL "") |
| 44 |
set(PNetCDF_ROOT $ENV{PNetCDF_ROOT}) |
| 45 |
endif() |
| 46 |
|
| 47 |
# PNetCDF_DIR is DEPRECATED WARN THE USER if it is set |
| 48 |
if (NOT PNetCDF_ROOT AND PNetCDF_DIR ) |
| 49 |
message(WARNING "The configuration parameter PNetCDF_DIR is deprecated." |
| 50 |
" Please use PNetCDF_ROOT instead to define the NetCDF installation") |
| 51 |
set(PNetCDF_ROOT ${PNetCDF_DIR}) |
| 52 |
endif() |
| 53 |
|
| 54 |
# Cache variables |
| 55 |
if(PNetCDF_ROOT) |
| 56 |
set(PNetCDF_ROOT "${PNetCDF_ROOT}" CACHE PATH "Path to search for PNetCDF include and library files") |
| 57 |
endif() |
| 58 |
|
| 59 |
if(PNetCDF_INCLUDE_DIR) |
| 60 |
set(PNetCDF_INCLUDE_DIR "${PNetCDF_INCLUDE_DIR}" CACHE PATH "Path to search for PNetCDF include files") |
| 61 |
endif() |
| 62 |
|
| 63 |
if(PNetCDF_LIBRARY_DIR) |
| 64 |
set(PNetCDF_LIBRARY_DIR "${PNetCDF_LIBRARY_DIR}" CACHE PATH "Path to search for PNetCDF library files") |
| 65 |
endif() |
| 66 |
|
| 67 |
|
| 68 |
# Search for include files |
| 69 |
# Search order preference: |
| 70 |
# (1) PNetCDF_INCLUDE_DIR - check existence of path AND if the include files exist |
| 71 |
# (2) PNetCDF_ROOT/<include> |
| 72 |
# (3) Default CMake paths See cmake --html-help=out.html file for more information. |
| 73 |
# |
| 74 |
set(pnetcdf_inc_names "pnetcdf.h") |
| 75 |
if (PNetCDF_INCLUDE_DIR) |
| 76 |
|
| 77 |
if (EXISTS "${PNetCDF_INCLUDE_DIR}") |
| 78 |
|
| 79 |
find_path(cdf_test_include_path |
| 80 |
NAMES ${pnetcdf_inc_names} |
| 81 |
HINTS ${PNetCDF_INCLUDE_DIR} |
| 82 |
NO_DEFAULT_PATH) |
| 83 |
if(NOT cdf_test_include_path) |
| 84 |
message(SEND_ERROR "Can not locate ${pnetcdf_inc_names} in ${PNetCDF_INCLUDE_DIR}") |
| 85 |
endif() |
| 86 |
set(PNetCDF_INCLUDE_DIR "${cdf_test_include_path}") |
| 87 |
|
| 88 |
else() |
| 89 |
message(SEND_ERROR "PNetCDF_INCLUDE_DIR=${PNetCDF_INCLUDE_DIR} does not exist") |
| 90 |
set(PNetCDF_INCLUDE_DIR "PNetCDF_INCLUDE_DIR-NOTFOUND") |
| 91 |
endif() |
| 92 |
|
| 93 |
else() |
| 94 |
|
| 95 |
set(pnetcdf_inc_suffixes "include") |
| 96 |
if(PNetCDF_ROOT) |
| 97 |
|
| 98 |
if (EXISTS "${PNetCDF_ROOT}" ) |
| 99 |
|
| 100 |
find_path(PNetCDF_INCLUDE_DIR |
| 101 |
NAMES ${pnetcdf_inc_names} |
| 102 |
HINTS ${PNetCDF_ROOT}/include |
| 103 |
PATH_SUFFIXES ${pnetcdf_inc_suffixes} |
| 104 |
NO_DEFAULT_PATH) |
| 105 |
|
| 106 |
else() |
| 107 |
message(SEND_ERROR "PNetCDF_ROOT=${PNetCDF_ROOT} does not exist") |
| 108 |
set(PNetCDF_INCLUDE_DIR "PNetCDF_INCLUDE_DIR-NOTFOUND") |
| 109 |
endif() |
| 110 |
|
| 111 |
|
| 112 |
else() |
| 113 |
|
| 114 |
find_path(PNetCDF_INCLUDE_DIR |
| 115 |
NAMES ${pnetcdf_inc_names} |
| 116 |
PATH_SUFFIXES ${pnetcdf_inc_suffixes}) |
| 117 |
|
| 118 |
endif() |
| 119 |
|
| 120 |
endif() |
| 121 |
|
| 122 |
|
| 123 |
if ( NOT PNetCDF_INCLUDE_DIR ) |
| 124 |
message(SEND_ERROR "Can not locate PNetCDF include directory") |
| 125 |
endif() |
| 126 |
|
| 127 |
# Large dimension and parallel check here |
| 128 |
if ( PNetCDF_INCLUDE_DIR ) |
| 129 |
|
| 130 |
set(pnetcdf_h "${PNetCDF_INCLUDE_DIR}/pnetcdf.h" ) |
| 131 |
message(STATUS "PNetCDF include file ${pnetcdf_h} will be searched for define values") |
| 132 |
|
| 133 |
file(STRINGS "${pnetcdf_h}" pnetcdf_max_dims_string REGEX "^#define NC_MAX_DIMS") |
| 134 |
string(REGEX REPLACE "[^0-9]" "" pnetcdf_max_dims "${pnetcdf_max_dims_string}") |
| 135 |
|
| 136 |
file(STRINGS "${pnetcdf_h}" pnetcdf_max_vars_string REGEX "^#define NC_MAX_VARS") |
| 137 |
string(REGEX REPLACE "[^0-9]" "" pnetcdf_max_vars "${pnetcdf_max_vars_string}") |
| 138 |
|
| 139 |
if ( |
| 140 |
( (pnetcdf_max_dims EQUAL 65536) OR (pnetcdf_max_dims GREATER 65536) ) AND |
| 141 |
( (pnetcdf_max_vars EQUAL 524288) OR (pnetcdf_max_vars GREATER 524288) ) |
| 142 |
) |
| 143 |
set(PNetCDF_LARGE_DIMS TRUE) |
| 144 |
else() |
| 145 |
message(WARNING "WARNING: The PNetCDF found in ${PNetCDF_ROOT} does not have the correct NC_MAX_DIMS and NC_MAX_VARS. " |
| 146 |
"It may not be compatible with Exodus. See NetCDF-Mapping.md for details\n" ) |
| 147 |
set(PNetCDF_LARGE_DIMS FALSE) |
| 148 |
endif() |
| 149 |
|
| 150 |
endif() |
| 151 |
|
| 152 |
# Search for libraries |
| 153 |
# Search order preference: |
| 154 |
# (1) PNetCDF_LIBRARY_DIR - check existence of path AND if the include files exist |
| 155 |
# (2) PNetCDF_ROOT/<lib,Lib> |
| 156 |
# (3) Default CMake paths See cmake --html-help=out.html file for more information |
| 157 |
# |
| 158 |
if (PNetCDF_LIBRARY_DIR) |
| 159 |
|
| 160 |
if (EXISTS "${PNetCDF_LIBRARY_DIR}") |
| 161 |
|
| 162 |
find_library(PNetCDF_LIBRARY |
| 163 |
NAMES pnetcdf |
| 164 |
HINTS ${PNetCDF_LIBRARY_DIR} |
| 165 |
NO_DEFAULT_PATH) |
| 166 |
|
| 167 |
else() |
| 168 |
message(SEND_ERROR "PNetCDF_LIBRARY_DIR=${PNetCDF_LIBRARY_DIR} does not exist") |
| 169 |
set(PNetCDF_LIBRARY "PNetCDF_LIBRARY-NOTFOUND") |
| 170 |
endif() |
| 171 |
|
| 172 |
else() |
| 173 |
|
| 174 |
if(PNetCDF_ROOT) |
| 175 |
|
| 176 |
if (EXISTS "${PNetCDF_ROOT}" ) |
| 177 |
|
| 178 |
find_library(PNetCDF_LIBRARY |
| 179 |
NAMES pnetcdf |
| 180 |
HINTS ${PNetCDF_ROOT} |
| 181 |
PATH_SUFFIXES "lib" "Lib" |
| 182 |
NO_DEFAULT_PATH) |
| 183 |
|
| 184 |
else() |
| 185 |
message(SEND_ERROR "PNetCDF_ROOT=${PNetCDF_ROOT} does not exist") |
| 186 |
set(PNetCDF_LIBRARY "PNetCDF_LIBRARY-NOTFOUND") |
| 187 |
endif() |
| 188 |
|
| 189 |
|
| 190 |
else() |
| 191 |
|
| 192 |
find_library(PNetCDF_LIBRARY |
| 193 |
NAMES pnetcdf |
| 194 |
PATH_SUFFIXES ${pnetcdf_lib_suffixes}) |
| 195 |
|
| 196 |
endif() |
| 197 |
|
| 198 |
endif() |
| 199 |
|
| 200 |
if ( NOT PNetCDF_LIBRARY ) |
| 201 |
message(SEND_ERROR "Can not locate PNetCDF library") |
| 202 |
endif() |
| 203 |
|
| 204 |
# Define the LIBRARIES and INCLUDE_DORS |
| 205 |
set(PNetCDF_INCLUDE_DIRS ${PNetCDF_INCLUDE_DIR}) |
| 206 |
set(PNetCDF_LIBRARIES ${PNetCDF_CXX_LIBRARY} ${PNetCDF_LIBRARY}) |
| 207 |
|
| 208 |
endif(PNetCDF_LIBRARIES AND PNetCDF_INCLUDE_DIRS ) |
| 209 |
|
| 210 |
# Send useful message if everything is found |
| 211 |
find_package_handle_standard_args(PNetCDF DEFAULT_MSG |
| 212 |
PNetCDF_LIBRARIES |
| 213 |
PNetCDF_INCLUDE_DIRS) |
| 214 |
|
| 215 |
# find_package)handle)standard_args should set PNetCDF_FOUND but it does not! |
| 216 |
if ( PNetCDF_LIBRARIES AND PNetCDF_INCLUDE_DIRS) |
| 217 |
set(PNetCDF_FOUND TRUE) |
| 218 |
else() |
| 219 |
set(PNetCDF_FOUND FALSE) |
| 220 |
endif() |
| 221 |
|
| 222 |
# --- Provide a summary of what the module found |
| 223 |
if ( NOT PNetCDF_FIND_QUIETLY ) |
| 224 |
|
| 225 |
# Create a not found list |
| 226 |
message(STATUS "\tPNetCDF_INCLUDE_DIRS = ${PNetCDF_INCLUDE_DIRS}") |
| 227 |
message(STATUS "\tPNetCDF_LIBRARIES = ${PNetCDF_LIBRARIES}") |
| 228 |
|
| 229 |
endif() |
| 230 |
# For compatibility with TriBITS: |
| 231 |
set(DOCSTR "List of semi-colon separated paths to look for the TPL PNetCDF") |
| 232 |
|
| 233 |
set(TPL_PNetCDF_LIBRARIES ${PNetCDF_LIBRARIES} CACHE PATH ${DOCSTR}) |
| 234 |
set(TPL_PNetCDF_INCLUDE_DIRS ${PNetCDF_INCLUDE_DIRS} CACHE PATH ${DOCSTR}) |
| 235 |
|
| 236 |
mark_as_advanced( |
| 237 |
PNetCDF_INCLUDE_DIR |
| 238 |
PNetCDF_INCLUDE_DIRS |
| 239 |
PNetCDF_LIBRARY |
| 240 |
PNetCDF_CXX_LIBRARY |
| 241 |
PNetCDF_LIBRARIES |
| 242 |
PNetCDF_LIBRARY_DIR |
| 243 |
) |