FindFFTW.cmake 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. # - Find the FFTW library
  2. #
  3. # Original version of this file:
  4. # Copyright (c) 2015, Wenzel Jakob
  5. # https://github.com/wjakob/layerlab/blob/master/cmake/FindFFTW.cmake, commit 4d58bfdc28891b4f9373dfe46239dda5a0b561c6
  6. # Modifications:
  7. # Copyright (c) 2017, Patrick Bos
  8. #
  9. # Usage:
  10. # find_package(FFTW [REQUIRED] [QUIET] [COMPONENTS component1 ... componentX] )
  11. #
  12. # It sets the following variables:
  13. # FFTW_FOUND ... true if fftw is found on the system
  14. # FFTW_[component]_LIB_FOUND ... true if the component is found on the system (see components below)
  15. # FFTW_LIBRARIES ... full paths to all found fftw libraries
  16. # FFTW_[component]_LIB ... full path to one of the components (see below)
  17. # FFTW_INCLUDE_DIRS ... fftw include directory paths
  18. #
  19. # The following variables will be checked by the function
  20. # FFTW_USE_STATIC_LIBS ... if true, only static libraries are found, otherwise both static and shared.
  21. # FFTW_ROOT ... if set, the libraries are exclusively searched
  22. # under this path
  23. #
  24. # This package supports the following components:
  25. # FLOAT_LIB
  26. # DOUBLE_LIB
  27. # LONGDOUBLE_LIB
  28. # FLOAT_THREADS_LIB
  29. # DOUBLE_THREADS_LIB
  30. # LONGDOUBLE_THREADS_LIB
  31. # FLOAT_OPENMP_LIB
  32. # DOUBLE_OPENMP_LIB
  33. # LONGDOUBLE_OPENMP_LIB
  34. #
  35. # TODO (maybe): extend with ExternalProject download + build option
  36. # TODO: put on conda-forge
  37. if( NOT FFTW_ROOT AND DEFINED ENV{FFTWDIR} )
  38. set( FFTW_ROOT $ENV{FFTWDIR} )
  39. endif()
  40. # Check if we can use PkgConfig
  41. find_package(PkgConfig)
  42. #Determine from PKG
  43. if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT )
  44. pkg_check_modules( PKG_FFTW QUIET "fftw3" )
  45. endif()
  46. #Check whether to search static or dynamic libs
  47. set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} )
  48. if( ${FFTW_USE_STATIC_LIBS} )
  49. set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} )
  50. else()
  51. set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} )
  52. endif()
  53. if( FFTW_ROOT )
  54. # find libs
  55. find_library(
  56. FFTW_DOUBLE_LIB
  57. NAMES "fftw3" libfftw3-3
  58. PATHS ${FFTW_ROOT}
  59. PATH_SUFFIXES "lib" "lib64"
  60. NO_DEFAULT_PATH
  61. )
  62. find_library(
  63. FFTW_DOUBLE_THREADS_LIB
  64. NAMES "fftw3_threads"
  65. PATHS ${FFTW_ROOT}
  66. PATH_SUFFIXES "lib" "lib64"
  67. NO_DEFAULT_PATH
  68. )
  69. find_library(
  70. FFTW_DOUBLE_OPENMP_LIB
  71. NAMES "fftw3_omp"
  72. PATHS ${FFTW_ROOT}
  73. PATH_SUFFIXES "lib" "lib64"
  74. NO_DEFAULT_PATH
  75. )
  76. find_library(
  77. FFTW_DOUBLE_MPI_LIB
  78. NAMES "fftw3_mpi"
  79. PATHS ${FFTW_ROOT}
  80. PATH_SUFFIXES "lib" "lib64"
  81. NO_DEFAULT_PATH
  82. )
  83. find_library(
  84. FFTW_FLOAT_LIB
  85. NAMES "fftw3f" libfftw3f-3
  86. PATHS ${FFTW_ROOT}
  87. PATH_SUFFIXES "lib" "lib64"
  88. NO_DEFAULT_PATH
  89. )
  90. find_library(
  91. FFTW_FLOAT_THREADS_LIB
  92. NAMES "fftw3f_threads"
  93. PATHS ${FFTW_ROOT}
  94. PATH_SUFFIXES "lib" "lib64"
  95. NO_DEFAULT_PATH
  96. )
  97. find_library(
  98. FFTW_FLOAT_OPENMP_LIB
  99. NAMES "fftw3f_omp"
  100. PATHS ${FFTW_ROOT}
  101. PATH_SUFFIXES "lib" "lib64"
  102. NO_DEFAULT_PATH
  103. )
  104. find_library(
  105. FFTW_FLOAT_MPI_LIB
  106. NAMES "fftw3f_mpi"
  107. PATHS ${FFTW_ROOT}
  108. PATH_SUFFIXES "lib" "lib64"
  109. NO_DEFAULT_PATH
  110. )
  111. find_library(
  112. FFTW_LONGDOUBLE_LIB
  113. NAMES "fftw3l" libfftw3l-3
  114. PATHS ${FFTW_ROOT}
  115. PATH_SUFFIXES "lib" "lib64"
  116. NO_DEFAULT_PATH
  117. )
  118. find_library(
  119. FFTW_LONGDOUBLE_THREADS_LIB
  120. NAMES "fftw3l_threads"
  121. PATHS ${FFTW_ROOT}
  122. PATH_SUFFIXES "lib" "lib64"
  123. NO_DEFAULT_PATH
  124. )
  125. find_library(
  126. FFTW_LONGDOUBLE_OPENMP_LIB
  127. NAMES "fftw3l_omp"
  128. PATHS ${FFTW_ROOT}
  129. PATH_SUFFIXES "lib" "lib64"
  130. NO_DEFAULT_PATH
  131. )
  132. find_library(
  133. FFTW_LONGDOUBLE_MPI_LIB
  134. NAMES "fftw3l_mpi"
  135. PATHS ${FFTW_ROOT}
  136. PATH_SUFFIXES "lib" "lib64"
  137. NO_DEFAULT_PATH
  138. )
  139. #find includes
  140. find_path(FFTW_INCLUDE_DIRS
  141. NAMES "fftw3.h"
  142. PATHS ${FFTW_ROOT}
  143. PATH_SUFFIXES "include"
  144. NO_DEFAULT_PATH
  145. )
  146. else()
  147. find_library(
  148. FFTW_DOUBLE_LIB
  149. NAMES "fftw3"
  150. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  151. )
  152. find_library(
  153. FFTW_DOUBLE_THREADS_LIB
  154. NAMES "fftw3_threads"
  155. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  156. )
  157. find_library(
  158. FFTW_DOUBLE_OPENMP_LIB
  159. NAMES "fftw3_omp"
  160. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  161. )
  162. find_library(
  163. FFTW_DOUBLE_MPI_LIB
  164. NAMES "fftw3_mpi"
  165. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  166. )
  167. find_library(
  168. FFTW_FLOAT_LIB
  169. NAMES "fftw3f"
  170. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  171. )
  172. find_library(
  173. FFTW_FLOAT_THREADS_LIB
  174. NAMES "fftw3f_threads"
  175. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  176. )
  177. find_library(
  178. FFTW_FLOAT_OPENMP_LIB
  179. NAMES "fftw3f_omp"
  180. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  181. )
  182. find_library(
  183. FFTW_FLOAT_MPI_LIB
  184. NAMES "fftw3f_mpi"
  185. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  186. )
  187. find_library(
  188. FFTW_LONGDOUBLE_LIB
  189. NAMES "fftw3l"
  190. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  191. )
  192. find_library(
  193. FFTW_LONGDOUBLE_THREADS_LIB
  194. NAMES "fftw3l_threads"
  195. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  196. )
  197. find_library(FFTW_LONGDOUBLE_OPENMP_LIB
  198. NAMES "fftw3l_omp"
  199. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  200. )
  201. find_library(FFTW_LONGDOUBLE_MPI_LIB
  202. NAMES "fftw3l_mpi"
  203. PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
  204. )
  205. find_path(FFTW_INCLUDE_DIRS
  206. NAMES "fftw3.h"
  207. PATHS ${PKG_FFTW_INCLUDE_DIRS} ${INCLUDE_INSTALL_DIR}
  208. )
  209. endif( FFTW_ROOT )
  210. #--------------------------------------- components
  211. if (FFTW_DOUBLE_LIB)
  212. set(FFTW_DOUBLE_LIB_FOUND TRUE)
  213. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_LIB})
  214. add_library(FFTW::Double INTERFACE IMPORTED)
  215. set_target_properties(FFTW::Double
  216. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  217. INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_LIB}"
  218. )
  219. else()
  220. set(FFTW_DOUBLE_LIB_FOUND FALSE)
  221. endif()
  222. if (FFTW_FLOAT_LIB)
  223. set(FFTW_FLOAT_LIB_FOUND TRUE)
  224. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_LIB})
  225. add_library(FFTW::Float INTERFACE IMPORTED)
  226. set_target_properties(FFTW::Float
  227. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  228. INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_LIB}"
  229. )
  230. else()
  231. set(FFTW_FLOAT_LIB_FOUND FALSE)
  232. endif()
  233. if (FFTW_LONGDOUBLE_LIB)
  234. set(FFTW_LONGDOUBLE_LIB_FOUND TRUE)
  235. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_LIB})
  236. add_library(FFTW::LongDouble INTERFACE IMPORTED)
  237. set_target_properties(FFTW::LongDouble
  238. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  239. INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_LIB}"
  240. )
  241. else()
  242. set(FFTW_LONGDOUBLE_LIB_FOUND FALSE)
  243. endif()
  244. if (FFTW_DOUBLE_THREADS_LIB)
  245. set(FFTW_DOUBLE_THREADS_LIB_FOUND TRUE)
  246. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_THREADS_LIB})
  247. add_library(FFTW::DoubleThreads INTERFACE IMPORTED)
  248. set_target_properties(FFTW::DoubleThreads
  249. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  250. INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_THREADS_LIB}"
  251. )
  252. else()
  253. set(FFTW_DOUBLE_THREADS_LIB_FOUND FALSE)
  254. endif()
  255. if (FFTW_FLOAT_THREADS_LIB)
  256. set(FFTW_FLOAT_THREADS_LIB_FOUND TRUE)
  257. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_THREADS_LIB})
  258. add_library(FFTW::FloatThreads INTERFACE IMPORTED)
  259. set_target_properties(FFTW::FloatThreads
  260. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  261. INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_THREADS_LIB}"
  262. )
  263. else()
  264. set(FFTW_FLOAT_THREADS_LIB_FOUND FALSE)
  265. endif()
  266. if (FFTW_LONGDOUBLE_THREADS_LIB)
  267. set(FFTW_LONGDOUBLE_THREADS_LIB_FOUND TRUE)
  268. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_THREADS_LIB})
  269. add_library(FFTW::LongDoubleThreads INTERFACE IMPORTED)
  270. set_target_properties(FFTW::LongDoubleThreads
  271. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  272. INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_THREADS_LIB}"
  273. )
  274. else()
  275. set(FFTW_LONGDOUBLE_THREADS_LIB_FOUND FALSE)
  276. endif()
  277. if (FFTW_DOUBLE_OPENMP_LIB)
  278. set(FFTW_DOUBLE_OPENMP_LIB_FOUND TRUE)
  279. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_OPENMP_LIB})
  280. add_library(FFTW::DoubleOpenMP INTERFACE IMPORTED)
  281. set_target_properties(FFTW::DoubleOpenMP
  282. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  283. INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_OPENMP_LIB}"
  284. )
  285. else()
  286. set(FFTW_DOUBLE_OPENMP_LIB_FOUND FALSE)
  287. endif()
  288. if (FFTW_FLOAT_OPENMP_LIB)
  289. set(FFTW_FLOAT_OPENMP_LIB_FOUND TRUE)
  290. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_OPENMP_LIB})
  291. add_library(FFTW::FloatOpenMP INTERFACE IMPORTED)
  292. set_target_properties(FFTW::FloatOpenMP
  293. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  294. INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_OPENMP_LIB}"
  295. )
  296. else()
  297. set(FFTW_FLOAT_OPENMP_LIB_FOUND FALSE)
  298. endif()
  299. if (FFTW_LONGDOUBLE_OPENMP_LIB)
  300. set(FFTW_LONGDOUBLE_OPENMP_LIB_FOUND TRUE)
  301. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_OPENMP_LIB})
  302. add_library(FFTW::LongDoubleOpenMP INTERFACE IMPORTED)
  303. set_target_properties(FFTW::LongDoubleOpenMP
  304. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  305. INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_OPENMP_LIB}"
  306. )
  307. else()
  308. set(FFTW_LONGDOUBLE_OPENMP_LIB_FOUND FALSE)
  309. endif()
  310. if (FFTW_DOUBLE_MPI_LIB)
  311. set(FFTW_DOUBLE_MPI_LIB_FOUND TRUE)
  312. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_DOUBLE_MPI_LIB})
  313. add_library(FFTW::DoubleMPI INTERFACE IMPORTED)
  314. set_target_properties(FFTW::DoubleMPI
  315. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  316. INTERFACE_LINK_LIBRARIES "${FFTW_DOUBLE_MPI_LIB}"
  317. )
  318. else()
  319. set(FFTW_DOUBLE_MPI_LIB_FOUND FALSE)
  320. endif()
  321. if (FFTW_FLOAT_MPI_LIB)
  322. set(FFTW_FLOAT_MPI_LIB_FOUND TRUE)
  323. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_FLOAT_MPI_LIB})
  324. add_library(FFTW::FloatMPI INTERFACE IMPORTED)
  325. set_target_properties(FFTW::FloatMPI
  326. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  327. INTERFACE_LINK_LIBRARIES "${FFTW_FLOAT_MPI_LIB}"
  328. )
  329. else()
  330. set(FFTW_FLOAT_MPI_LIB_FOUND FALSE)
  331. endif()
  332. if (FFTW_LONGDOUBLE_MPI_LIB)
  333. set(FFTW_LONGDOUBLE_MPI_LIB_FOUND TRUE)
  334. set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LONGDOUBLE_MPI_LIB})
  335. add_library(FFTW::LongDoubleMPI INTERFACE IMPORTED)
  336. set_target_properties(FFTW::LongDoubleMPI
  337. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIRS}"
  338. INTERFACE_LINK_LIBRARIES "${FFTW_LONGDOUBLE_MPI_LIB}"
  339. )
  340. else()
  341. set(FFTW_LONGDOUBLE_MPI_LIB_FOUND FALSE)
  342. endif()
  343. #--------------------------------------- end components
  344. set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} )
  345. include(FindPackageHandleStandardArgs)
  346. find_package_handle_standard_args(FFTW
  347. REQUIRED_VARS FFTW_INCLUDE_DIRS
  348. HANDLE_COMPONENTS
  349. )
  350. mark_as_advanced(
  351. FFTW_INCLUDE_DIRS
  352. FFTW_LIBRARIES
  353. FFTW_FLOAT_LIB
  354. FFTW_DOUBLE_LIB
  355. FFTW_LONGDOUBLE_LIB
  356. FFTW_FLOAT_THREADS_LIB
  357. FFTW_DOUBLE_THREADS_LIB
  358. FFTW_LONGDOUBLE_THREADS_LIB
  359. FFTW_FLOAT_OPENMP_LIB
  360. FFTW_DOUBLE_OPENMP_LIB
  361. FFTW_LONGDOUBLE_OPENMP_LIB
  362. FFTW_FLOAT_MPI_LIB
  363. FFTW_DOUBLE_MPI_LIB
  364. FFTW_LONGDOUBLE_MPI_LIB
  365. )