1 # - Find FFTW 2/3 single double
2 # Find the native FFTW headers and libraries.
4 # FFTW_INCLUDE_DIRS - where to find FFTW headers
5 # FFTW_LIBRARIES - List of libraries when using FFTW.
6 # FFTW_PKG - The name of the pkg-config package needed
7 # FFTW_FOUND - True if FFTW was found
9 # This file is part of Gromacs Copyright (c) 2012
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # To help us fund GROMACS development, we humbly ask that you cite
17 # the research papers on the package. Check out http://www.gromacs.org
19 find_package(PkgConfig)
20 list(LENGTH FFTW_FIND_COMPONENTS FFTW_NUM_COMPONENTS_WANTED)
21 if(${FFTW_NUM_COMPONENTS_WANTED} LESS 1)
22 message(FATAL_ERROR "No FFTW component to search given")
23 elseif(${FFTW_NUM_COMPONENTS_WANTED} GREATER 1)
24 message(FATAL_ERROR "We only support finding one FFTW component at the time, go and implement it ;-)")
25 elseif(${FFTW_FIND_COMPONENTS} MATCHES "^fftw(f)?$")
26 if (${FFTW_FIND_VERSION} EQUAL 3 OR NOT FFTW_FIND_VERSION) #find FFTW3 by default
27 string(REGEX REPLACE "fftw" "fftw3" FFTW_PKG "${FFTW_FIND_COMPONENTS}")
28 set(FFTW_HEADER "fftw3.h")
29 set(FFTW_FUNCTION "${FFTW_FIND_COMPONENTS}_plan_r2r_1d")
30 #elseif(${FFTW_FIND_VERSION} EQUAL 2)
31 # set(FFTW_PKG "${FFTW_FIND_COMPONENTS}")
32 # set(FFTW_HEADER "${FFTW_FIND_COMPONENTS}.h")
34 message(FATAL_ERROR "We only support finding FFTW version 3, go and implement it ;-)")
37 message(FATAL_ERROR "We do not support finding ${FFTW_FIND_COMPONENTS}, go and implement it ;-)")
40 pkg_check_modules(PC_FFTW "${FFTW_PKG}")
41 find_path(FFTW_INCLUDE_DIR_${FFTW_PKG} "${FFTW_HEADER}" HINTS ${PC_FFTW_INCLUDE_DIRS})
43 find_library(FFTW_LIBRARY_${FFTW_PKG} NAMES "${FFTW_PKG}" HINTS ${PC_FFTW_LIBRARY_DIRS} )
45 #do that so that the user can use FFTW_LIBRARY, FFTW_INCLUDE_DIR to provide custom stuff
46 set(FFTW_LIBRARY ${FFTW_LIBRARY_${FFTW_PKG}} CACHE STRING "Path to library ${FFTW_PKG}")
47 set(FFTW_INCLUDE_DIR ${FFTW_INCLUDE_DIR_${FFTW_PKG}} CACHE STRING "Path to ${FFTW_HEADER}")
49 set(FFTW_LIBRARIES ${FFTW_LIBRARY} )
50 set(FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR} )
52 include(FindPackageHandleStandardArgs)
53 # handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE
54 # if all listed variables are TRUE
56 find_package_handle_standard_args(FFTW DEFAULT_MSG FFTW_LIBRARY FFTW_INCLUDE_DIR )
58 if (FFTW_FOUND AND HAVE_LIBM)
59 include(CheckLibraryExists)
60 #adding MATH_LIBRARIES here to allow static libs, this does not harm us as we are anyway using it
61 check_library_exists("${FFTW_LIBRARIES};m" "${FFTW_FUNCTION}" "" FOUND_FFTW_PLAN)
62 if(NOT FOUND_FFTW_PLAN)
63 message(FATAL_ERROR "Could not find ${FFTW_FUNCTION} in ${FFTW_LIBRARY}, take a look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what was going wrong. If you are using a static lib (.a) make sure you have specified all dependencies of ${FFTW_PKG} in FFTW_LIBRARY by hand (e.g. -DFFTW_LIBRARY='/path/to/lib${FFTW_PKG}.so;/path/to/libm.so') !")
64 endif(NOT FOUND_FFTW_PLAN)
65 endif (FFTW_FOUND AND HAVE_LIBM)
67 mark_as_advanced(FFTW_INCLUDE_DIR FFTW_LIBRARY )