Lemma is an Electromagnetics API
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. ###
  2. #
  3. # @copyright (c) 2009-2014 The University of Tennessee and The University
  4. # of Tennessee Research Foundation.
  5. # All rights reserved.
  6. # @copyright (c) 2012-2014 Inria. All rights reserved.
  7. # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
  8. #
  9. ###
  10. #
  11. # - Find HWLOC include dirs and libraries
  12. # Use this module by invoking find_package with the form:
  13. # find_package(HWLOC
  14. # [REQUIRED]) # Fail with error if hwloc is not found
  15. #
  16. # This module finds headers and hwloc library.
  17. # Results are reported in variables:
  18. # HWLOC_FOUND - True if headers and requested libraries were found
  19. # HWLOC_INCLUDE_DIRS - hwloc include directories
  20. # HWLOC_LIBRARY_DIRS - Link directories for hwloc libraries
  21. # HWLOC_LIBRARIES - hwloc component libraries to be linked
  22. #
  23. # The user can give specific paths where to find the libraries adding cmake
  24. # options at configure (ex: cmake path/to/project -DHWLOC_DIR=path/to/hwloc):
  25. # HWLOC_DIR - Where to find the base directory of hwloc
  26. # HWLOC_INCDIR - Where to find the header files
  27. # HWLOC_LIBDIR - Where to find the library files
  28. # The module can also look for the following environment variables if paths
  29. # are not given as cmake variable: HWLOC_DIR, HWLOC_INCDIR, HWLOC_LIBDIR
  30. #=============================================================================
  31. # Copyright 2012-2013 Inria
  32. # Copyright 2012-2013 Emmanuel Agullo
  33. # Copyright 2012-2013 Mathieu Faverge
  34. # Copyright 2012 Cedric Castagnede
  35. # Copyright 2013 Florent Pruvost
  36. #
  37. # Distributed under the OSI-approved BSD License (the "License");
  38. # see accompanying file MORSE-Copyright.txt for details.
  39. #
  40. # This software is distributed WITHOUT ANY WARRANTY; without even the
  41. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  42. # See the License for more information.
  43. #=============================================================================
  44. # (To distribute this file outside of Morse, substitute the full
  45. # License text for the above reference.)
  46. include(CheckStructHasMember)
  47. include(CheckCSourceCompiles)
  48. if (NOT HWLOC_FOUND)
  49. set(HWLOC_DIR "" CACHE PATH "Installation directory of HWLOC library")
  50. if (NOT HWLOC_FIND_QUIETLY)
  51. message(STATUS "A cache variable, namely HWLOC_DIR, has been set to specify the install directory of HWLOC")
  52. endif()
  53. endif()
  54. set(ENV_HWLOC_DIR "$ENV{HWLOC_DIR}")
  55. set(ENV_HWLOC_INCDIR "$ENV{HWLOC_INCDIR}")
  56. set(ENV_HWLOC_LIBDIR "$ENV{HWLOC_LIBDIR}")
  57. set(HWLOC_GIVEN_BY_USER "FALSE")
  58. if ( HWLOC_DIR OR ( HWLOC_INCDIR AND HWLOC_LIBDIR) OR ENV_HWLOC_DIR OR (ENV_HWLOC_INCDIR AND ENV_HWLOC_LIBDIR) )
  59. set(HWLOC_GIVEN_BY_USER "TRUE")
  60. endif()
  61. # Optionally use pkg-config to detect include/library dirs (if pkg-config is available)
  62. # -------------------------------------------------------------------------------------
  63. include(FindPkgConfig)
  64. find_package(PkgConfig QUIET)
  65. if( PKG_CONFIG_EXECUTABLE AND NOT HWLOC_GIVEN_BY_USER )
  66. pkg_search_module(HWLOC hwloc)
  67. if (NOT HWLOC_FIND_QUIETLY)
  68. if (HWLOC_FOUND AND HWLOC_LIBRARIES)
  69. message(STATUS "Looking for HWLOC - found using PkgConfig")
  70. #if(NOT HWLOC_INCLUDE_DIRS)
  71. # message("${Magenta}HWLOC_INCLUDE_DIRS is empty using PkgConfig."
  72. # "Perhaps the path to hwloc headers is already present in your"
  73. # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}")
  74. #endif()
  75. else()
  76. message(STATUS "${Magenta}Looking for HWLOC - not found using PkgConfig."
  77. "\n Perhaps you should add the directory containing hwloc.pc to"
  78. "\n the PKG_CONFIG_PATH environment variable.${ColourReset}")
  79. endif()
  80. endif()
  81. endif( PKG_CONFIG_EXECUTABLE AND NOT HWLOC_GIVEN_BY_USER )
  82. if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR (HWLOC_GIVEN_BY_USER) )
  83. if (NOT HWLOC_FIND_QUIETLY)
  84. message(STATUS "Looking for HWLOC - PkgConfig not used")
  85. endif()
  86. # Looking for include
  87. # -------------------
  88. # Add system include paths to search include
  89. # ------------------------------------------
  90. unset(_inc_env)
  91. if(ENV_HWLOC_INCDIR)
  92. list(APPEND _inc_env "${ENV_HWLOC_INCDIR}")
  93. elseif(ENV_HWLOC_DIR)
  94. list(APPEND _inc_env "${ENV_HWLOC_DIR}")
  95. list(APPEND _inc_env "${ENV_HWLOC_DIR}/include")
  96. list(APPEND _inc_env "${ENV_HWLOC_DIR}/include/hwloc")
  97. else()
  98. if(WIN32)
  99. string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
  100. else()
  101. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  102. list(APPEND _inc_env "${_path_env}")
  103. string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
  104. list(APPEND _inc_env "${_path_env}")
  105. string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
  106. list(APPEND _inc_env "${_path_env}")
  107. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
  108. list(APPEND _inc_env "${_path_env}")
  109. endif()
  110. endif()
  111. list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  112. list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  113. list(REMOVE_DUPLICATES _inc_env)
  114. # set paths where to look for
  115. set(PATH_TO_LOOK_FOR "${_inc_env}")
  116. # Try to find the hwloc header in the given paths
  117. # -------------------------------------------------
  118. # call cmake macro to find the header path
  119. if(HWLOC_INCDIR)
  120. set(HWLOC_hwloc.h_DIRS "HWLOC_hwloc.h_DIRS-NOTFOUND")
  121. find_path(HWLOC_hwloc.h_DIRS
  122. NAMES hwloc.h
  123. HINTS ${HWLOC_INCDIR})
  124. else()
  125. if(HWLOC_DIR)
  126. set(HWLOC_hwloc.h_DIRS "HWLOC_hwloc.h_DIRS-NOTFOUND")
  127. find_path(HWLOC_hwloc.h_DIRS
  128. NAMES hwloc.h
  129. HINTS ${HWLOC_DIR}
  130. PATH_SUFFIXES "include" "include/hwloc")
  131. else()
  132. set(HWLOC_hwloc.h_DIRS "HWLOC_hwloc.h_DIRS-NOTFOUND")
  133. find_path(HWLOC_hwloc.h_DIRS
  134. NAMES hwloc.h
  135. HINTS ${PATH_TO_LOOK_FOR}
  136. PATH_SUFFIXES "hwloc")
  137. endif()
  138. endif()
  139. mark_as_advanced(HWLOC_hwloc.h_DIRS)
  140. # Add path to cmake variable
  141. # ------------------------------------
  142. if (HWLOC_hwloc.h_DIRS)
  143. set(HWLOC_INCLUDE_DIRS "${HWLOC_hwloc.h_DIRS}")
  144. else ()
  145. set(HWLOC_INCLUDE_DIRS "HWLOC_INCLUDE_DIRS-NOTFOUND")
  146. if(NOT HWLOC_FIND_QUIETLY)
  147. message(STATUS "Looking for hwloc -- hwloc.h not found")
  148. endif()
  149. endif ()
  150. if (HWLOC_INCLUDE_DIRS)
  151. list(REMOVE_DUPLICATES HWLOC_INCLUDE_DIRS)
  152. endif ()
  153. # Looking for lib
  154. # ---------------
  155. # Add system library paths to search lib
  156. # --------------------------------------
  157. unset(_lib_env)
  158. if(ENV_HWLOC_LIBDIR)
  159. list(APPEND _lib_env "${ENV_HWLOC_LIBDIR}")
  160. elseif(ENV_HWLOC_DIR)
  161. list(APPEND _lib_env "${ENV_HWLOC_DIR}")
  162. list(APPEND _lib_env "${ENV_HWLOC_DIR}/lib")
  163. else()
  164. if(WIN32)
  165. string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
  166. else()
  167. if(APPLE)
  168. string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
  169. else()
  170. string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
  171. endif()
  172. list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
  173. list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  174. endif()
  175. endif()
  176. list(REMOVE_DUPLICATES _lib_env)
  177. # set paths where to look for
  178. set(PATH_TO_LOOK_FOR "${_lib_env}")
  179. # Try to find the hwloc lib in the given paths
  180. # ----------------------------------------------
  181. # call cmake macro to find the lib path
  182. if(HWLOC_LIBDIR)
  183. set(HWLOC_hwloc_LIBRARY "HWLOC_hwloc_LIBRARY-NOTFOUND")
  184. find_library(HWLOC_hwloc_LIBRARY
  185. NAMES hwloc
  186. HINTS ${HWLOC_LIBDIR})
  187. else()
  188. if(HWLOC_DIR)
  189. set(HWLOC_hwloc_LIBRARY "HWLOC_hwloc_LIBRARY-NOTFOUND")
  190. find_library(HWLOC_hwloc_LIBRARY
  191. NAMES hwloc
  192. HINTS ${HWLOC_DIR}
  193. PATH_SUFFIXES lib lib32 lib64)
  194. else()
  195. set(HWLOC_hwloc_LIBRARY "HWLOC_hwloc_LIBRARY-NOTFOUND")
  196. find_library(HWLOC_hwloc_LIBRARY
  197. NAMES hwloc
  198. HINTS ${PATH_TO_LOOK_FOR})
  199. endif()
  200. endif()
  201. mark_as_advanced(HWLOC_hwloc_LIBRARY)
  202. # If found, add path to cmake variable
  203. # ------------------------------------
  204. if (HWLOC_hwloc_LIBRARY)
  205. get_filename_component(hwloc_lib_path ${HWLOC_hwloc_LIBRARY} PATH)
  206. # set cmake variables (respects naming convention)
  207. set(HWLOC_LIBRARIES "${HWLOC_hwloc_LIBRARY}")
  208. set(HWLOC_LIBRARY_DIRS "${hwloc_lib_path}")
  209. else ()
  210. set(HWLOC_LIBRARIES "HWLOC_LIBRARIES-NOTFOUND")
  211. set(HWLOC_LIBRARY_DIRS "HWLOC_LIBRARY_DIRS-NOTFOUND")
  212. if(NOT HWLOC_FIND_QUIETLY)
  213. message(STATUS "Looking for hwloc -- lib hwloc not found")
  214. endif()
  215. endif ()
  216. if (HWLOC_LIBRARY_DIRS)
  217. list(REMOVE_DUPLICATES HWLOC_LIBRARY_DIRS)
  218. endif ()
  219. # check a function to validate the find
  220. if(HWLOC_LIBRARIES)
  221. set(REQUIRED_INCDIRS)
  222. set(REQUIRED_LIBDIRS)
  223. set(REQUIRED_LIBS)
  224. # HWLOC
  225. if (HWLOC_INCLUDE_DIRS)
  226. set(REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}")
  227. endif()
  228. if (HWLOC_LIBRARY_DIRS)
  229. set(REQUIRED_LIBDIRS "${HWLOC_LIBRARY_DIRS}")
  230. endif()
  231. set(REQUIRED_LIBS "${HWLOC_LIBRARIES}")
  232. # set required libraries for link
  233. set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
  234. set(CMAKE_REQUIRED_LIBRARIES)
  235. foreach(lib_dir ${REQUIRED_LIBDIRS})
  236. list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
  237. endforeach()
  238. list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
  239. string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
  240. # test link
  241. unset(HWLOC_WORKS CACHE)
  242. include(CheckFunctionExists)
  243. check_function_exists(hwloc_topology_init HWLOC_WORKS)
  244. mark_as_advanced(HWLOC_WORKS)
  245. if(NOT HWLOC_WORKS)
  246. if(NOT HWLOC_FIND_QUIETLY)
  247. message(STATUS "Looking for hwloc : test of hwloc_topology_init with hwloc library fails")
  248. message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
  249. message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
  250. message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
  251. endif()
  252. endif()
  253. set(CMAKE_REQUIRED_INCLUDES)
  254. set(CMAKE_REQUIRED_FLAGS)
  255. set(CMAKE_REQUIRED_LIBRARIES)
  256. endif(HWLOC_LIBRARIES)
  257. endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR (HWLOC_GIVEN_BY_USER) )
  258. if (HWLOC_LIBRARIES)
  259. if (HWLOC_LIBRARY_DIRS)
  260. list(GET HWLOC_LIBRARY_DIRS 0 first_lib_path)
  261. else()
  262. list(GET HWLOC_LIBRARIES 0 first_lib)
  263. get_filename_component(first_lib_path "${first_lib}" PATH)
  264. endif()
  265. if (${first_lib_path} MATCHES "/lib(32|64)?$")
  266. string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
  267. set(HWLOC_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of HWLOC library" FORCE)
  268. else()
  269. set(HWLOC_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of HWLOC library" FORCE)
  270. endif()
  271. endif()
  272. mark_as_advanced(HWLOC_DIR)
  273. mark_as_advanced(HWLOC_DIR_FOUND)
  274. # check that HWLOC has been found
  275. # -------------------------------
  276. include(FindPackageHandleStandardArgs)
  277. if (PKG_CONFIG_EXECUTABLE AND HWLOC_FOUND)
  278. find_package_handle_standard_args(HWLOC DEFAULT_MSG
  279. HWLOC_LIBRARIES)
  280. else()
  281. find_package_handle_standard_args(HWLOC DEFAULT_MSG
  282. HWLOC_LIBRARIES
  283. HWLOC_WORKS)
  284. endif()
  285. if (HWLOC_FOUND)
  286. set(HWLOC_SAVE_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
  287. list(APPEND CMAKE_REQUIRED_INCLUDES ${HWLOC_INCLUDE_DIRS})
  288. # test headers to guess the version
  289. check_struct_has_member( "struct hwloc_obj" parent hwloc.h HAVE_HWLOC_PARENT_MEMBER )
  290. check_struct_has_member( "struct hwloc_cache_attr_s" size hwloc.h HAVE_HWLOC_CACHE_ATTR )
  291. check_c_source_compiles( "#include <hwloc.h>
  292. int main(void) { hwloc_obj_t o; o->type = HWLOC_OBJ_PU; return 0;}" HAVE_HWLOC_OBJ_PU)
  293. include(CheckLibraryExists)
  294. check_library_exists(${HWLOC_LIBRARIES} hwloc_bitmap_free "" HAVE_HWLOC_BITMAP)
  295. set(CMAKE_REQUIRED_INCLUDES ${HWLOC_SAVE_CMAKE_REQUIRED_INCLUDES})
  296. endif()