Main Lemma Repository
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.

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