|
| 1 | +# - Find ADIOS library, routines for scientific, parallel IO |
| 2 | +# https://www.olcf.ornl.gov/center-projects/adios/ |
| 3 | +# |
| 4 | +# Use this module by invoking find_package with the form: |
| 5 | +# find_package(ADIOS |
| 6 | +# [version] [EXACT] # Minimum or EXACT version, e.g. 1.6.0 |
| 7 | +# [REQUIRED] # Fail with an error if ADIOS or a required |
| 8 | +# # component is not found |
| 9 | +# [QUIET] # ... |
| 10 | +# [COMPONENTS <...>] # Compiled in components, ignored |
| 11 | +# ) |
| 12 | +# |
| 13 | +# Module that finds the includes and libraries for a working ADIOS install. |
| 14 | +# This module invokes the `adios_config` script that should be installed with |
| 15 | +# the other ADIOS tools. |
| 16 | +# |
| 17 | +# To provide a hint to the module where to find the ADIOS installation, |
| 18 | +# set the ADIOS_ROOT environment variable. |
| 19 | +# |
| 20 | +# If this variable is not set, make sure that at least the according `bin/` |
| 21 | +# directory of ADIOS is in your PATH environment variable. |
| 22 | +# |
| 23 | +# Set the following CMake variables BEFORE calling find_packages to |
| 24 | +# influence this module: |
| 25 | +# ADIOS_USE_STATIC_LIBS - Set to ON to force the use of static |
| 26 | +# libraries. Default: OFF |
| 27 | +# |
| 28 | +# This module will define the following variables: |
| 29 | +# ADIOS_INCLUDE_DIRS - Include directories for the ADIOS headers. |
| 30 | +# ADIOS_LIBRARIES - ADIOS libraries. |
| 31 | +# ADIOS_FOUND - TRUE if FindADIOS found a working install |
| 32 | +# ADIOS_VERSION - Version in format Major.Minor.Patch |
| 33 | +# |
| 34 | +# Not used for now: |
| 35 | +# ADIOS_DEFINITIONS - Compiler definitions you should add with |
| 36 | +# add_definitions(${ADIOS_DEFINITIONS}) |
| 37 | +# |
| 38 | + |
| 39 | + |
| 40 | +################################################################################ |
| 41 | +# Copyright 2014 Axel Huebl, Felix Schmitt |
| 42 | +# |
| 43 | +# This file is part of PIConGPU. |
| 44 | +# |
| 45 | +# PIConGPU is free software: you can redistribute it and/or modify |
| 46 | +# it under the terms of the GNU General Public License as published by |
| 47 | +# the Free Software Foundation, either version 3 of the License, or |
| 48 | +# (at your option) any later version. |
| 49 | +# |
| 50 | +# PIConGPU is distributed in the hope that it will be useful, |
| 51 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 52 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 53 | +# GNU General Public License for more details. |
| 54 | +# |
| 55 | +# You should have received a copy of the GNU General Public License |
| 56 | +# along with PIConGPU. |
| 57 | +# If not, see <http://www.gnu.org/licenses/>. |
| 58 | +################################################################################ |
| 59 | + |
| 60 | + |
| 61 | +################################################################################ |
| 62 | +# Required cmake version |
| 63 | +################################################################################ |
| 64 | + |
| 65 | +cmake_minimum_required(VERSION 2.8.5) |
| 66 | + |
| 67 | + |
| 68 | +################################################################################ |
| 69 | +# ADIOS |
| 70 | +################################################################################ |
| 71 | + |
| 72 | +# we start by assuming we found ADIOS and falsify it if some |
| 73 | +# dependencies are missing (or if we did not find ADIOS at all) |
| 74 | +set(ADIOS_FOUND TRUE) |
| 75 | + |
| 76 | + |
| 77 | +# find `adios_config` program ################################################# |
| 78 | +# check the ADIOS_ROOT hint and the normal PATH |
| 79 | +find_file(ADIOS_CONFIG |
| 80 | + NAME adios_config |
| 81 | + PATHS $ENV{ADIOS_ROOT}/bin $ENV{PATH}) |
| 82 | + |
| 83 | +if(ADIOS_CONFIG) |
| 84 | + message(STATUS "Found 'adios_config': ${ADIOS_CONFIG}") |
| 85 | +else(ADIOS_CONFIG) |
| 86 | + set(ADIOS_FOUND FALSE) |
| 87 | + message(STATUS "Can NOT find 'adios_config' - set ADIOS_ROOT or check your PATH") |
| 88 | +endif(ADIOS_CONFIG) |
| 89 | + |
| 90 | + |
| 91 | +# check `adios_config` program ################################################ |
| 92 | +if(ADIOS_FOUND) |
| 93 | + execute_process(COMMAND ${ADIOS_CONFIG} -l |
| 94 | + OUTPUT_VARIABLE ADIOS_LINKFLAGS |
| 95 | + RESULT_VARIABLE ADIOS_CONFIG_RETURN |
| 96 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 97 | + if(NOT ADIOS_CONFIG_RETURN EQUAL 0) |
| 98 | + set(ADIOS_FOUND FALSE) |
| 99 | + message(STATUS "Can NOT execute 'adios_config' - check file permissions") |
| 100 | + endif() |
| 101 | + |
| 102 | + # find ADIOS_ROOT_DIR |
| 103 | + execute_process(COMMAND ${ADIOS_CONFIG} -d |
| 104 | + OUTPUT_VARIABLE ADIOS_ROOT_DIR |
| 105 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 106 | + if(NOT IS_DIRECTORY "${ADIOS_ROOT_DIR}") |
| 107 | + set(ADIOS_FOUND FALSE) |
| 108 | + message(STATUS "The directory provided by 'adios_config -d' does not exist: ${ADIOS_ROOT_DIR}") |
| 109 | + endif() |
| 110 | +endif(ADIOS_FOUND) |
| 111 | + |
| 112 | + |
| 113 | +# option: use only static libs ################################################ |
| 114 | +if(ADIOS_USE_STATIC_LIBS) |
| 115 | + # carfully: we have to restore the original path in the end |
| 116 | + set(_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
| 117 | + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) |
| 118 | +endif() |
| 119 | + |
| 120 | + |
| 121 | +# we found something in ADIOS_ROOT_DIR and adios_config works ################# |
| 122 | +if(ADIOS_FOUND) |
| 123 | + # ADIOS headers |
| 124 | + list(APPEND ADIOS_INCLUDE_DIRS ${ADIOS_ROOT_DIR}/include) |
| 125 | + |
| 126 | + # check for compiled in dependencies |
| 127 | + message(STATUS "ADIOS linker flags (unparsed): ${ADIOS_LINKFLAGS}") |
| 128 | + |
| 129 | + # find all library paths -L |
| 130 | + # note: this can cause trouble if some libs are specified twice from |
| 131 | + # different sources (quite unlikely) |
| 132 | + # http://www.cmake.org/pipermail/cmake/2008-November/025128.html |
| 133 | + set(ADIOS_LIBRARY_DIRS "") |
| 134 | + string(REGEX MATCHALL "-L([A-Za-z_0-9/\\.-]+)" _ADIOS_LIBDIRS "${ADIOS_LINKFLAGS}") |
| 135 | + foreach(_LIBDIR ${_ADIOS_LIBDIRS}) |
| 136 | + string(REPLACE "-L" "" _LIBDIR ${_LIBDIR}) |
| 137 | + list(APPEND ADIOS_LIBRARY_DIRS ${_LIBDIR}) |
| 138 | + endforeach() |
| 139 | + # we could append ${CMAKE_PREFIX_PATH} now but that is not really necessary |
| 140 | + |
| 141 | + #message(STATUS "ADIOS DIRS to look for libs: ${ADIOS_LIBRARY_DIRS}") |
| 142 | + |
| 143 | + # parse all -lname libraries and find an absolute path for them |
| 144 | + string(REGEX MATCHALL "-l([A-Za-z_0-9\\.-]+)" _ADIOS_LIBS "${ADIOS_LINKFLAGS}") |
| 145 | + |
| 146 | + foreach(_LIB ${_ADIOS_LIBS}) |
| 147 | + string(REPLACE "-l" "" _LIB ${_LIB}) |
| 148 | + |
| 149 | + # find static lib: absolute path in -L then default |
| 150 | + find_library(_LIB_DIR NAMES ${_LIB} PATHS ${ADIOS_LIBRARY_DIRS}) |
| 151 | + |
| 152 | + # found? |
| 153 | + if(_LIB_DIR) |
| 154 | + message(STATUS "Found ${_LIB} in ${_LIB_DIR}") |
| 155 | + list(APPEND ADIOS_LIBRARIES "${_LIB_DIR}") |
| 156 | + else(_LIB_DIR) |
| 157 | + set(ADIOS_FOUND FALSE) |
| 158 | + message(STATUS "ADIOS: Could NOT find library '${_LIB}'") |
| 159 | + endif(_LIB_DIR) |
| 160 | + |
| 161 | + # clean cached var |
| 162 | + unset(_LIB_DIR CACHE) |
| 163 | + unset(_LIB_DIR) |
| 164 | + endforeach() |
| 165 | + |
| 166 | + # simplify lists and check for missing components (not implemented) |
| 167 | + set(ADIOS_MISSING_COMPONENTS "") |
| 168 | + foreach(COMPONENT ${ADIOS_FIND_COMPONENTS}) |
| 169 | + string(TOUPPER ${COMPONENT} COMPONENT) |
| 170 | + list(APPEND ADIOS_MISSING_COMPONENTS ${COMPONENT}) |
| 171 | + endforeach() |
| 172 | + #message(STATUS "ADIOS required components: ${ADIOS_FIND_COMPONENTS}") |
| 173 | + |
| 174 | + # add the version string |
| 175 | + execute_process(COMMAND ${ADIOS_CONFIG} -v |
| 176 | + OUTPUT_VARIABLE ADIOS_VERSION |
| 177 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 178 | + |
| 179 | +endif(ADIOS_FOUND) |
| 180 | + |
| 181 | +# unset checked variables if not found |
| 182 | +if(NOT ADIOS_FOUND) |
| 183 | + unset(ADIOS_INCLUDE_DIRS) |
| 184 | + unset(ADIOS_LIBRARIES) |
| 185 | +endif(NOT ADIOS_FOUND) |
| 186 | + |
| 187 | + |
| 188 | +# restore CMAKE_FIND_LIBRARY_SUFFIXES if manipulated by this module ########### |
| 189 | +if(ADIOS_USE_STATIC_LIBS) |
| 190 | + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) |
| 191 | +endif() |
| 192 | + |
| 193 | + |
| 194 | +############################################################################### |
| 195 | +# FindPackage Options |
| 196 | +############################################################################### |
| 197 | + |
| 198 | +# handles the REQUIRED, QUIET and version-related arguments for find_package |
| 199 | +include(FindPackageHandleStandardArgs) |
| 200 | +find_package_handle_standard_args(ADIOS |
| 201 | + REQUIRED_VARS ADIOS_LIBRARIES ADIOS_INCLUDE_DIRS |
| 202 | + VERSION_VAR ADIOS_VERSION |
| 203 | +) |
0 commit comments