You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
4.5 KiB

  1. # FindHwloc
  2. # ----------
  3. #
  4. # Try to find Portable Hardware Locality (hwloc) libraries.
  5. # http://www.open-mpi.org/software/hwloc
  6. #
  7. # You may declare HWLOC_ROOT environment variable to tell where
  8. # your hwloc library is installed.
  9. #
  10. # Once done this will define::
  11. #
  12. # Hwloc_FOUND - True if hwloc was found
  13. # Hwloc_INCLUDE_DIRS - include directories for hwloc
  14. # Hwloc_LIBRARIES - link against these libraries to use hwloc
  15. # Hwloc_VERSION - version
  16. # Hwloc_CFLAGS - include directories as compiler flags
  17. # Hwloc_LDLFAGS - link paths and libs as compiler flags
  18. #
  19. #=============================================================================
  20. # Copyright 2014 Mikael Lepistö
  21. #
  22. # Distributed under the OSI-approved BSD License (the "License");
  23. #
  24. # This software is distributed WITHOUT ANY WARRANTY; without even the
  25. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  26. # See the License for more information.
  27. #=============================================================================
  28. if(WIN32)
  29. find_path(Hwloc_INCLUDE_DIR
  30. NAMES
  31. hwloc.h
  32. PATHS
  33. ENV "PROGRAMFILES(X86)"
  34. ENV HWLOC_ROOT
  35. PATH_SUFFIXES
  36. include
  37. )
  38. find_library(Hwloc_LIBRARY
  39. NAMES
  40. libhwloc.lib
  41. PATHS
  42. ENV "PROGRAMFILES(X86)"
  43. ENV HWLOC_ROOT
  44. PATH_SUFFIXES
  45. lib
  46. )
  47. #
  48. # Check if the found library can be used to linking
  49. #
  50. SET (_TEST_SOURCE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/linktest.c")
  51. FILE (WRITE "${_TEST_SOURCE}"
  52. "
  53. #include <hwloc.h>
  54. int main()
  55. {
  56. hwloc_topology_t topology;
  57. int nbcores;
  58. hwloc_topology_init(&topology);
  59. hwloc_topology_load(topology);
  60. nbcores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
  61. hwloc_topology_destroy(topology);
  62. return 0;
  63. }
  64. "
  65. )
  66. TRY_COMPILE(_LINK_SUCCESS ${CMAKE_BINARY_DIR} "${_TEST_SOURCE}"
  67. CMAKE_FLAGS
  68. "-DINCLUDE_DIRECTORIES:STRING=${Hwloc_INCLUDE_DIR}"
  69. CMAKE_FLAGS
  70. "-DLINK_LIBRARIES:STRING=${Hwloc_LIBRARY}"
  71. )
  72. IF(NOT _LINK_SUCCESS)
  73. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  74. message(STATUS "You are building 64bit target.")
  75. ELSE()
  76. message(STATUS "You are building 32bit code. If you like to build x64 use e.g. -G 'Visual Studio 12 Win64' generator." )
  77. ENDIF()
  78. message(FATAL_ERROR "Library found, but linking test program failed.")
  79. ENDIF()
  80. #
  81. # Resolve version if some compiled binary found...
  82. #
  83. find_program(HWLOC_INFO_EXECUTABLE
  84. NAMES
  85. hwloc-info
  86. PATHS
  87. ENV HWLOC_ROOT
  88. PATH_SUFFIXES
  89. bin
  90. )
  91. if(HWLOC_INFO_EXECUTABLE)
  92. execute_process(
  93. COMMAND ${HWLOC_INFO_EXECUTABLE} "--version"
  94. OUTPUT_VARIABLE HWLOC_VERSION_LINE
  95. OUTPUT_STRIP_TRAILING_WHITESPACE
  96. )
  97. string(REGEX MATCH "([0-9]+.[0-9]+)$"
  98. Hwloc_VERSION "${HWLOC_VERSION_LINE}")
  99. unset(HWLOC_VERSION_LINE)
  100. endif()
  101. #
  102. # All good
  103. #
  104. set(Hwloc_LIBRARIES ${Hwloc_LIBRARY})
  105. set(Hwloc_INCLUDE_DIRS ${Hwloc_INCLUDE_DIR})
  106. include(FindPackageHandleStandardArgs)
  107. find_package_handle_standard_args(
  108. Hwloc
  109. FOUND_VAR Hwloc_FOUND
  110. REQUIRED_VARS Hwloc_LIBRARY Hwloc_INCLUDE_DIR
  111. VERSION_VAR Hwloc_VERSION)
  112. mark_as_advanced(
  113. Hwloc_INCLUDE_DIR
  114. Hwloc_LIBRARY)
  115. foreach(arg ${Hwloc_INCLUDE_DIRS})
  116. set(Hwloc_CFLAGS "${Hwloc_CFLAGS} /I${arg}")
  117. endforeach()
  118. set(Hwloc_LDFLAGS "${Hwloc_LIBRARY}")
  119. else()
  120. # Find with pkgconfig
  121. find_package(PkgConfig)
  122. if(HWLOC_ROOT)
  123. set(ENV{PKG_CONFIG_PATH} "${HWLOC_ROOT}/lib/pkgconfig")
  124. else()
  125. foreach(PREFIX ${CMAKE_PREFIX_PATH})
  126. set(PKG_CONFIG_PATH "${PKG_CONFIG_PATH}:${PREFIX}/lib/pkgconfig")
  127. endforeach()
  128. set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}")
  129. endif()
  130. if(hwloc_FIND_REQUIRED)
  131. set(_hwloc_OPTS "REQUIRED")
  132. elseif(hwloc_FIND_QUIETLY)
  133. set(_hwloc_OPTS "QUIET")
  134. else()
  135. set(_hwloc_output 1)
  136. endif()
  137. if(hwloc_FIND_VERSION)
  138. if(hwloc_FIND_VERSION_EXACT)
  139. pkg_check_modules(Hwloc ${_hwloc_OPTS} hwloc=${hwloc_FIND_VERSION})
  140. else()
  141. pkg_check_modules(Hwloc ${_hwloc_OPTS} hwloc>=${hwloc_FIND_VERSION})
  142. endif()
  143. else()
  144. pkg_check_modules(Hwloc ${_hwloc_OPTS} hwloc)
  145. endif()
  146. if(Hwloc_FOUND)
  147. include(FindPackageHandleStandardArgs)
  148. find_package_handle_standard_args(Hwloc DEFAULT_MSG Hwloc_LIBRARIES)
  149. if(NOT ${Hwloc_VERSION} VERSION_LESS 1.7.0)
  150. set(Hwloc_GL_FOUND 1)
  151. endif()
  152. if(_hwloc_output)
  153. message(STATUS
  154. "Found hwloc ${Hwloc_VERSION} in ${Hwloc_INCLUDE_DIRS}:${Hwloc_LIBRARIES}")
  155. endif()
  156. endif()
  157. endif()