2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2015,2016, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
37 # - Locate headers and libraries for the Portable Hardware Locality (hwloc)
40 # Usage: find_package(Hwloc)
42 # FindHwloc defines the following variables:
44 # HWLOC_FOUND - True if both headers and libraries were located
45 # HWLOC_INCLUDE_DIRS - Where to find hwloc headers
46 # HWLOC_LIBRARIES - Libraries to link with to enable hwloc usage
47 # HWLOC_VERSION - Version (string) of the hwloc library
50 # Function for converting hex version numbers from HWLOC_API_VERSION if necessary
51 function(HEX2DEC str res)
52 string(LENGTH "${str}" len)
54 if("${str}" MATCHES "[0-9]")
55 set(${res} "${str}" PARENT_SCOPE)
56 elseif( "${str}" MATCHES "[aA]")
57 set(${res} 10 PARENT_SCOPE)
58 elseif( "${str}" MATCHES "[bB]")
59 set(${res} 11 PARENT_SCOPE)
60 elseif( "${str}" MATCHES "[cC]")
61 set(${res} 12 PARENT_SCOPE)
62 elseif( "${str}" MATCHES "[dD]")
63 set(${res} 13 PARENT_SCOPE)
64 elseif( "${str}" MATCHES "[eE]")
65 set(${res} 14 PARENT_SCOPE)
66 elseif( "${str}" MATCHES "[fF]")
67 set(${res} 15 PARENT_SCOPE)
72 string(SUBSTRING "${str}" 0 1 str1)
73 string(SUBSTRING "${str}" 1 -1 str2)
76 math(EXPR val "16 * ${res1} + ${res2}")
77 set(${res} "${val}" PARENT_SCOPE)
81 find_path(HWLOC_INCLUDE_DIRS "hwloc.h")
82 find_library(HWLOC_LIBRARIES "hwloc")
84 if(HWLOC_INCLUDE_DIRS)
85 # If we are not cross-compiling we try to use the hwloc-info program
86 if(NOT CMAKE_CROSSCOMPILING)
87 find_program(HWLOC_INFO "hwloc-info")
90 execute_process(COMMAND ${HWLOC_INFO} "--version"
91 RESULT_VARIABLE HWLOC_INFO_RES
92 OUTPUT_VARIABLE HWLOC_INFO_OUT
93 ERROR_VARIABLE HWLOC_INFO_ERR)
96 message(STATUS "Error executing hwloc-info: ${HWLOC_INFO_ERR}")
98 string(REGEX MATCH "[0-9]+.*[0-9]+" HWLOC_INFO_OUT "${HWLOC_INFO_OUT}")
99 set(HWLOC_VERSION ${HWLOC_INFO_OUT} CACHE STRING "Hwloc library version")
103 if (NOT Hwloc_FIND_QUIETLY)
104 message(STATUS "hwloc version: ${HWLOC_VERSION}")
107 # Parse header if cross-compiling, or if hwloc-info was not found
108 if(NOT HWLOC_VERSION)
109 # Hwloc is never installed as a framework on OS X, so this should always work.
110 file(READ "${HWLOC_INCLUDE_DIRS}/hwloc.h"
111 HEADER_CONTENTS LIMIT 16384)
112 string(REGEX REPLACE ".*#define HWLOC_API_VERSION (0[xX][0-9a-fA-F]+).*" "\\1"
113 HWLOC_API_VERSION "${HEADER_CONTENTS}")
114 string(SUBSTRING "${HWLOC_API_VERSION}" 4 2 HEX_MAJOR)
115 string(SUBSTRING "${HWLOC_API_VERSION}" 6 2 HEX_MINOR)
116 string(SUBSTRING "${HWLOC_API_VERSION}" 8 2 HEX_PATCH)
117 hex2dec(${HEX_MAJOR} DEC_MAJOR)
118 hex2dec(${HEX_MINOR} DEC_MINOR)
119 hex2dec(${HEX_PATCH} DEC_PATCH)
120 set(HWLOC_VERSION "${DEC_MAJOR}.${DEC_MINOR}.${DEC_PATCH}" CACHE STRING "Hwloc library version")
124 find_package_handle_standard_args(Hwloc
125 REQUIRED_VARS HWLOC_LIBRARIES HWLOC_INCLUDE_DIRS
126 VERSION_VAR HWLOC_VERSION)
128 mark_as_advanced(HWLOC_INCLUDE_DIRS HWLOC_LIBRARIES HWLOC_VERSION)