| 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 CGNS Find Module |
| 12 |
# |
| 13 |
# Usage: |
| 14 |
# Control the search through CGNS_DIR or setting environment variable |
| 15 |
# CGNS_ROOT to the CGNS installation prefix. |
| 16 |
# |
| 17 |
# This module does not search default paths! |
| 18 |
# |
| 19 |
# Following variables are set: |
| 20 |
# CGNS_FOUND (BOOL) Flag indicating if CGNS was found |
| 21 |
# CGNS_INCLUDE_DIR (PATH) Path to the CGNS include file |
| 22 |
# CGNS_INCLUDE_DIRS (LIST) List of all required include files |
| 23 |
# CGNS_LIBRARY_DIR (PATH) Path to the CGNS library |
| 24 |
# CGNS_LIBRARY (FILE) CGNS library |
| 25 |
# CGNS_LIBRARIES (LIST) List of all required CGNS 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 CGNS_ROOT was defined in the environment, use it. |
| 36 |
# Definition from the command line will take precedence. |
| 37 |
if (NOT CGNS_ROOT AND NOT $ENV{CGNS_ROOT} STREQUAL "") |
| 38 |
set(CGNS_ROOT $ENV{CGNS_ROOT}) |
| 39 |
endif() |
| 40 |
|
| 41 |
# CGNS_DIR is DEPRECATED WARN THE USER if it is set |
| 42 |
if (NOT CGNS_ROOT AND CGNS_DIR ) |
| 43 |
message(WARNING "The configuration parameter CGNS_DIR is deprecated." |
| 44 |
" Please use CGNS_ROOT instead to define the CGNS installation") |
| 45 |
set(CGNS_ROOT ${CGNS_DIR}) |
| 46 |
endif() |
| 47 |
|
| 48 |
# Add the usual paths for searching using the CGNS_ROOT variable |
| 49 |
if (CGNS_ROOT) |
| 50 |
list(APPEND _cgns_INCLUDE_SEARCH_DIRS |
| 51 |
${CGNS_ROOT}/include |
| 52 |
${CGNS_ROOT}) |
| 53 |
|
| 54 |
list(APPEND _cgns_LIBRARY_SEARCH_DIRS |
| 55 |
${CGNS_ROOT}/lib |
| 56 |
${CGNS_ROOT}) |
| 57 |
|
| 58 |
list(APPEND _cgns_BINARY_SEARCH_DIRS |
| 59 |
${CGNS_ROOT}/bin |
| 60 |
${CGNS_ROOT}) |
| 61 |
endif() |
| 62 |
|
| 63 |
if ( CGNS_LIBRARIES AND CGNS_INCLUDE_DIRS ) |
| 64 |
|
| 65 |
# Do nothing. Variables are set. No need to search again |
| 66 |
|
| 67 |
else(CGNS_LIBRARIES AND CGNS_INCLUDE_DIRS) |
| 68 |
|
| 69 |
# Cache variables |
| 70 |
if(CGNS_ROOT) |
| 71 |
set(CGNS_ROOT "${CGNS_ROOT}" CACHE PATH "Path to search for CGNS include and library files") |
| 72 |
endif() |
| 73 |
|
| 74 |
if(CGNS_INCLUDE_DIR) |
| 75 |
set(CGNS_INCLUDE_DIR "${CGNS_INCLUDE_DIR}" CACHE PATH "Path to search for CGNS include files") |
| 76 |
endif() |
| 77 |
|
| 78 |
if(CGNS_LIBRARY_DIR) |
| 79 |
set(CGNS_LIBRARY_DIR "${CGNS_LIBRARY_DIR}" CACHE PATH "Path to search for CGNS library files") |
| 80 |
endif() |
| 81 |
|
| 82 |
|
| 83 |
# Search for include files |
| 84 |
# Search order preference: |
| 85 |
# (1) CGNS_INCLUDE_DIR - check existence of path AND if the include files exist |
| 86 |
# (2) CGNS_ROOT/<include> |
| 87 |
# (3) Default CMake paths See cmake --html-help=out.html file for more information. |
| 88 |
# |
| 89 |
set(cgns_inc_names "cgnslib.h") |
| 90 |
if (CGNS_INCLUDE_DIR) |
| 91 |
|
| 92 |
if (EXISTS "${CGNS_INCLUDE_DIR}") |
| 93 |
|
| 94 |
find_path(cdf_test_include_path |
| 95 |
NAMES ${cgns_inc_names} |
| 96 |
HINTS ${CGNS_INCLUDE_DIR} |
| 97 |
NO_DEFAULT_PATH) |
| 98 |
if(NOT cdf_test_include_path) |
| 99 |
message(SEND_ERROR "Can not locate ${cgns_inc_names} in ${CGNS_INCLUDE_DIR}") |
| 100 |
endif() |
| 101 |
set(CGNS_INCLUDE_DIR "${cdf_test_include_path}") |
| 102 |
|
| 103 |
else() |
| 104 |
message(SEND_ERROR "CGNS_INCLUDE_DIR=${CGNS_INCLUDE_DIR} does not exist") |
| 105 |
set(CGNS_INCLUDE_DIR "CGNS_INCLUDE_DIR-NOTFOUND") |
| 106 |
endif() |
| 107 |
|
| 108 |
else() |
| 109 |
|
| 110 |
set(cgns_inc_suffixes "include") |
| 111 |
if(CGNS_ROOT) |
| 112 |
|
| 113 |
if (EXISTS "${CGNS_ROOT}" ) |
| 114 |
|
| 115 |
find_path(CGNS_INCLUDE_DIR |
| 116 |
NAMES ${cgns_inc_names} |
| 117 |
HINTS ${CGNS_ROOT}/include |
| 118 |
PATH_SUFFIXES ${cgns_inc_suffixes} |
| 119 |
NO_DEFAULT_PATH) |
| 120 |
|
| 121 |
else() |
| 122 |
message(SEND_ERROR "CGNS_ROOT=${CGNS_ROOT} does not exist") |
| 123 |
set(CGNS_INCLUDE_DIR "CGNS_INCLUDE_DIR-NOTFOUND") |
| 124 |
endif() |
| 125 |
|
| 126 |
|
| 127 |
else() |
| 128 |
|
| 129 |
find_path(CGNS_INCLUDE_DIR |
| 130 |
NAMES ${cgns_inc_names} |
| 131 |
PATH_SUFFIXES ${cgns_inc_suffixes}) |
| 132 |
|
| 133 |
endif() |
| 134 |
|
| 135 |
endif() |
| 136 |
|
| 137 |
|
| 138 |
if ( NOT CGNS_INCLUDE_DIR ) |
| 139 |
message(SEND_ERROR "Can not locate CGNS include directory") |
| 140 |
endif() |
| 141 |
|
| 142 |
# Search for libraries |
| 143 |
# Search order preference: |
| 144 |
# (1) CGNS_LIBRARY_DIR - check existence of path AND if the include files exist |
| 145 |
# (2) CGNS_ROOT/<lib,Lib> |
| 146 |
# (3) Default CMake paths See cmake --html-help=out.html file for more information. |
| 147 |
# |
| 148 |
if (CGNS_LIBRARY_DIR) |
| 149 |
|
| 150 |
if (EXISTS "${CGNS_LIBRARY_DIR}") |
| 151 |
|
| 152 |
find_library(CGNS_LIBRARY |
| 153 |
NAMES cgns |
| 154 |
HINTS ${CGNS_LIBRARY_DIR} |
| 155 |
NO_DEFAULT_PATH) |
| 156 |
|
| 157 |
else() |
| 158 |
message(SEND_ERROR "CGNS_LIBRARY_DIR=${CGNS_LIBRARY_DIR} does not exist") |
| 159 |
set(CGNS_LIBRARY "CGNS_LIBRARY-NOTFOUND") |
| 160 |
endif() |
| 161 |
|
| 162 |
else() |
| 163 |
|
| 164 |
if(CGNS_ROOT) |
| 165 |
|
| 166 |
if (EXISTS "${CGNS_ROOT}" ) |
| 167 |
|
| 168 |
find_library(CGNS_LIBRARY |
| 169 |
NAMES cgns |
| 170 |
HINTS ${CGNS_ROOT} |
| 171 |
PATH_SUFFIXES "lib" "Lib" |
| 172 |
NO_DEFAULT_PATH) |
| 173 |
|
| 174 |
else() |
| 175 |
message(SEND_ERROR "CGNS_ROOT=${CGNS_ROOT} does not exist") |
| 176 |
set(CGNS_LIBRARY "CGNS_LIBRARY-NOTFOUND") |
| 177 |
endif() |
| 178 |
|
| 179 |
|
| 180 |
else() |
| 181 |
|
| 182 |
find_library(CGNS_LIBRARY |
| 183 |
NAMES cgns |
| 184 |
PATH_SUFFIXES ${cgns_lib_suffixes}) |
| 185 |
|
| 186 |
endif() |
| 187 |
|
| 188 |
endif() |
| 189 |
|
| 190 |
if ( NOT CGNS_LIBRARY ) |
| 191 |
message(SEND_ERROR "Can not locate CGNS library") |
| 192 |
endif() |
| 193 |
|
| 194 |
# Define the LIBRARIES and INCLUDE_DORS |
| 195 |
set(CGNS_INCLUDE_DIRS ${CGNS_INCLUDE_DIR}) |
| 196 |
set(CGNS_LIBRARIES ${CGNS_CXX_LIBRARY} ${CGNS_LIBRARY}) |
| 197 |
|
| 198 |
# Need to find the CGNS config script to check for HDF5 |
| 199 |
set(cgns_config_h "${CGNS_INCLUDE_DIR}/cgnsconfig.h" ) |
| 200 |
if (EXISTS ${cgns_config_h}) |
| 201 |
file(STRINGS "${cgns_config_h}" cg_build_hdf5_string REGEX "^#define CG_BUILD_HDF5") |
| 202 |
string(REGEX REPLACE "[^0-9]" "" cg_build_hdf5 "${cg_build_hdf5_string}") |
| 203 |
if ( cg_build_hdf5 EQUAL 51 ) # Kluge: define is 1, but the 5 comes from hdf5 |
| 204 |
message(STATUS "CGNS requires HDF5") |
| 205 |
add_package_dependency(CGNS DEPENDS_ON HDF5) |
| 206 |
endif() |
| 207 |
else() |
| 208 |
message(STATUS "CGNS does not have cgnsconfig.h; assuming CGNS depends on HDF5") |
| 209 |
add_package_dependency(CGNS DEPENDS_ON HDF5) |
| 210 |
endif() |
| 211 |
|
| 212 |
# Need to find the CGNS types include to check for SCOPING |
| 213 |
set(cgns_types_h "${CGNS_INCLUDE_DIR}/cgnstypes.h" ) |
| 214 |
if (EXISTS ${cgns_types_h}) |
| 215 |
file(STRINGS "${cgns_types_h}" cg_scoping_string REGEX "^#define CG_BUILD_SCOPE") |
| 216 |
string(REGEX REPLACE "[^0-9]" "" cg_scoping "${cg_scoping_string}") |
| 217 |
if ( cg_scoping EQUAL 1 ) |
| 218 |
message(STATUS "CGNS Scoping Enabled as Required") |
| 219 |
else() |
| 220 |
message(SEND_ERROR "CGNS Scoping *Not* Enabled as Required. Rebuild CGNS library with CGNS_ENABLE_SCOPING defined.") |
| 221 |
endif() |
| 222 |
else() |
| 223 |
message(SEND_ERROR "CGNS: Could not find cgnstypes.h") |
| 224 |
endif() |
| 225 |
endif(CGNS_LIBRARIES AND CGNS_INCLUDE_DIRS ) |
| 226 |
|
| 227 |
# Search for CGNS tools |
| 228 |
set(_cgns_TOOLS cgnscheck cgnsdiff cgnslist cgnscompress cgnsconvert cgnsnames cgnsupdate) |
| 229 |
set(CGNS_TOOLS_FOUND) |
| 230 |
foreach( tool ${_cgns_TOOLS}) |
| 231 |
string(TOUPPER "${tool}" tool_uc) |
| 232 |
set(_cgns_VAR_NAME CGNS_${tool_uc}_BINARY) |
| 233 |
find_program(${_cgns_VAR_NAME} |
| 234 |
${tool} |
| 235 |
HINTS ${_cgns_BINARY_SEARCH_DIRS} |
| 236 |
${_cgns_FIND_OPTIONS}) |
| 237 |
if (${_cgns_VAR_NAME}) |
| 238 |
list(APPEND CGNS_TOOLS_FOUND ${tool}) |
| 239 |
endif() |
| 240 |
endforeach() |
| 241 |
|
| 242 |
# Send useful message if everything is found |
| 243 |
find_package_handle_standard_args(CGNS DEFAULT_MSG |
| 244 |
CGNS_LIBRARIES |
| 245 |
CGNS_INCLUDE_DIRS) |
| 246 |
|
| 247 |
# find_package)handle)standard_args should set CGNS_FOUND but it does not! |
| 248 |
if ( CGNS_LIBRARIES AND CGNS_INCLUDE_DIRS) |
| 249 |
set(CGNS_FOUND TRUE) |
| 250 |
else() |
| 251 |
set(CGNS_FOUND FALSE) |
| 252 |
endif() |
| 253 |
|
| 254 |
# --- Provide a summary of what the module found |
| 255 |
if ( NOT CGNS_FIND_QUIETLY ) |
| 256 |
|
| 257 |
# Create a not found list |
| 258 |
message(STATUS "\tCGNS_INCLUDE_DIRS = ${CGNS_INCLUDE_DIRS}") |
| 259 |
message(STATUS "\tCGNS_LIBRARIES = ${CGNS_LIBRARIES}") |
| 260 |
message(STATUS "\tCGNS_TOOLS_FOUND = ${CGNS_TOOLS_FOUND}") |
| 261 |
|
| 262 |
endif() |
| 263 |
# For compatibility with TriBITS: |
| 264 |
set(DOCSTR "List of semi-colon separated paths to look for the TPL CGNS") |
| 265 |
|
| 266 |
set(TPL_CGNS_LIBRARIES ${CGNS_LIBRARIES} CACHE PATH ${DOCSTR}) |
| 267 |
set(TPL_CGNS_INCLUDE_DIRS ${CGNS_INCLUDE_DIRS} CACHE PATH ${DOCSTR}) |
| 268 |
|
| 269 |
mark_as_advanced( |
| 270 |
CGNS_INCLUDE_DIR |
| 271 |
CGNS_INCLUDE_DIRS |
| 272 |
CGNS_LIBRARY |
| 273 |
CGNS_CXX_LIBRARY |
| 274 |
CGNS_LIBRARIES |
| 275 |
CGNS_LIBRARY_DIR |
| 276 |
) |