Autogenerate gromacs.7 from programs.txt
[gromacs.git] / cmake / FindFFTW.cmake
blobf1476adbf1e30015002ec8e61c28102d9ebf48a1
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_HAVE_SSE     - True if FFTW was build with SSE support
8 #  FFTW_FOUND        - True if FFTW was found
10 #  This file is part of Gromacs        Copyright (c) 2012
12 #  This program is free software; you can redistribute it and/or
13 #  modify it under the terms of the GNU General Public License
14 #  as published by the Free Software Foundation; either version 2
15 #  of the License, or (at your option) any later version.
17 #  To help us fund GROMACS development, we humbly ask that you cite
18 #  the research papers on the package. Check out http://www.gromacs.org
20 find_package(PkgConfig)
21 list(LENGTH FFTW_FIND_COMPONENTS FFTW_NUM_COMPONENTS_WANTED)
22 if(${FFTW_NUM_COMPONENTS_WANTED} LESS 1)
23   message(FATAL_ERROR "No FFTW component to search given")
24 elseif(${FFTW_NUM_COMPONENTS_WANTED} GREATER 1)
25   message(FATAL_ERROR "We only support finding one FFTW component at the time, go and implement it ;-)")
26 elseif(${FFTW_FIND_COMPONENTS} MATCHES "^fftw(f)?$")
27   if (${FFTW_FIND_VERSION} EQUAL 3 OR NOT FFTW_FIND_VERSION) #find FFTW3 by default
28     string(REGEX REPLACE "fftw" "fftw3" FFTW_PKG "${FFTW_FIND_COMPONENTS}")
29     set(FFTW_HEADER "fftw3.h")
30     set(FFTW_FUNCTION "${FFTW_FIND_COMPONENTS}_plan_r2r_1d")
31   #elseif(${FFTW_FIND_VERSION} EQUAL 2)
32   #  set(FFTW_PKG "${FFTW_FIND_COMPONENTS}")
33   #  set(FFTW_HEADER "${FFTW_FIND_COMPONENTS}.h")
34   else()
35     message(FATAL_ERROR "We only support finding FFTW version 3, go and implement it ;-)")
36   endif()
37 else()
38   message(FATAL_ERROR "We do not support finding ${FFTW_FIND_COMPONENTS}, go and implement it ;-)")
39 endif()
41 if(NOT __pkg_config_checked_PC_FFTW_${FFTW_PKG})
42   pkg_check_modules(PC_FFTW_${FFTW_PKG} "${FFTW_PKG}")
43 endif(NOT __pkg_config_checked_PC_FFTW_${FFTW_PKG})
45 if(FFTW_LIBRARY)
46   set(FFTW_LIBRARY_${FFTW_PKG} "${FFTW_LIBRARY}" CACHE INTERNAL "Path to ${FFTW_PKG} library" FORCE)
47 endif(FFTW_LIBRARY)
49 if(FFTW_INCLUDE_DIR)
50   set(FFTW_INCLUDE_DIR_${FFTW_PKG} "${FFTW_INCLUDE_DIR}" CACHE INTERNAL "Path to ${FFTW_HEADER}" FORCE)
51 endif(FFTW_INCLUDE_DIR)
53 #we use _${FFTW_PKG} variables to have different cache entries for fftw3 and ffw3f
54 find_path(FFTW_INCLUDE_DIR_${FFTW_PKG} "${FFTW_HEADER}" HINTS ${PC_FFTW_${FFTW_PKG}_INCLUDE_DIRS})
55 find_library(FFTW_LIBRARY_${FFTW_PKG} NAMES "${FFTW_PKG}" HINTS ${PC_FFTW_${FFTW_PKG}_LIBRARY_DIRS})
57 #make _${FFTW_PKG} variables INTERNAL to avoid confusion in cmake-gui
58 set(FFTW_LIBRARY_${FFTW_PKG} ${FFTW_LIBRARY_${FFTW_PKG}} CACHE INTERNAL "Path to ${FFTW_PKG} library" FORCE)
59 set(FFTW_INCLUDE_DIR_${FFTW_PKG} ${FFTW_INCLUDE_DIR_${FFTW_PKG}} CACHE INTERNAL "Path to ${FFTW_HEADER}" FORCE)
61 set(FFTW_LIBRARY "${FFTW_LIBRARY_${FFTW_PKG}}" CACHE FILEPATH "Path to ${FFTW_PKG} library" FORCE)
62 set(FFTW_INCLUDE_DIR "${FFTW_INCLUDE_DIR_${FFTW_PKG}}" CACHE DIRECTORY "Path to ${FFTW_HEADER}" FORCE)
64 # set default find_package outcome variables
65 set(FFTW_LIBRARIES "${FFTW_LIBRARY_${FFTW_PKG}}")
66 set(FFTW_INCLUDE_DIRS "${FFTW_INCLUDE_DIR_${FFTW_PKG}}")
68 set(FFTW_FOUND FALSE)
69 if (FFTW_LIBRARY_${FFTW_PKG} AND FFTW_INCLUDE_DIR_${FFTW_PKG})
70   set(FFTW_FOUND TRUE)
71 elseif (NOT FFTW_LIBRARY_${FFTW_PKG})
72   message("Could not find ${FFTW_PKG} library named lib${FFTW_PKG}, please specify its location in FFTW_LIBRARY by hand (e.g. -DFFTW_LIBRARY='/path/to/lib${FFTW_PKG}.so')")
73 elseif (NOT FFTW_INCLUDE_DIR_${FFTW_PKG})
74   message("Could not the ${FFTW_PKG} header ${FFTW_HEADER}, please specify its path in FFTW_INCLUDE_DIR by hand (e.g. -DFFTW_INCLUDE_DIR='/path/to/include')")
75 endif()
77 set(FFTW_HAVE_SSE FALSE CACHE BOOL "If ${FFTW_PKG} was built with SSE support")
78 if (FFTW_FOUND AND HAVE_LIBM AND NOT "${FFTW_LIBRARY_PREVIOUS}" STREQUAL "${FFTW_LIBRARY}")
79   #The user could specify trash in FFTW_LIBRARY, so test if we can link it
80   include(CheckLibraryExists)
81   #adding MATH_LIBRARIES here to allow static libs, this does not harm us as we are anyway using it
82   set(CMAKE_REQUIRED_LIBRARIES m)
83   unset(FOUND_FFTW_PLAN_${FFTW_PKG} CACHE)
84   check_library_exists("${FFTW_LIBRARIES}" "${FFTW_FUNCTION}" "" FOUND_FFTW_PLAN_${FFTW_PKG})
85   if(NOT FOUND_FFTW_PLAN_${FFTW_PKG})
86     message(FATAL_ERROR "Could not find ${FFTW_FUNCTION} in ${FFTW_LIBRARY_${FFTW_PKG}}, take a look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what went 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') !")
87   endif(NOT FOUND_FFTW_PLAN_${FFTW_PKG})
88   #in 3.3 sse function name has changed
89   foreach(SSE_FCT fftwf_have_simd_sse2;fftw_have_simd_sse2;fftwf_have_sse;fftw_have_sse2)
90     unset(FFTW_HAVE_${SSE_FCT}_${FFTW_PKG} CACHE)
91     check_library_exists("${FFTW_LIBRARIES}" "${SSE_FCT}" "" FFTW_HAVE_${SSE_FCT}_${FFTW_PKG})
92     if(FFTW_HAVE_${SSE_FCT}_${FFTW_PKG})
93       set(FFTW_HAVE_SSE_${FFTW_PKG} "${FFTW_HAVE_${SSE_FCT}_${FFTW_PKG}}")
94       break()
95     endif(FFTW_HAVE_${SSE_FCT}_${FFTW_PKG})
96   endforeach()
97   set(FFTW_HAVE_SSE "${FFTW_HAVE_SSE_${FFTW_PKG}}" CACHE BOOL "If ${FFTW_PKG} was built with SSE support" FORCE)
98   set(CMAKE_REQUIRED_LIBRARIES)
99   set(FFTW_LIBRARY_PREVIOUS "${FFTW_LIBRARY}" CACHE INTERNAL "Value of FFTW_LIBRARY when executing the linking check that last time" FORCE)
100 endif (FFTW_FOUND AND HAVE_LIBM AND NOT "${FFTW_LIBRARY_PREVIOUS}" STREQUAL "${FFTW_LIBRARY}")
102 mark_as_advanced(FFTW_INCLUDE_DIR FFTW_LIBRARY FFTW_HAVE_SSE)