Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FindPTSCOTCH.cmake 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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-2016 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 PTSCOTCH include dirs and libraries
  12. # Use this module by invoking find_package with the form:
  13. # find_package(PTSCOTCH
  14. # [REQUIRED] # Fail with error if ptscotch is not found
  15. # [COMPONENTS <comp1> <comp2> ...] # dependencies
  16. # )
  17. #
  18. # PTSCOTCH depends on the following libraries:
  19. # - Threads
  20. # - MPI
  21. #
  22. # COMPONENTS can be some of the following:
  23. # - ESMUMPS: to activate detection of PT-Scotch with the esmumps interface
  24. #
  25. # This module finds headers and ptscotch library.
  26. # Results are reported in variables:
  27. # PTSCOTCH_FOUND - True if headers and requested libraries were found
  28. # PTSCOTCH_LINKER_FLAGS - list of required linker flags (excluding -l and -L)
  29. # PTSCOTCH_INCLUDE_DIRS - ptscotch include directories
  30. # PTSCOTCH_LIBRARY_DIRS - Link directories for ptscotch libraries
  31. # PTSCOTCH_LIBRARIES - ptscotch component libraries to be linked
  32. # PTSCOTCH_INCLUDE_DIRS_DEP - ptscotch + dependencies include directories
  33. # PTSCOTCH_LIBRARY_DIRS_DEP - ptscotch + dependencies link directories
  34. # PTSCOTCH_LIBRARIES_DEP - ptscotch libraries + dependencies
  35. # PTSCOTCH_INTSIZE - Number of octets occupied by a SCOTCH_Num
  36. #
  37. # The user can give specific paths where to find the libraries adding cmake
  38. # options at configure (ex: cmake path/to/project -DPTSCOTCH=path/to/ptscotch):
  39. # PTSCOTCH_DIR - Where to find the base directory of ptscotch
  40. # PTSCOTCH_INCDIR - Where to find the header files
  41. # PTSCOTCH_LIBDIR - Where to find the library files
  42. # The module can also look for the following environment variables if paths
  43. # are not given as cmake variable: PTSCOTCH_DIR, PTSCOTCH_INCDIR, PTSCOTCH_LIBDIR
  44. #=============================================================================
  45. # Copyright 2012-2013 Inria
  46. # Copyright 2012-2013 Emmanuel Agullo
  47. # Copyright 2012-2013 Mathieu Faverge
  48. # Copyright 2012 Cedric Castagnede
  49. # Copyright 2013-2016 Florent Pruvost
  50. #
  51. # Distributed under the OSI-approved BSD License (the "License");
  52. # see accompanying file MORSE-Copyright.txt for details.
  53. #
  54. # This software is distributed WITHOUT ANY WARRANTY; without even the
  55. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  56. # See the License for more information.
  57. #=============================================================================
  58. # (To distribute this file outside of Morse, substitute the full
  59. # License text for the above reference.)
  60. if (NOT PTSCOTCH_FOUND)
  61. set(PTSCOTCH_DIR "" CACHE PATH "Installation directory of PTSCOTCH library")
  62. if (NOT PTSCOTCH_FIND_QUIETLY)
  63. message(STATUS "A cache variable, namely PTSCOTCH_DIR, has been set to specify the install directory of PTSCOTCH")
  64. endif()
  65. endif()
  66. # Set the version to find
  67. set(PTSCOTCH_LOOK_FOR_ESMUMPS OFF)
  68. if( PTSCOTCH_FIND_COMPONENTS )
  69. foreach( component ${PTSCOTCH_FIND_COMPONENTS} )
  70. if (${component} STREQUAL "ESMUMPS")
  71. # means we look for esmumps library
  72. set(PTSCOTCH_LOOK_FOR_ESMUMPS ON)
  73. endif()
  74. endforeach()
  75. endif()
  76. # PTSCOTCH depends on Threads, try to find it
  77. if (NOT THREADS_FOUND)
  78. if (PTSCOTCH_FIND_REQUIRED)
  79. find_package(Threads REQUIRED)
  80. else()
  81. find_package(Threads)
  82. endif()
  83. endif()
  84. # PTSCOTCH depends on MPI, try to find it
  85. if (NOT MPI_FOUND)
  86. if (PTSCOTCH_FIND_REQUIRED)
  87. find_package(MPI REQUIRED)
  88. else()
  89. find_package(MPI)
  90. endif()
  91. endif()
  92. # Looking for include
  93. # -------------------
  94. # Add system include paths to search include
  95. # ------------------------------------------
  96. unset(_inc_env)
  97. set(ENV_PTSCOTCH_DIR "$ENV{PTSCOTCH_DIR}")
  98. set(ENV_PTSCOTCH_INCDIR "$ENV{PTSCOTCH_INCDIR}")
  99. if(ENV_PTSCOTCH_INCDIR)
  100. list(APPEND _inc_env "${ENV_PTSCOTCH_INCDIR}")
  101. elseif(ENV_PTSCOTCH_DIR)
  102. list(APPEND _inc_env "${ENV_PTSCOTCH_DIR}")
  103. list(APPEND _inc_env "${ENV_PTSCOTCH_DIR}/include")
  104. list(APPEND _inc_env "${ENV_PTSCOTCH_DIR}/include/ptscotch")
  105. else()
  106. if(WIN32)
  107. string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
  108. else()
  109. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  110. list(APPEND _inc_env "${_path_env}")
  111. string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
  112. list(APPEND _inc_env "${_path_env}")
  113. string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
  114. list(APPEND _inc_env "${_path_env}")
  115. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
  116. list(APPEND _inc_env "${_path_env}")
  117. endif()
  118. endif()
  119. list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  120. list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  121. list(REMOVE_DUPLICATES _inc_env)
  122. # Try to find the ptscotch header in the given paths
  123. # -------------------------------------------------
  124. set(PTSCOTCH_hdrs_to_find "ptscotch.h;scotch.h")
  125. # call cmake macro to find the header path
  126. if(PTSCOTCH_INCDIR)
  127. foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
  128. set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND")
  129. find_path(PTSCOTCH_${ptscotch_hdr}_DIRS
  130. NAMES ${ptscotch_hdr}
  131. HINTS ${PTSCOTCH_INCDIR})
  132. mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS)
  133. endforeach()
  134. else()
  135. if(PTSCOTCH_DIR)
  136. foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
  137. set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND")
  138. find_path(PTSCOTCH_${ptscotch_hdr}_DIRS
  139. NAMES ${ptscotch_hdr}
  140. HINTS ${PTSCOTCH_DIR}
  141. PATH_SUFFIXES "include" "include/scotch")
  142. mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS)
  143. endforeach()
  144. else()
  145. foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
  146. set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND")
  147. find_path(PTSCOTCH_${ptscotch_hdr}_DIRS
  148. NAMES ${ptscotch_hdr}
  149. HINTS ${_inc_env}
  150. PATH_SUFFIXES "scotch")
  151. mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS)
  152. endforeach()
  153. endif()
  154. endif()
  155. # If found, add path to cmake variable
  156. # ------------------------------------
  157. foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
  158. if (PTSCOTCH_${ptscotch_hdr}_DIRS)
  159. list(APPEND PTSCOTCH_INCLUDE_DIRS "${PTSCOTCH_${ptscotch_hdr}_DIRS}")
  160. else ()
  161. set(PTSCOTCH_INCLUDE_DIRS "PTSCOTCH_INCLUDE_DIRS-NOTFOUND")
  162. if (NOT PTSCOTCH_FIND_QUIETLY)
  163. message(STATUS "Looking for ptscotch -- ${ptscotch_hdr} not found")
  164. endif()
  165. endif()
  166. endforeach()
  167. list(REMOVE_DUPLICATES PTSCOTCH_INCLUDE_DIRS)
  168. # Looking for lib
  169. # ---------------
  170. # Add system library paths to search lib
  171. # --------------------------------------
  172. unset(_lib_env)
  173. set(ENV_PTSCOTCH_LIBDIR "$ENV{PTSCOTCH_LIBDIR}")
  174. if(ENV_PTSCOTCH_LIBDIR)
  175. list(APPEND _lib_env "${ENV_PTSCOTCH_LIBDIR}")
  176. elseif(ENV_PTSCOTCH_DIR)
  177. list(APPEND _lib_env "${ENV_PTSCOTCH_DIR}")
  178. list(APPEND _lib_env "${ENV_PTSCOTCH_DIR}/lib")
  179. else()
  180. if(WIN32)
  181. string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
  182. else()
  183. if(APPLE)
  184. string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
  185. else()
  186. string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
  187. endif()
  188. list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
  189. list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  190. endif()
  191. endif()
  192. list(REMOVE_DUPLICATES _lib_env)
  193. # Try to find the ptscotch lib in the given paths
  194. # ----------------------------------------------
  195. set(PTSCOTCH_libs_to_find "ptscotch;ptscotcherr")
  196. if (PTSCOTCH_LOOK_FOR_ESMUMPS)
  197. list(INSERT PTSCOTCH_libs_to_find 0 "ptesmumps")
  198. list(APPEND PTSCOTCH_libs_to_find "esmumps" )
  199. endif()
  200. list(APPEND PTSCOTCH_libs_to_find "scotch;scotcherr")
  201. # call cmake macro to find the lib path
  202. if(PTSCOTCH_LIBDIR)
  203. foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
  204. set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND")
  205. find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY
  206. NAMES ${ptscotch_lib}
  207. HINTS ${PTSCOTCH_LIBDIR})
  208. endforeach()
  209. else()
  210. if(PTSCOTCH_DIR)
  211. foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
  212. set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND")
  213. find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY
  214. NAMES ${ptscotch_lib}
  215. HINTS ${PTSCOTCH_DIR}
  216. PATH_SUFFIXES lib lib32 lib64)
  217. endforeach()
  218. else()
  219. foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
  220. set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND")
  221. find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY
  222. NAMES ${ptscotch_lib}
  223. HINTS ${_lib_env})
  224. endforeach()
  225. endif()
  226. endif()
  227. set(PTSCOTCH_LIBRARIES "")
  228. set(PTSCOTCH_LIBRARY_DIRS "")
  229. # If found, add path to cmake variable
  230. # ------------------------------------
  231. foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
  232. if (PTSCOTCH_${ptscotch_lib}_LIBRARY)
  233. get_filename_component(${ptscotch_lib}_lib_path "${PTSCOTCH_${ptscotch_lib}_LIBRARY}" PATH)
  234. # set cmake variables
  235. list(APPEND PTSCOTCH_LIBRARIES "${PTSCOTCH_${ptscotch_lib}_LIBRARY}")
  236. list(APPEND PTSCOTCH_LIBRARY_DIRS "${${ptscotch_lib}_lib_path}")
  237. else ()
  238. list(APPEND PTSCOTCH_LIBRARIES "${PTSCOTCH_${ptscotch_lib}_LIBRARY}")
  239. if (NOT PTSCOTCH_FIND_QUIETLY)
  240. message(STATUS "Looking for ptscotch -- lib ${ptscotch_lib} not found")
  241. endif()
  242. endif ()
  243. mark_as_advanced(PTSCOTCH_${ptscotch_lib}_LIBRARY)
  244. endforeach()
  245. list(REMOVE_DUPLICATES PTSCOTCH_LIBRARY_DIRS)
  246. # check a function to validate the find
  247. if(PTSCOTCH_LIBRARIES)
  248. set(REQUIRED_LDFLAGS)
  249. set(REQUIRED_INCDIRS)
  250. set(REQUIRED_LIBDIRS)
  251. set(REQUIRED_LIBS)
  252. # PTSCOTCH
  253. if (PTSCOTCH_INCLUDE_DIRS)
  254. set(REQUIRED_INCDIRS "${PTSCOTCH_INCLUDE_DIRS}")
  255. endif()
  256. if (PTSCOTCH_LIBRARY_DIRS)
  257. set(REQUIRED_LIBDIRS "${PTSCOTCH_LIBRARY_DIRS}")
  258. endif()
  259. set(REQUIRED_LIBS "${PTSCOTCH_LIBRARIES}")
  260. # MPI
  261. if (MPI_FOUND)
  262. if (MPI_C_INCLUDE_PATH)
  263. list(APPEND CMAKE_REQUIRED_INCLUDES "${MPI_C_INCLUDE_PATH}")
  264. endif()
  265. if (MPI_C_LINK_FLAGS)
  266. if (${MPI_C_LINK_FLAGS} MATCHES " -")
  267. string(REGEX REPLACE " -" "-" MPI_C_LINK_FLAGS ${MPI_C_LINK_FLAGS})
  268. endif()
  269. list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
  270. endif()
  271. list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
  272. endif()
  273. # THREADS
  274. if(CMAKE_THREAD_LIBS_INIT)
  275. list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT}")
  276. endif()
  277. set(Z_LIBRARY "Z_LIBRARY-NOTFOUND")
  278. find_library(Z_LIBRARY NAMES z)
  279. mark_as_advanced(Z_LIBRARY)
  280. if(Z_LIBRARY)
  281. list(APPEND REQUIRED_LIBS "-lz")
  282. endif()
  283. set(M_LIBRARY "M_LIBRARY-NOTFOUND")
  284. find_library(M_LIBRARY NAMES m)
  285. mark_as_advanced(M_LIBRARY)
  286. if(M_LIBRARY)
  287. list(APPEND REQUIRED_LIBS "-lm")
  288. endif()
  289. set(RT_LIBRARY "RT_LIBRARY-NOTFOUND")
  290. find_library(RT_LIBRARY NAMES rt)
  291. mark_as_advanced(RT_LIBRARY)
  292. if(RT_LIBRARY)
  293. list(APPEND REQUIRED_LIBS "-lrt")
  294. endif()
  295. # set required libraries for link
  296. set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
  297. set(CMAKE_REQUIRED_LIBRARIES)
  298. list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
  299. foreach(lib_dir ${REQUIRED_LIBDIRS})
  300. list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
  301. endforeach()
  302. list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
  303. list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
  304. string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
  305. # test link
  306. unset(PTSCOTCH_WORKS CACHE)
  307. include(CheckFunctionExists)
  308. check_function_exists(SCOTCH_dgraphInit PTSCOTCH_WORKS)
  309. mark_as_advanced(PTSCOTCH_WORKS)
  310. if(PTSCOTCH_WORKS)
  311. # save link with dependencies
  312. set(PTSCOTCH_LIBRARIES_DEP "${REQUIRED_LIBS}")
  313. set(PTSCOTCH_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
  314. set(PTSCOTCH_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
  315. set(PTSCOTCH_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
  316. list(REMOVE_DUPLICATES PTSCOTCH_LIBRARY_DIRS_DEP)
  317. list(REMOVE_DUPLICATES PTSCOTCH_INCLUDE_DIRS_DEP)
  318. list(REMOVE_DUPLICATES PTSCOTCH_LINKER_FLAGS)
  319. else()
  320. if(NOT PTSCOTCH_FIND_QUIETLY)
  321. message(STATUS "Looking for PTSCOTCH : test of SCOTCH_dgraphInit with PTSCOTCH library fails")
  322. message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
  323. message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
  324. message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
  325. endif()
  326. endif()
  327. set(CMAKE_REQUIRED_INCLUDES)
  328. set(CMAKE_REQUIRED_FLAGS)
  329. set(CMAKE_REQUIRED_LIBRARIES)
  330. endif(PTSCOTCH_LIBRARIES)
  331. if (PTSCOTCH_LIBRARIES)
  332. list(GET PTSCOTCH_LIBRARIES 0 first_lib)
  333. get_filename_component(first_lib_path "${first_lib}" PATH)
  334. if (${first_lib_path} MATCHES "/lib(32|64)?$")
  335. string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
  336. set(PTSCOTCH_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PTSCOTCH library" FORCE)
  337. else()
  338. set(PTSCOTCH_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PTSCOTCH library" FORCE)
  339. endif()
  340. endif()
  341. mark_as_advanced(PTSCOTCH_DIR)
  342. mark_as_advanced(PTSCOTCH_DIR_FOUND)
  343. # Check the size of SCOTCH_Num
  344. # ---------------------------------
  345. set(CMAKE_REQUIRED_INCLUDES ${PTSCOTCH_INCLUDE_DIRS})
  346. include(CheckCSourceRuns)
  347. #stdio.h and stdint.h should be included by scotch.h directly
  348. set(PTSCOTCH_C_TEST_SCOTCH_Num_4 "
  349. #include <stdio.h>
  350. #include <stdint.h>
  351. #include <ptscotch.h>
  352. int main(int argc, char **argv) {
  353. if (sizeof(SCOTCH_Num) == 4)
  354. return 0;
  355. else
  356. return 1;
  357. }
  358. ")
  359. set(PTSCOTCH_C_TEST_SCOTCH_Num_8 "
  360. #include <stdio.h>
  361. #include <stdint.h>
  362. #include <ptscotch.h>
  363. int main(int argc, char **argv) {
  364. if (sizeof(SCOTCH_Num) == 8)
  365. return 0;
  366. else
  367. return 1;
  368. }
  369. ")
  370. check_c_source_runs("${PTSCOTCH_C_TEST_SCOTCH_Num_4}" PTSCOTCH_Num_4)
  371. if(NOT PTSCOTCH_Num_4)
  372. check_c_source_runs("${PTSCOTCH_C_TEST_SCOTCH_Num_8}" PTSCOTCH_Num_8)
  373. if(NOT PTSCOTCH_Num_8)
  374. set(PTSCOTCH_INTSIZE -1)
  375. else()
  376. set(PTSCOTCH_INTSIZE 8)
  377. endif()
  378. else()
  379. set(PTSCOTCH_INTSIZE 4)
  380. endif()
  381. set(CMAKE_REQUIRED_INCLUDES "")
  382. # check that PTSCOTCH has been found
  383. # ---------------------------------
  384. include(FindPackageHandleStandardArgs)
  385. find_package_handle_standard_args(PTSCOTCH DEFAULT_MSG
  386. PTSCOTCH_LIBRARIES
  387. PTSCOTCH_WORKS)
  388. #
  389. # TODO: Add possibility to check for specific functions in the library
  390. #