forked from gromacs/gromacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindFFTW.cmake
172 lines (160 loc) · 8.71 KB
/
FindFFTW.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright 2012- The GROMACS Authors
# and the project initiators Erik Lindahl, Berk Hess and David van der Spoel.
# Consult the AUTHORS/COPYING files and https://www.gromacs.org for details.
#
# GROMACS is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# GROMACS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with GROMACS; if not, see
# https://www.gnu.org/licenses, or write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# If you want to redistribute modifications to GROMACS, please
# consider that scientific software is very special. Version
# control is crucial - bugs must be traceable. We will be happy to
# consider code for inclusion in the official distribution, but
# derived work must not be called official GROMACS. Details are found
# in the README & COPYING files - if they are missing, get the
# official version at https://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out https://www.gromacs.org.
# - Find FFTW 3
# Find the native FFTW headers and libraries.
#
# ${FFTW}_INCLUDE_DIRS - where to find FFTW headers
# ${FFTW}_LIBRARIES - List of libraries when using FFTW.
# ${FFTW}_PKG - The name of the pkg-config package needed
# ${FFTW}_HAVE_SIMD - True if FFTW was built with SIMD support
# ${FFTW}_HAVE_SSE - True if FFTW was built with SSE support
# ${FFTW}_HAVE_SSE2 - True if FFTW was built with SSE2 support
# ${FFTW}_FOUND - True if FFTW was found
# where ${FFTW} is FFTW or FFTWF
list(LENGTH FFTW_FIND_COMPONENTS FFTW_NUM_COMPONENTS_WANTED)
if(${FFTW_NUM_COMPONENTS_WANTED} LESS 1)
message(FATAL_ERROR "No FFTW component to search given")
elseif(${FFTW_NUM_COMPONENTS_WANTED} GREATER 1)
message(FATAL_ERROR "We only support finding one FFTW component at the time, go and implement it ;-)")
elseif(${FFTW_FIND_COMPONENTS} MATCHES "^fftw(f)?$")
if (NOT FFTW_FIND_VERSION OR FFTW_FIND_VERSION EQUAL 3) #find FFTW3 by default
string(TOUPPER "${FFTW_FIND_COMPONENTS}" FFTW)
string(REGEX REPLACE "fftw" "fftw3" ${FFTW}_PKG "${FFTW_FIND_COMPONENTS}")
set(${FFTW}_FUNCTION_PREFIX "${FFTW_FIND_COMPONENTS}")
else()
message(FATAL_ERROR "We only support finding FFTW version 3, go and implement it ;-)")
endif()
else()
message(FATAL_ERROR "We do not support finding ${FFTW_FIND_COMPONENTS}, go and implement it ;-)")
endif()
find_package(PkgConfig QUIET)
if(NOT __pkg_config_checked_PC_${FFTW} OR NOT ${FFTW}_LIBRARY)
pkg_check_modules(PC_${FFTW} "${${FFTW}_PKG}")
if(NOT PC_${FFTW}_FOUND)
message(STATUS "pkg-config could not detect ${${FFTW}_PKG}, trying generic detection")
endif()
endif()
find_path(${FFTW}_INCLUDE_DIR "fftw3.h" HINTS ${PC_${FFTW}_INCLUDE_DIRS})
find_library(${FFTW}_LIBRARY NAMES "${${FFTW}_PKG}" HINTS ${PC_${FFTW}_LIBRARY_DIRS})
set(${FFTW}_LIBRARIES "${${FFTW}_LIBRARY}")
set(${FFTW}_INCLUDE_DIRS "${${FFTW}_INCLUDE_DIR}")
#better error message than find_package_handle_standard_args
if (${FFTW}_LIBRARY AND ${FFTW}_INCLUDE_DIR)
set(${FFTW}_FOUND TRUE)
elseif (NOT ${FFTW}_LIBRARY)
message("Could not find ${${FFTW}_PKG} library named lib${${FFTW}_PKG}, please specify its location in CMAKE_PREFIX_PATH or ${FFTW}_LIBRARY by hand (e.g. -D${FFTW}_LIBRARY='/path/to/lib${${FFTW}_PKG}.so')")
elseif (NOT ${FFTW}_INCLUDE_DIR)
message("Could not the ${${FFTW}_PKG} header fftw3.h, please specify its path in ${FFTW}_INCLUDE_DIR by hand (e.g. -D${FFTW}_INCLUDE_DIR='/path/to/include')")
endif()
if (${FFTW}_FOUND)
#The user could specify trash in ${FFTW}_LIBRARY, so test if we can link it
include(CheckLibraryExists)
include(gmxOptionUtilities)
if (LIBM_LIBRARY)
#adding MATH_LIBRARIES here to allow static libs, this does not harm us as we are anyway using it
set(CMAKE_REQUIRED_LIBRARIES ${LIBM_LIBRARY})
endif ()
gmx_check_if_changed(FFTW_LIBRARY_CHANGED ${FFTW}_LIBRARIES)
if (FFTW_LIBRARY_CHANGED)
unset(FOUND_${FFTW}_PLAN CACHE)
endif()
check_library_exists("${${FFTW}_LIBRARIES}" "${${FFTW}_FUNCTION_PREFIX}_plan_many_dft" "" FOUND_${FFTW}_PLAN_MANY)
check_library_exists("${${FFTW}_LIBRARIES}" "${${FFTW}_FUNCTION_PREFIX}_plan_many_dft_r2c" "" FOUND_${FFTW}_PLAN_MANY_R2C)
check_library_exists("${${FFTW}_LIBRARIES}" "${${FFTW}_FUNCTION_PREFIX}_plan_many_dft_c2r" "" FOUND_${FFTW}_PLAN_MANY_C2R)
if(NOT (FOUND_${FFTW}_PLAN_MANY AND
FOUND_${FFTW}_PLAN_MANY_R2C AND
FOUND_${FFTW}_PLAN_MANY_C2R))
message(FATAL_ERROR "Could not find ${${FFTW}_FUNCTION_PREFIX}_plan_many_[r2c|c2r] in ${${FFTW}_LIBRARY}, 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. -D${FFTW}_LIBRARY='/path/to/lib${${FFTW}_PKG}.so;/path/to/libm.so') !")
endif()
if(NOT WIN32) # *_have_* functions aren't external. Thus aren't visible on Windows.
# Check for FFTW3 compiled with --enable-sse
foreach(SSE_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse ${${FFTW}_FUNCTION_PREFIX}_have_sse)
if (FFTW_LIBRARY_CHANGED)
unset(${FFTW}_HAVE_${SSE_FUNCTION} CACHE)
endif()
check_library_exists("${${FFTW}_LIBRARIES}" "${SSE_FUNCTION}" "" ${FFTW}_HAVE_${SSE_FUNCTION})
if(${FFTW}_HAVE_${SSE_FUNCTION})
set(${FFTW}_HAVE_SSE TRUE)
set(${FFTW}_HAVE_SIMD TRUE)
break()
endif()
endforeach()
# Check for FFTW3 compiled with --enable-sse2
foreach(SSE2_FUNCTION ${${FFTW}_FUNCTION_PREFIX}_have_simd_sse2 ${${FFTW}_FUNCTION_PREFIX}_have_sse2)
if (FFTW_LIBRARY_CHANGED)
unset(${FFTW}_HAVE_${SSE2_FUNCTION} CACHE)
endif()
check_library_exists("${${FFTW}_LIBRARIES}" "${SSE2_FUNCTION}" "" ${FFTW}_HAVE_${SSE2_FUNCTION})
if(${FFTW}_HAVE_${SSE2_FUNCTION})
set(${FFTW}_HAVE_SSE2 TRUE)
set(${FFTW}_HAVE_SIMD TRUE)
break()
endif()
endforeach()
# Check for any other SIMD support in FFTW
if (NOT ${FFTW}_HAVE_SIMD)
foreach(SIMD_FCT
${${FFTW}_FUNCTION_PREFIX}_have_simd_avx
${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2
${${FFTW}_FUNCTION_PREFIX}_have_simd_avx2_128
${${FFTW}_FUNCTION_PREFIX}_have_simd_avx512
${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_128_fma
${${FFTW}_FUNCTION_PREFIX}_have_simd_avx_512
${${FFTW}_FUNCTION_PREFIX}_have_simd_kcvi
${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec
${${FFTW}_FUNCTION_PREFIX}_have_simd_neon
${${FFTW}_FUNCTION_PREFIX}_have_simd_vsx
${${FFTW}_FUNCTION_PREFIX}_have_simd_altivec
${${FFTW}_FUNCTION_PREFIX}_have_altivec) # Name used before FFTW 3.3
if (FFTW_LIBRARY_CHANGED)
unset(${FFTW}_HAVE_${SIMD_FCT} CACHE)
endif()
check_library_exists("${${FFTW}_LIBRARIES}" "${SIMD_FCT}" "" ${FFTW}_HAVE_${SIMD_FCT})
if(${FFTW}_HAVE_${SIMD_FCT})
set(${FFTW}_HAVE_SIMD TRUE)
break()
endif()
endforeach()
endif()
endif()
#Verify FFTW is compiled with fPIC (necessary for shared libraries)
if (CMAKE_OBJDUMP AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND BUILD_SHARED_LIBS AND NOT CYGWIN AND NOT APPLE)
execute_process(COMMAND ${CMAKE_OBJDUMP} --reloc ${${FFTW}_LIBRARY} OUTPUT_VARIABLE ${FFTW}_OBJDUMP)
if (${${FFTW}_OBJDUMP} MATCHES "R_X86_64" #Should always be true for static libraries. Checks that objdump works properly and that the library isn't dynamic
AND NOT ${${FFTW}_OBJDUMP} MATCHES "R_X86_64_PLT32")
message(FATAL_ERROR "The FFTW library ${${FFTW}_LIBRARY} cannot be used with shared libraries. Provide a different FFTW library by setting ${FFTW}_LIBRARY. If you don't have a different one, recompile FFTW with \"--enable-shared\" or \"--with-pic\". Or disable shared libraries for GROMACS by setting BUILD_SHARED_LIBS to \"no\". Note: Disabling shared libraries requires up to 10x as much disk space.")
endif()
endif()
set(CMAKE_REQUIRED_LIBRARIES)
endif ()
mark_as_advanced(${FFTW}_INCLUDE_DIR ${FFTW}_LIBRARY)