~ubuntu-branches/ubuntu/vivid/adios/vivid-proposed

« back to all changes in this revision

Viewing changes to scripts/FindADIOS.cmake

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2014-06-16 23:06:38 UTC
  • mfrom: (15.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20140616230638-cxryhot6b8ge32l6
Tags: 1.7.0-1
* New upstream release.
* Add adios.pc pkgconfig file. adios_config now uses this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: fortran, readonly, 
 
11
                            # sequential (all are case insentative) 
 
12
#   )
 
13
#
 
14
# Module that finds the includes and libraries for a working ADIOS install.
 
15
# This module invokes the `adios_config` script that should be installed with
 
16
# the other ADIOS tools.
 
17
#
 
18
# To provide a hint to the module where to find the ADIOS installation,
 
19
# set the ADIOS_ROOT environment variable.
 
20
#
 
21
# If this variable is not set, make sure that at least the according `bin/`
 
22
# directory of ADIOS is in your PATH environment variable.
 
23
#
 
24
# Set the following CMake variables BEFORE calling find_packages to
 
25
# influence this module:
 
26
#   ADIOS_USE_STATIC_LIBS - Set to ON to force the use of static
 
27
#                           libraries.  Default: OFF
 
28
#
 
29
# This module will define the following variables:
 
30
#   ADIOS_INCLUDE_DIRS    - Include directories for the ADIOS headers.
 
31
#   ADIOS_LIBRARIES       - ADIOS libraries.
 
32
#   ADIOS_FOUND           - TRUE if FindADIOS found a working install
 
33
#   ADIOS_VERSION         - Version in format Major.Minor.Patch
 
34
#
 
35
# Not used for now:
 
36
#   ADIOS_DEFINITIONS     - Compiler definitions you should add with
 
37
#                           add_definitions(${ADIOS_DEFINITIONS})
 
38
#
 
39
# Example to find ADIOS (default)
 
40
# find_package(ADIOS)
 
41
# if(ADIOS_FOUND)
 
42
#   include_directories(${ADIOS_INCLUDE_DIRS})
 
43
#   add_executable(foo foo.c)
 
44
#   target_link_libraries(foo ${ADIOS_LIBRARIES})
 
45
# endif()
 
46
 
 
47
# Example to find ADIOS using component
 
48
# find_package(ADIOS COMPONENTS fortran)
 
49
# if(ADIOS_FOUND)
 
50
#   include_directories(${ADIOS_INCLUDE_DIRS})
 
51
#   add_executable(foo foo.c)
 
52
#   target_link_libraries(foo ${ADIOS_LIBRARIES})
 
53
# endif()
 
54
###############################################################################
 
55
#Copyright (c) 2014, Axel Huebl and Felix Schmitt from http://picongpu.hzdr.de
 
56
#All rights reserved.
 
57
 
 
58
#Redistribution and use in source and binary forms, with or without
 
59
#modification, are permitted provided that the following conditions are met:
 
60
 
 
61
#1. Redistributions of source code must retain the above copyright notice, this
 
62
#list of conditions and the following disclaimer.
 
63
 
 
64
#2. Redistributions in binary form must reproduce the above copyright notice,
 
65
#this list of conditions and the following disclaimer in the documentation
 
66
#and/or other materials provided with the distribution.
 
67
 
 
68
#3. Neither the name of the copyright holder nor the names of its contributors
 
69
#may be used to endorse or promote products derived from this software without
 
70
#specific prior written permission.
 
71
 
 
72
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
73
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
74
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
75
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 
76
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
77
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
78
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
79
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
80
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
81
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
82
###############################################################################
 
83
 
 
84
 
 
85
###############################################################################
 
86
# Required cmake version
 
87
###############################################################################
 
88
 
 
89
cmake_minimum_required(VERSION 2.8.5)
 
90
 
 
91
 
 
92
###############################################################################
 
93
# ADIOS
 
94
###############################################################################
 
95
# get flags for adios_config, -l is the default
 
96
#-f for fortran, -r for readonly, -s for sequential (nompi)
 
97
set(OPTLIST "-l")
 
98
if(ADIOS_FIND_COMPONENTS)
 
99
    foreach(COMP ${ADIOS_FIND_COMPONENTS})
 
100
        string(TOLOWER ${COMP} comp)
 
101
        if(comp STREQUAL "fortran")
 
102
            set(OPTLIST ${OPTLIST} f)
 
103
        elseif(comp STREQUAL "readonly")
 
104
            set(OPTLIST ${OPTLIST} r)
 
105
        elseif(comp STREQUAL "sequential")
 
106
            set(OPTLIST ${OPTLIST} s)
 
107
        else()
 
108
            message("ADIOS component ${COMP} is not supported. Please use fortran, readonly, or sequential")
 
109
        endif()
 
110
    endforeach()
 
111
endif()
 
112
string(REGEX REPLACE ";" "" OPTLIST "${OPTLIST}")
 
113
 
 
114
# we start by assuming we found ADIOS and falsify it if some
 
115
# dependencies are missing (or if we did not find ADIOS at all)
 
116
set(ADIOS_FOUND TRUE)
 
117
 
 
118
 
 
119
# find `adios_config` program #################################################
 
120
#   check the ADIOS_ROOT hint and the normal PATH
 
121
find_file(ADIOS_CONFIG
 
122
    NAME adios_config
 
123
    PATHS $ENV{ADIOS_ROOT}/bin $ENV{ADIOS_DIR}/bin $ENV{INSTALL_PREFIX}/bin $ENV{PATH})
 
124
 
 
125
if(ADIOS_CONFIG)
 
126
    message(STATUS "Found 'adios_config': ${ADIOS_CONFIG}")
 
127
else(ADIOS_CONFIG)
 
128
    set(ADIOS_FOUND FALSE)
 
129
    message(STATUS "Can NOT find 'adios_config' - set ADIOS_ROOT, ADIOS_DIR or INSTALL_PREFIX, or check your PATH")
 
130
endif(ADIOS_CONFIG)
 
131
 
 
132
# check `adios_config` program ################################################
 
133
if(ADIOS_FOUND)
 
134
    execute_process(COMMAND ${ADIOS_CONFIG} ${OPTLIST}
 
135
                    OUTPUT_VARIABLE ADIOS_LINKFLAGS
 
136
                    RESULT_VARIABLE ADIOS_CONFIG_RETURN
 
137
                    OUTPUT_STRIP_TRAILING_WHITESPACE)
 
138
    if(NOT ADIOS_CONFIG_RETURN EQUAL 0)
 
139
        set(ADIOS_FOUND FALSE)
 
140
        message(STATUS "Can NOT execute 'adios_config' - check file permissions")
 
141
    endif()
 
142
 
 
143
    # find ADIOS_ROOT_DIR
 
144
    execute_process(COMMAND ${ADIOS_CONFIG} -d
 
145
                    OUTPUT_VARIABLE ADIOS_ROOT_DIR
 
146
                    OUTPUT_STRIP_TRAILING_WHITESPACE)
 
147
    if(NOT IS_DIRECTORY "${ADIOS_ROOT_DIR}")
 
148
        set(ADIOS_FOUND FALSE)
 
149
        message(STATUS "The directory provided by 'adios_config -d' does not exist: ${ADIOS_ROOT_DIR}")
 
150
    endif()
 
151
endif(ADIOS_FOUND)
 
152
 
 
153
# option: use only static libs ################################################
 
154
if(ADIOS_USE_STATIC_LIBS)
 
155
    # carfully: we have to restore the original path in the end
 
156
    set(_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
 
157
    set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
 
158
endif()
 
159
 
 
160
 
 
161
# we found something in ADIOS_ROOT_DIR and adios_config works #################
 
162
if(ADIOS_FOUND)
 
163
    # ADIOS headers
 
164
    list(APPEND ADIOS_INCLUDE_DIRS ${ADIOS_ROOT_DIR}/include)
 
165
 
 
166
    # check for compiled in dependencies
 
167
    message(STATUS "ADIOS linker flags (unparsed): ${ADIOS_LINKFLAGS}")
 
168
 
 
169
    # find all library paths -L
 
170
    #   note: this can cause trouble if some libs are specified twice from
 
171
    #         different sources (quite unlikely)
 
172
    #         http://www.cmake.org/pipermail/cmake/2008-November/025128.html
 
173
    set(ADIOS_LIBRARY_DIRS "")
 
174
    string(REGEX MATCHALL "-L([A-Za-z_0-9/\\.-]+)" _ADIOS_LIBDIRS "${ADIOS_LINKFLAGS}")
 
175
    foreach(_LIBDIR ${_ADIOS_LIBDIRS})
 
176
        string(REPLACE "-L" "" _LIBDIR ${_LIBDIR})
 
177
        list(APPEND ADIOS_LIBRARY_DIRS ${_LIBDIR})
 
178
    endforeach()
 
179
    # we could append ${CMAKE_PREFIX_PATH} now but that is not really necessary
 
180
 
 
181
    #message(STATUS "ADIOS DIRS to look for libs: ${ADIOS_LIBRARY_DIRS}")
 
182
 
 
183
    # parse all -lname libraries and find an absolute path for them
 
184
    string(REGEX MATCHALL "-l([A-Za-z_0-9\\.-]+)" _ADIOS_LIBS "${ADIOS_LINKFLAGS}")
 
185
    foreach(_LIB ${_ADIOS_LIBS})
 
186
        string(REPLACE "-l" "" _LIB ${_LIB})
 
187
 
 
188
        # find static lib: absolute path in -L then default
 
189
        find_library(_LIB_DIR NAMES ${_LIB} PATHS ${ADIOS_LIBRARY_DIRS})
 
190
 
 
191
        # found?
 
192
        if(_LIB_DIR)
 
193
            message(STATUS "Found ${_LIB} in ${_LIB_DIR}")
 
194
            list(APPEND ADIOS_LIBRARIES "${_LIB_DIR}")
 
195
        else(_LIB_DIR)
 
196
            set(ADIOS_FOUND FALSE)
 
197
            message(STATUS "ADIOS: Could NOT find library '${_LIB}'")
 
198
        endif(_LIB_DIR)
 
199
 
 
200
        # clean cached var
 
201
        unset(_LIB_DIR CACHE)
 
202
        unset(_LIB_DIR)
 
203
    endforeach()
 
204
 
 
205
    #add libraries which are already using cmake format
 
206
    string(REGEX MATCHALL "/([A-Za-z_0-9/\\.-]+)\\.([a|so]+)" _ADIOS_LIBS_SUB "${ADIOS_LINKFLAGS}")
 
207
    list(APPEND ADIOS_LIBRARIES "${_ADIOS_LIBS_SUB}")
 
208
 
 
209
    # add the version string
 
210
    execute_process(COMMAND ${ADIOS_CONFIG} -v
 
211
                    OUTPUT_VARIABLE ADIOS_VERSION
 
212
                    OUTPUT_STRIP_TRAILING_WHITESPACE)
 
213
    
 
214
endif(ADIOS_FOUND)
 
215
 
 
216
# unset checked variables if not found
 
217
if(NOT ADIOS_FOUND)
 
218
    unset(ADIOS_INCLUDE_DIRS)
 
219
    unset(ADIOS_LIBRARIES)
 
220
endif(NOT ADIOS_FOUND)
 
221
 
 
222
 
 
223
# restore CMAKE_FIND_LIBRARY_SUFFIXES if manipulated by this module ###########
 
224
if(ADIOS_USE_STATIC_LIBS)
 
225
    set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
 
226
endif()
 
227
 
 
228
 
 
229
###############################################################################
 
230
# FindPackage Options
 
231
###############################################################################
 
232
 
 
233
# handles the REQUIRED, QUIET and version-related arguments for find_package
 
234
include(FindPackageHandleStandardArgs)
 
235
find_package_handle_standard_args(ADIOS
 
236
    REQUIRED_VARS ADIOS_LIBRARIES ADIOS_INCLUDE_DIRS
 
237
    VERSION_VAR ADIOS_VERSION
 
238
)