2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2015,2016,2017,2018, 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")
88 mark_as_advanced(HWLOC_INFO)
91 execute_process(COMMAND ${HWLOC_INFO} "--version"
92 RESULT_VARIABLE HWLOC_INFO_RES
93 OUTPUT_VARIABLE HWLOC_INFO_OUT
94 ERROR_VARIABLE HWLOC_INFO_ERR)
97 message(STATUS "Error executing hwloc-info: ${HWLOC_INFO_ERR}")
99 string(REGEX MATCH "[0-9]+.*[0-9]+" HWLOC_INFO_OUT "${HWLOC_INFO_OUT}")
100 set(HWLOC_VERSION ${HWLOC_INFO_OUT} CACHE STRING "Hwloc library version")
104 if (NOT Hwloc_FIND_QUIETLY)
105 message(STATUS "hwloc version: ${HWLOC_VERSION}")
108 # Parse header if cross-compiling, or if hwloc-info was not found
109 if(NOT HWLOC_VERSION)
110 # Hwloc is never installed as a framework on OS X, so this should always work.
111 file(READ "${HWLOC_INCLUDE_DIRS}/hwloc.h"
112 HEADER_CONTENTS LIMIT 16384)
113 string(REGEX REPLACE ".*#define HWLOC_API_VERSION (0[xX][0-9a-fA-F]+).*" "\\1"
114 HWLOC_API_VERSION "${HEADER_CONTENTS}")
115 string(SUBSTRING "${HWLOC_API_VERSION}" 4 2 HEX_MAJOR)
116 string(SUBSTRING "${HWLOC_API_VERSION}" 6 2 HEX_MINOR)
117 string(SUBSTRING "${HWLOC_API_VERSION}" 8 2 HEX_PATCH)
118 hex2dec(${HEX_MAJOR} DEC_MAJOR)
119 hex2dec(${HEX_MINOR} DEC_MINOR)
120 hex2dec(${HEX_PATCH} DEC_PATCH)
121 set(HWLOC_VERSION "${DEC_MAJOR}.${DEC_MINOR}.${DEC_PATCH}" CACHE STRING "Hwloc library version")
125 include(FindPackageHandleStandardArgs)
126 find_package_handle_standard_args(Hwloc
127 REQUIRED_VARS HWLOC_LIBRARIES HWLOC_INCLUDE_DIRS
128 VERSION_VAR HWLOC_VERSION)
130 mark_as_advanced(HWLOC_INCLUDE_DIRS HWLOC_LIBRARIES HWLOC_VERSION)