FindPASTIX.cmake 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 PASTIX include dirs and libraries
  12. # Use this module by invoking find_package with the form:
  13. # find_package(PASTIX
  14. # [REQUIRED] # Fail with error if pastix is not found
  15. # [COMPONENTS <comp1> <comp2> ...] # dependencies
  16. # )
  17. #
  18. # PASTIX depends on the following libraries:
  19. # - Threads, m, rt
  20. # - MPI
  21. # - HWLOC
  22. # - BLAS
  23. #
  24. # COMPONENTS are optional libraries PASTIX could be linked with,
  25. # Use it to drive detection of a specific compilation chain
  26. # COMPONENTS can be some of the following:
  27. # - MPI: to activate detection of the parallel MPI version (default)
  28. # it looks for Threads, HWLOC, BLAS, MPI and ScaLAPACK libraries
  29. # - SEQ: to activate detection of the sequential version (exclude MPI version)
  30. # - STARPU: to activate detection of StarPU version
  31. # it looks for MPI version of StarPU (default behaviour)
  32. # if SEQ and STARPU are given, it looks for a StarPU without MPI
  33. # - STARPU_CUDA: to activate detection of StarPU with CUDA
  34. # - STARPU_FXT: to activate detection of StarPU with FxT
  35. # - SCOTCH: to activate detection of PASTIX linked with SCOTCH
  36. # - PTSCOTCH: to activate detection of PASTIX linked with SCOTCH
  37. # - METIS: to activate detection of PASTIX linked with SCOTCH
  38. #
  39. # This module finds headers and pastix library.
  40. # Results are reported in variables:
  41. # PASTIX_FOUND - True if headers and requested libraries were found
  42. # PASTIX_LINKER_FLAGS - list of required linker flags (excluding -l and -L)
  43. # PASTIX_INCLUDE_DIRS - pastix include directories
  44. # PASTIX_LIBRARY_DIRS - Link directories for pastix libraries
  45. # PASTIX_LIBRARIES - pastix libraries
  46. # PASTIX_INCLUDE_DIRS_DEP - pastix + dependencies include directories
  47. # PASTIX_LIBRARY_DIRS_DEP - pastix + dependencies link directories
  48. # PASTIX_LIBRARIES_DEP - pastix libraries + dependencies
  49. #
  50. # The user can give specific paths where to find the libraries adding cmake
  51. # options at configure (ex: cmake path/to/project -DPASTIX_DIR=path/to/pastix):
  52. # PASTIX_DIR - Where to find the base directory of pastix
  53. # PASTIX_INCDIR - Where to find the header files
  54. # PASTIX_LIBDIR - Where to find the library files
  55. # The module can also look for the following environment variables if paths
  56. # are not given as cmake variable: PASTIX_DIR, PASTIX_INCDIR, PASTIX_LIBDIR
  57. #=============================================================================
  58. # Copyright 2012-2013 Inria
  59. # Copyright 2012-2013 Emmanuel Agullo
  60. # Copyright 2012-2013 Mathieu Faverge
  61. # Copyright 2012 Cedric Castagnede
  62. # Copyright 2013 Florent Pruvost
  63. #
  64. # Distributed under the OSI-approved BSD License (the "License");
  65. # see accompanying file MORSE-Copyright.txt for details.
  66. #
  67. # This software is distributed WITHOUT ANY WARRANTY; without even the
  68. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  69. # See the License for more information.
  70. #=============================================================================
  71. # (To distribute this file outside of Morse, substitute the full
  72. # License text for the above reference.)
  73. if (NOT PASTIX_FOUND)
  74. set(PASTIX_DIR "" CACHE PATH "Installation directory of PASTIX library")
  75. if (NOT PASTIX_FIND_QUIETLY)
  76. message(STATUS "A cache variable, namely PASTIX_DIR, has been set to specify the install directory of PASTIX")
  77. endif()
  78. endif()
  79. # Set the version to find
  80. set(PASTIX_LOOK_FOR_MPI ON)
  81. set(PASTIX_LOOK_FOR_SEQ OFF)
  82. set(PASTIX_LOOK_FOR_STARPU OFF)
  83. set(PASTIX_LOOK_FOR_STARPU_CUDA OFF)
  84. set(PASTIX_LOOK_FOR_STARPU_FXT OFF)
  85. set(PASTIX_LOOK_FOR_SCOTCH ON)
  86. set(PASTIX_LOOK_FOR_PTSCOTCH OFF)
  87. set(PASTIX_LOOK_FOR_METIS OFF)
  88. if( PASTIX_FIND_COMPONENTS )
  89. foreach( component ${PASTIX_FIND_COMPONENTS} )
  90. if (${component} STREQUAL "SEQ")
  91. # means we look for the sequential version of PaStiX (without MPI)
  92. set(PASTIX_LOOK_FOR_SEQ ON)
  93. set(PASTIX_LOOK_FOR_MPI OFF)
  94. endif()
  95. if (${component} STREQUAL "MPI")
  96. # means we look for the MPI version of PaStiX (default)
  97. set(PASTIX_LOOK_FOR_SEQ OFF)
  98. set(PASTIX_LOOK_FOR_MPI ON)
  99. endif()
  100. if (${component} STREQUAL "STARPU")
  101. # means we look for PaStiX with StarPU
  102. set(PASTIX_LOOK_FOR_STARPU ON)
  103. endif()
  104. if (${component} STREQUAL "STARPU_CUDA")
  105. # means we look for PaStiX with StarPU + CUDA
  106. set(PASTIX_LOOK_FOR_STARPU ON)
  107. set(PASTIX_LOOK_FOR_STARPU_CUDA ON)
  108. endif()
  109. if (${component} STREQUAL "STARPU_FXT")
  110. # means we look for PaStiX with StarPU + FxT
  111. set(PASTIX_LOOK_FOR_STARPU_FXT ON)
  112. endif()
  113. if (${component} STREQUAL "SCOTCH")
  114. set(PASTIX_LOOK_FOR_SCOTCH ON)
  115. endif()
  116. if (${component} STREQUAL "PTSCOTCH")
  117. set(PASTIX_LOOK_FOR_PTSCOTCH ON)
  118. endif()
  119. if (${component} STREQUAL "METIS")
  120. set(PASTIX_LOOK_FOR_METIS ON)
  121. endif()
  122. endforeach()
  123. endif()
  124. # Dependencies detection
  125. # ----------------------
  126. # Required dependencies
  127. # ---------------------
  128. include(CMakeFindDependencyMacro)
  129. if (NOT PASTIX_FIND_QUIETLY)
  130. message(STATUS "Looking for PASTIX - Try to detect pthread")
  131. endif()
  132. if (PASTIX_FIND_REQUIRED)
  133. find_dependency(Threads REQUIRED QUIET)
  134. else()
  135. find_dependency(Threads QUIET)
  136. endif()
  137. set(PASTIX_EXTRA_LIBRARIES "")
  138. if( THREADS_FOUND )
  139. list(APPEND PASTIX_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  140. endif ()
  141. # Add math library to the list of extra
  142. # it normally exists on all common systems provided with a C compiler
  143. if (NOT PASTIX_FIND_QUIETLY)
  144. message(STATUS "Looking for PASTIX - Try to detect libm")
  145. endif()
  146. set(PASTIX_M_LIBRARIES "")
  147. if(UNIX OR WIN32)
  148. find_library(
  149. PASTIX_M_m_LIBRARY
  150. NAMES m
  151. )
  152. mark_as_advanced(PASTIX_M_m_LIBRARY)
  153. if (PASTIX_M_m_LIBRARY)
  154. list(APPEND PASTIX_M_LIBRARIES "${PASTIX_M_m_LIBRARY}")
  155. list(APPEND PASTIX_EXTRA_LIBRARIES "${PASTIX_M_m_LIBRARY}")
  156. else()
  157. if (PASTIX_FIND_REQUIRED)
  158. message(FATAL_ERROR "Could NOT find libm on your system."
  159. "Are you sure to a have a C compiler installed?")
  160. endif()
  161. endif()
  162. endif()
  163. # Try to find librt (libposix4 - POSIX.1b Realtime Extensions library)
  164. # on Unix systems except Apple ones because it does not exist on it
  165. if (NOT PASTIX_FIND_QUIETLY)
  166. message(STATUS "Looking for PASTIX - Try to detect librt")
  167. endif()
  168. set(PASTIX_RT_LIBRARIES "")
  169. if(UNIX AND NOT APPLE)
  170. find_library(
  171. PASTIX_RT_rt_LIBRARY
  172. NAMES rt
  173. )
  174. mark_as_advanced(PASTIX_RT_rt_LIBRARY)
  175. if (PASTIX_RT_rt_LIBRARY)
  176. list(APPEND PASTIX_RT_LIBRARIES "${PASTIX_RT_rt_LIBRARY}")
  177. list(APPEND PASTIX_EXTRA_LIBRARIES "${PASTIX_RT_rt_LIBRARY}")
  178. else()
  179. if (PASTIX_FIND_REQUIRED)
  180. message(FATAL_ERROR "Could NOT find librt on your system")
  181. endif()
  182. endif()
  183. endif()
  184. # PASTIX depends on HWLOC
  185. #------------------------
  186. if (NOT PASTIX_FIND_QUIETLY)
  187. message(STATUS "Looking for PASTIX - Try to detect HWLOC")
  188. endif()
  189. if (PASTIX_FIND_REQUIRED)
  190. find_dependency(HWLOC REQUIRED QUIET)
  191. else()
  192. find_dependency(HWLOC QUIET)
  193. endif()
  194. # PASTIX depends on BLAS
  195. #-----------------------
  196. if (NOT PASTIX_FIND_QUIETLY)
  197. message(STATUS "Looking for PASTIX - Try to detect BLAS")
  198. endif()
  199. if (PASTIX_FIND_REQUIRED)
  200. find_dependency(BLASEXT REQUIRED QUIET)
  201. else()
  202. find_dependency(BLASEXT QUIET)
  203. endif()
  204. # Optional dependencies
  205. # ---------------------
  206. # PASTIX may depend on MPI
  207. #-------------------------
  208. if (NOT MPI_FOUND AND PASTIX_LOOK_FOR_MPI)
  209. if (NOT PASTIX_FIND_QUIETLY)
  210. message(STATUS "Looking for PASTIX - Try to detect MPI")
  211. endif()
  212. # allows to use an external mpi compilation by setting compilers with
  213. # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
  214. # at cmake configure
  215. if(NOT MPI_C_COMPILER)
  216. set(MPI_C_COMPILER mpicc)
  217. endif()
  218. if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_MPI)
  219. find_dependency(MPI REQUIRED QUIET)
  220. else()
  221. find_dependency(MPI QUIET)
  222. endif()
  223. if (MPI_FOUND)
  224. mark_as_advanced(MPI_LIBRARY)
  225. mark_as_advanced(MPI_EXTRA_LIBRARY)
  226. endif()
  227. endif ()
  228. # PASTIX may depend on STARPU
  229. #----------------------------
  230. if( NOT STARPU_FOUND AND PASTIX_LOOK_FOR_STARPU)
  231. if (NOT PASTIX_FIND_QUIETLY)
  232. message(STATUS "Looking for PASTIX - Try to detect StarPU")
  233. endif()
  234. set(PASTIX_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
  235. # create list of components in order to make a single call to find_package(starpu...)
  236. # we explicitly need a StarPU version built with hwloc
  237. set(STARPU_COMPONENT_LIST "HWLOC")
  238. # StarPU may depend on MPI
  239. # allows to use an external mpi compilation by setting compilers with
  240. # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
  241. # at cmake configure
  242. if (PASTIX_LOOK_FOR_MPI)
  243. if(NOT MPI_C_COMPILER)
  244. set(MPI_C_COMPILER mpicc)
  245. endif()
  246. list(APPEND STARPU_COMPONENT_LIST "MPI")
  247. endif()
  248. if (PASTIX_LOOK_FOR_STARPU_CUDA)
  249. list(APPEND STARPU_COMPONENT_LIST "CUDA")
  250. endif()
  251. if (PASTIX_LOOK_FOR_STARPU_FXT)
  252. list(APPEND STARPU_COMPONENT_LIST "FXT")
  253. endif()
  254. # set the list of optional dependencies we may discover
  255. if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_STARPU)
  256. find_dependency(STARPU ${PASTIX_STARPU_VERSION} REQUIRED
  257. COMPONENTS ${STARPU_COMPONENT_LIST})
  258. else()
  259. find_dependency(STARPU ${PASTIX_STARPU_VERSION}
  260. COMPONENTS ${STARPU_COMPONENT_LIST})
  261. endif()
  262. endif()
  263. # PASTIX may depends on SCOTCH
  264. #-----------------------------
  265. if (NOT SCOTCH_FOUND AND PASTIX_LOOK_FOR_SCOTCH)
  266. if (NOT PASTIX_FIND_QUIETLY)
  267. message(STATUS "Looking for PASTIX - Try to detect SCOTCH")
  268. endif()
  269. if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_SCOTCH)
  270. find_dependency(SCOTCH REQUIRED QUIET)
  271. else()
  272. find_dependency(SCOTCH QUIET)
  273. endif()
  274. endif()
  275. # PASTIX may depends on PTSCOTCH
  276. #-------------------------------
  277. if (NOT PTSCOTCH_FOUND AND PASTIX_LOOK_FOR_PTSCOTCH)
  278. if (NOT PASTIX_FIND_QUIETLY)
  279. message(STATUS "Looking for PASTIX - Try to detect PTSCOTCH")
  280. endif()
  281. if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_PTSCOTCH)
  282. find_dependency(PTSCOTCH REQUIRED QUIET)
  283. else()
  284. find_dependency(PTSCOTCH QUIET)
  285. endif()
  286. endif()
  287. # PASTIX may depends on METIS
  288. #----------------------------
  289. if (NOT METIS_FOUND AND PASTIX_LOOK_FOR_METIS)
  290. if (NOT PASTIX_FIND_QUIETLY)
  291. message(STATUS "Looking for PASTIX - Try to detect METIS")
  292. endif()
  293. if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_METIS)
  294. find_dependency(METIS REQUIRED QUIET)
  295. else()
  296. find_dependency(METIS QUIET)
  297. endif()
  298. endif()
  299. # Error if pastix required and no partitioning lib found
  300. if (PASTIX_FIND_REQUIRED AND NOT SCOTCH_FOUND AND NOT PTSCOTCH_FOUND AND NOT METIS_FOUND)
  301. message(FATAL_ERROR "Could NOT find any partitioning library on your system"
  302. " (install scotch, ptscotch or metis)")
  303. endif()
  304. # Looking for PaStiX
  305. # ------------------
  306. # Looking for include
  307. # -------------------
  308. # Add system include paths to search include
  309. # ------------------------------------------
  310. unset(_inc_env)
  311. set(ENV_PASTIX_DIR "$ENV{PASTIX_DIR}")
  312. set(ENV_PASTIX_INCDIR "$ENV{PASTIX_INCDIR}")
  313. if(ENV_PASTIX_INCDIR)
  314. list(APPEND _inc_env "${ENV_PASTIX_INCDIR}")
  315. elseif(ENV_PASTIX_DIR)
  316. list(APPEND _inc_env "${ENV_PASTIX_DIR}")
  317. list(APPEND _inc_env "${ENV_PASTIX_DIR}/include")
  318. list(APPEND _inc_env "${ENV_PASTIX_DIR}/include/pastix")
  319. else()
  320. if(WIN32)
  321. string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
  322. else()
  323. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  324. list(APPEND _inc_env "${_path_env}")
  325. string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
  326. list(APPEND _inc_env "${_path_env}")
  327. string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
  328. list(APPEND _inc_env "${_path_env}")
  329. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
  330. list(APPEND _inc_env "${_path_env}")
  331. endif()
  332. endif()
  333. list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  334. list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  335. list(REMOVE_DUPLICATES _inc_env)
  336. # Try to find the pastix header in the given paths
  337. # ---------------------------------------------------
  338. # call cmake macro to find the header path
  339. if(PASTIX_INCDIR)
  340. set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
  341. find_path(PASTIX_pastix.h_DIRS
  342. NAMES pastix.h
  343. HINTS ${PASTIX_INCDIR})
  344. else()
  345. if(PASTIX_DIR)
  346. set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
  347. find_path(PASTIX_pastix.h_DIRS
  348. NAMES pastix.h
  349. HINTS ${PASTIX_DIR}
  350. PATH_SUFFIXES "include" "include/pastix")
  351. else()
  352. set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
  353. find_path(PASTIX_pastix.h_DIRS
  354. NAMES pastix.h
  355. HINTS ${_inc_env}
  356. PATH_SUFFIXES "pastix")
  357. endif()
  358. endif()
  359. mark_as_advanced(PASTIX_pastix.h_DIRS)
  360. # If found, add path to cmake variable
  361. # ------------------------------------
  362. if (PASTIX_pastix.h_DIRS)
  363. set(PASTIX_INCLUDE_DIRS "${PASTIX_pastix.h_DIRS}")
  364. else ()
  365. set(PASTIX_INCLUDE_DIRS "PASTIX_INCLUDE_DIRS-NOTFOUND")
  366. if(NOT PASTIX_FIND_QUIETLY)
  367. message(STATUS "Looking for pastix -- pastix.h not found")
  368. endif()
  369. endif()
  370. # Looking for lib
  371. # ---------------
  372. # Add system library paths to search lib
  373. # --------------------------------------
  374. unset(_lib_env)
  375. set(ENV_PASTIX_LIBDIR "$ENV{PASTIX_LIBDIR}")
  376. if(ENV_PASTIX_LIBDIR)
  377. list(APPEND _lib_env "${ENV_PASTIX_LIBDIR}")
  378. elseif(ENV_PASTIX_DIR)
  379. list(APPEND _lib_env "${ENV_PASTIX_DIR}")
  380. list(APPEND _lib_env "${ENV_PASTIX_DIR}/lib")
  381. else()
  382. if(WIN32)
  383. string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
  384. else()
  385. if(APPLE)
  386. string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
  387. else()
  388. string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
  389. endif()
  390. list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
  391. list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  392. endif()
  393. endif()
  394. list(REMOVE_DUPLICATES _lib_env)
  395. # Try to find the pastix lib in the given paths
  396. # ------------------------------------------------
  397. # create list of libs to find
  398. set(PASTIX_libs_to_find "pastix_murge;pastix")
  399. # call cmake macro to find the lib path
  400. if(PASTIX_LIBDIR)
  401. foreach(pastix_lib ${PASTIX_libs_to_find})
  402. set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
  403. find_library(PASTIX_${pastix_lib}_LIBRARY
  404. NAMES ${pastix_lib}
  405. HINTS ${PASTIX_LIBDIR})
  406. endforeach()
  407. else()
  408. if(PASTIX_DIR)
  409. foreach(pastix_lib ${PASTIX_libs_to_find})
  410. set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
  411. find_library(PASTIX_${pastix_lib}_LIBRARY
  412. NAMES ${pastix_lib}
  413. HINTS ${PASTIX_DIR}
  414. PATH_SUFFIXES lib lib32 lib64)
  415. endforeach()
  416. else()
  417. foreach(pastix_lib ${PASTIX_libs_to_find})
  418. set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
  419. find_library(PASTIX_${pastix_lib}_LIBRARY
  420. NAMES ${pastix_lib}
  421. HINTS ${_lib_env})
  422. endforeach()
  423. endif()
  424. endif()
  425. # If found, add path to cmake variable
  426. # ------------------------------------
  427. foreach(pastix_lib ${PASTIX_libs_to_find})
  428. get_filename_component(${pastix_lib}_lib_path ${PASTIX_${pastix_lib}_LIBRARY} PATH)
  429. # set cmake variables (respects naming convention)
  430. if (PASTIX_LIBRARIES)
  431. list(APPEND PASTIX_LIBRARIES "${PASTIX_${pastix_lib}_LIBRARY}")
  432. else()
  433. set(PASTIX_LIBRARIES "${PASTIX_${pastix_lib}_LIBRARY}")
  434. endif()
  435. if (PASTIX_LIBRARY_DIRS)
  436. list(APPEND PASTIX_LIBRARY_DIRS "${${pastix_lib}_lib_path}")
  437. else()
  438. set(PASTIX_LIBRARY_DIRS "${${pastix_lib}_lib_path}")
  439. endif()
  440. mark_as_advanced(PASTIX_${pastix_lib}_LIBRARY)
  441. endforeach()
  442. # check a function to validate the find
  443. if(PASTIX_LIBRARIES)
  444. set(REQUIRED_LDFLAGS)
  445. set(REQUIRED_INCDIRS)
  446. set(REQUIRED_LIBDIRS)
  447. set(REQUIRED_LIBS)
  448. # PASTIX
  449. if (PASTIX_INCLUDE_DIRS)
  450. set(REQUIRED_INCDIRS "${PASTIX_INCLUDE_DIRS}")
  451. endif()
  452. foreach(libdir ${PASTIX_LIBRARY_DIRS})
  453. if (libdir)
  454. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  455. endif()
  456. endforeach()
  457. set(REQUIRED_LIBS "${PASTIX_LIBRARIES}")
  458. # STARPU
  459. if (PASTIX_LOOK_FOR_STARPU AND STARPU_FOUND)
  460. if (STARPU_INCLUDE_DIRS_DEP)
  461. list(APPEND REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS_DEP}")
  462. elseif (STARPU_INCLUDE_DIRS)
  463. list(APPEND REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS}")
  464. endif()
  465. if(STARPU_LIBRARY_DIRS_DEP)
  466. list(APPEND REQUIRED_LIBDIRS "${STARPU_LIBRARY_DIRS_DEP}")
  467. elseif(STARPU_LIBRARY_DIRS)
  468. list(APPEND REQUIRED_LIBDIRS "${STARPU_LIBRARY_DIRS}")
  469. endif()
  470. if (STARPU_LIBRARIES_DEP)
  471. list(APPEND REQUIRED_LIBS "${STARPU_LIBRARIES_DEP}")
  472. elseif (STARPU_LIBRARIES)
  473. foreach(lib ${STARPU_LIBRARIES})
  474. if (EXISTS ${lib} OR ${lib} MATCHES "^-")
  475. list(APPEND REQUIRED_LIBS "${lib}")
  476. else()
  477. list(APPEND REQUIRED_LIBS "-l${lib}")
  478. endif()
  479. endforeach()
  480. endif()
  481. endif()
  482. # CUDA
  483. if (PASTIX_LOOK_FOR_STARPU_CUDA AND CUDA_FOUND)
  484. if (CUDA_INCLUDE_DIRS)
  485. list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}")
  486. endif()
  487. foreach(libdir ${CUDA_LIBRARY_DIRS})
  488. if (libdir)
  489. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  490. endif()
  491. endforeach()
  492. list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}")
  493. endif()
  494. # MPI
  495. if (PASTIX_LOOK_FOR_MPI AND MPI_FOUND)
  496. if (MPI_C_INCLUDE_PATH)
  497. list(APPEND REQUIRED_INCDIRS "${MPI_C_INCLUDE_PATH}")
  498. endif()
  499. if (MPI_C_LINK_FLAGS)
  500. if (${MPI_C_LINK_FLAGS} MATCHES " -")
  501. string(REGEX REPLACE " -" "-" MPI_C_LINK_FLAGS ${MPI_C_LINK_FLAGS})
  502. endif()
  503. list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
  504. endif()
  505. list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
  506. endif()
  507. # HWLOC
  508. if (HWLOC_FOUND)
  509. if (HWLOC_INCLUDE_DIRS)
  510. list(APPEND REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}")
  511. endif()
  512. foreach(libdir ${HWLOC_LIBRARY_DIRS})
  513. if (libdir)
  514. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  515. endif()
  516. endforeach()
  517. foreach(lib ${HWLOC_LIBRARIES})
  518. if (EXISTS ${lib} OR ${lib} MATCHES "^-")
  519. list(APPEND REQUIRED_LIBS "${lib}")
  520. else()
  521. list(APPEND REQUIRED_LIBS "-l${lib}")
  522. endif()
  523. endforeach()
  524. endif()
  525. # BLAS
  526. if (BLAS_FOUND)
  527. if (BLAS_INCLUDE_DIRS)
  528. list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}")
  529. endif()
  530. foreach(libdir ${BLAS_LIBRARY_DIRS})
  531. if (libdir)
  532. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  533. endif()
  534. endforeach()
  535. list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
  536. if (BLAS_LINKER_FLAGS)
  537. list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
  538. endif()
  539. endif()
  540. # SCOTCH
  541. if (PASTIX_LOOK_FOR_SCOTCH AND SCOTCH_FOUND)
  542. if (SCOTCH_INCLUDE_DIRS)
  543. list(APPEND REQUIRED_INCDIRS "${SCOTCH_INCLUDE_DIRS}")
  544. endif()
  545. foreach(libdir ${SCOTCH_LIBRARY_DIRS})
  546. if (libdir)
  547. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  548. endif()
  549. endforeach()
  550. list(APPEND REQUIRED_LIBS "${SCOTCH_LIBRARIES}")
  551. endif()
  552. # PTSCOTCH
  553. if (PASTIX_LOOK_FOR_PTSCOTCH AND PTSCOTCH_FOUND)
  554. if (PTSCOTCH_INCLUDE_DIRS)
  555. list(APPEND REQUIRED_INCDIRS "${PTSCOTCH_INCLUDE_DIRS}")
  556. endif()
  557. foreach(libdir ${PTSCOTCH_LIBRARY_DIRS})
  558. if (libdir)
  559. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  560. endif()
  561. endforeach()
  562. list(APPEND REQUIRED_LIBS "${PTSCOTCH_LIBRARIES}")
  563. endif()
  564. # METIS
  565. if (PASTIX_LOOK_FOR_METIS AND METIS_FOUND)
  566. if (METIS_INCLUDE_DIRS)
  567. list(APPEND REQUIRED_INCDIRS "${METIS_INCLUDE_DIRS}")
  568. endif()
  569. foreach(libdir ${METIS_LIBRARY_DIRS})
  570. if (libdir)
  571. list(APPEND REQUIRED_LIBDIRS "${libdir}")
  572. endif()
  573. endforeach()
  574. list(APPEND REQUIRED_LIBS "${METIS_LIBRARIES}")
  575. endif()
  576. # Fortran
  577. if (CMAKE_C_COMPILER_ID MATCHES "GNU")
  578. find_library(
  579. FORTRAN_gfortran_LIBRARY
  580. NAMES gfortran
  581. HINTS ${_lib_env}
  582. )
  583. mark_as_advanced(FORTRAN_gfortran_LIBRARY)
  584. if (FORTRAN_gfortran_LIBRARY)
  585. list(APPEND REQUIRED_LIBS "${FORTRAN_gfortran_LIBRARY}")
  586. endif()
  587. elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
  588. find_library(
  589. FORTRAN_ifcore_LIBRARY
  590. NAMES ifcore
  591. HINTS ${_lib_env}
  592. )
  593. mark_as_advanced(FORTRAN_ifcore_LIBRARY)
  594. if (FORTRAN_ifcore_LIBRARY)
  595. list(APPEND REQUIRED_LIBS "${FORTRAN_ifcore_LIBRARY}")
  596. endif()
  597. endif()
  598. # EXTRA LIBS such that pthread, m, rt
  599. list(APPEND REQUIRED_LIBS ${PASTIX_EXTRA_LIBRARIES})
  600. # set required libraries for link
  601. set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
  602. set(CMAKE_REQUIRED_LIBRARIES)
  603. list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
  604. foreach(lib_dir ${REQUIRED_LIBDIRS})
  605. list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
  606. endforeach()
  607. list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
  608. list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
  609. string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
  610. # test link
  611. unset(PASTIX_WORKS CACHE)
  612. include(CheckFunctionExists)
  613. check_function_exists(pastix PASTIX_WORKS)
  614. mark_as_advanced(PASTIX_WORKS)
  615. if(PASTIX_WORKS)
  616. # save link with dependencies
  617. set(PASTIX_LIBRARIES_DEP "${REQUIRED_LIBS}")
  618. set(PASTIX_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
  619. set(PASTIX_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
  620. set(PASTIX_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
  621. list(REMOVE_DUPLICATES PASTIX_LIBRARY_DIRS_DEP)
  622. list(REMOVE_DUPLICATES PASTIX_INCLUDE_DIRS_DEP)
  623. list(REMOVE_DUPLICATES PASTIX_LINKER_FLAGS)
  624. else()
  625. if(NOT PASTIX_FIND_QUIETLY)
  626. message(STATUS "Looking for PASTIX : test of pastix() fails")
  627. message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
  628. message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
  629. message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
  630. message(STATUS "Maybe PASTIX is linked with specific libraries. "
  631. "Have you tried with COMPONENTS (MPI/SEQ, STARPU, STARPU_CUDA, SCOTCH, PTSCOTCH, METIS)? "
  632. "See the explanation in FindPASTIX.cmake.")
  633. endif()
  634. endif()
  635. set(CMAKE_REQUIRED_INCLUDES)
  636. set(CMAKE_REQUIRED_FLAGS)
  637. set(CMAKE_REQUIRED_LIBRARIES)
  638. endif()
  639. if (PASTIX_LIBRARIES)
  640. list(GET PASTIX_LIBRARIES 0 first_lib)
  641. get_filename_component(first_lib_path "${first_lib}" PATH)
  642. if (${first_lib_path} MATCHES "/lib(32|64)?$")
  643. string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
  644. set(PASTIX_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PASTIX library" FORCE)
  645. else()
  646. set(PASTIX_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PASTIX library" FORCE)
  647. endif()
  648. endif()
  649. mark_as_advanced(PASTIX_DIR)
  650. mark_as_advanced(PASTIX_DIR_FOUND)
  651. # check that PASTIX has been found
  652. # ---------------------------------
  653. include(FindPackageHandleStandardArgs)
  654. find_package_handle_standard_args(PASTIX DEFAULT_MSG
  655. PASTIX_LIBRARIES
  656. PASTIX_WORKS)