File: FindFFTW.cmake

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (383 lines) | stat: -rw-r--r-- 12,505 bytes parent folder | download | duplicates (3)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# (C) Copyright 2011- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.

##############################################################################
#.rst:
#
# FindFFTW
# ========
#
# Find the FFTW library. ::
#
#   find_package(FFTW [REQUIRED] [QUIET]
#                [COMPONENTS [single] [double] [long_double] [quad]])
#
# By default, search for the double precision library ``fftw3``
#
# Search procedure
# ----------------
#
# * FFTW_LIBRARIES and FFTW_INCLUDE_DIRS set by user
#   
#   * Nothing is searched and these variables are used instead
#
# * Find MKL implementation via FFTW_ENABLE_MKL
#
#   * If FFTW_ENABLE_MKL is explicitly set to ON, only MKL is considered
#   * If FFTW_ENABLE_MKL is explicitly set to OFF, MKL will not be considered
#   * If FFTW_ENABLE_MKL is undefined, MKL is preferred unless ENABLE_MKL is explicitly set to OFF
#   * Note: MKLROOT environment variable helps to detect MKL (See FindMKL.cmake)
#
# * Find ARMPL or NVPL implementations, via FFTW_ENABLE_ARMPL or FFTW_ENABLE_NVPL, with behaviour as for MKL
#
# * Find official FFTW implementation
#
#   * FFTW_ROOT variable / environment variable helps to detect FFTW
#
# Components
# ----------
#
# If a different version or multiple versions of the library are required,
# these need to be specified as ``COMPONENTS``. Note that double must be given
# explicitly if any ``COMPONENTS`` are specified.
#
# The libraries corresponding to each of the ``COMPONENTS`` are:
#
# :single:      ``FFTW::fftw3f``
# :double:      ``FFTW::fftw3``
# :long_double: ``FFTW::fftw3l``
# :quad:        ``FFTW::fftw3q``
#
# Output variables
# ----------------
#
# The following CMake variables are set on completion:
#
# :FFTW_FOUND:            true if FFTW is found on the system
# :FFTW_LIBRARIES:        full paths to requested FFTW libraries
# :FFTW_INCLUDE_DIRS:     FFTW include directory
#
# Input variables
# ---------------
#
# The following CMake variables are checked by the function:
#
# :FFTW_USE_STATIC_LIBS:  if true, only static libraries are found
# :FFTW_ROOT:             if set, this path is exclusively searched
# :FFTW_DIR:              equivalent to FFTW_ROOT (deprecated)
# :FFTW_PATH:             equivalent to FFTW_ROOT (deprecated)
# :FFTW_LIBRARIES:        User overriden FFTW libraries
# :FFTW_INCLUDE_DIRS:     User overriden FFTW includes directories
# :FFTW_ENABLE_MKL:       User requests use of MKL implementation
# :FFTW_ENABLE_ARMPL:     User requests use of ARMPL implementation
# :FFTW_ENABLE_NVPL:      User requests use of NVPL implementation
#
##############################################################################

list( APPEND _possible_components double single long_double quad )

if( NOT FFTW_FIND_COMPONENTS )
  set( FFTW_FIND_COMPONENTS double )
endif()

set( FFTW_double_LIBRARY_NAME fftw3 )
set( FFTW_single_LIBRARY_NAME fftw3f )
set( FFTW_long_double_LIBRARY_NAME fftw3l )
set( FFTW_quad_LIBRARY_NAME fftw3q )

macro( FFTW_CHECK_ALL_COMPONENTS )
    set( FFTW_FOUND_ALL_COMPONENTS TRUE )
    foreach( _component ${FFTW_FIND_COMPONENTS} )
        if( NOT FFTW_${_component}_FOUND )
            set( FFTW_FOUND_ALL_COMPONENTS false )
        endif()
    endforeach()
endmacro()

# Command line override
foreach( _component ${FFTW_FIND_COMPONENTS} )
    if( NOT FFTW_${_component}_LIBRARIES AND FFTW_LIBRARIES )
        set( FFTW_${_component}_LIBRARIES ${FFTW_LIBRARIES} )
    endif()
    if( FFTW_${_component}_LIBRARIES )
        set( FFTW_${_component}_FOUND TRUE )
    endif()
endforeach()

### Check MKL
FFTW_CHECK_ALL_COMPONENTS()
if( NOT FFTW_FOUND_ALL_COMPONENTS )

    if( NOT DEFINED FFTW_ENABLE_MKL AND NOT DEFINED ENABLE_MKL )
        set( FFTW_ENABLE_MKL ON )
        set( FFTW_FindMKL_OPTIONS QUIET )
    elseif( FFTW_ENABLE_MKL )
        set( FFTW_MKL_REQUIRED TRUE )
    elseif( ENABLE_MKL AND NOT DEFINED FFTW_ENABLE_MKL )
        set( FFTW_ENABLE_MKL ON )
    endif()

    if( FFTW_ENABLE_MKL )
        if( NOT MKL_FOUND )
            find_package( MKL ${FFTW_FindMKL_OPTIONS} )
        endif()
        if( MKL_FOUND )
            if( NOT FFTW_INCLUDE_DIRS )
                set( FFTW_INCLUDE_DIRS ${MKL_INCLUDE_DIRS}/fftw )
            endif()
            if( NOT FFTW_LIBRARIES )
                set( FFTW_LIBRARIES ${MKL_LIBRARIES} )
            endif()

            foreach( _component ${FFTW_FIND_COMPONENTS} )
                set( FFTW_${_component}_FOUND TRUE )
                set( FFTW_${_component}_LIBRARIES ${MKL_LIBRARIES} )
            endforeach()
        else()
            if( FFTW_MKL_REQUIRED )
                if( FFTW_FIND_REQUIRED )
                    message(CRITICAL "FindFFTW: MKL required, but MKL was not found" )
                else()
                    if( NOT FFTW_MKL_FIND_QUIETLY )
                        message(STATUS "FindFFTW: MKL required, but MKL was not found" )
                    endif()
                    set( FFTW_FOUND FALSE )
                    return()
                endif()
            endif()
        endif()
    endif()
endif()

### Check ARMPL
FFTW_CHECK_ALL_COMPONENTS()
if( NOT FFTW_FOUND_ALL_COMPONENTS )

    if( NOT DEFINED FFTW_ENABLE_ARMPL AND NOT DEFINED ENABLE_ARMPL )
	set( FFTW_ENABLE_ARMPL ON )
	set( FFTW_FindARMPL_OPTIONS QUIET )
    elseif( FFTW_ENABLE_ARMPL )
	set( FFTW_ARMPL_REQUIRED TRUE )
    elseif( ENABLE_ARMPL AND NOT DEFINED FFTW_ENABLE_ARMPL )
	set( FFTW_ENABLE_ARMPL ON )
    endif()

    if( FFTW_ENABLE_ARMPL )
	if( NOT ARMPL_FOUND )
	    find_package( ARMPL ${FFTW_FindARMPL_OPTIONS} )
        endif()
	if( ARMPL_FOUND )
            if( NOT FFTW_INCLUDE_DIRS )
		set( FFTW_INCLUDE_DIRS ${ARMPL_INCLUDE_DIRS} )
            endif()
            if( NOT FFTW_LIBRARIES )
		set( FFTW_LIBRARIES ${ARMPL_LIBRARIES} )
            endif()

            foreach( _component ${FFTW_FIND_COMPONENTS} )
                set( FFTW_${_component}_FOUND TRUE )
		set( FFTW_${_component}_LIBRARIES ${ARMPL_LIBRARIES} )
            endforeach()
        else()
	    if( FFTW_ARMPL_REQUIRED )
                if( FFTW_FIND_REQUIRED )
		    message(CRITICAL "FindFFTW: ARMPL required, but was not found" )
                else()
		    if( NOT FFTW_ARMPL_FIND_QUIETLY )
			message(STATUS "FindFFTW: ARMPL required, but was not found" )
                    endif()
                    set( FFTW_FOUND FALSE )
                    return()
                endif()
            endif()
        endif()
    endif()
endif()

### Check NVPL
FFTW_CHECK_ALL_COMPONENTS()
if( NOT FFTW_FOUND_ALL_COMPONENTS )

    if( NOT DEFINED FFTW_ENABLE_NVPL AND NOT DEFINED ENABLE_NVPL )
	set( FFTW_ENABLE_NVPL ON )
	set( FFTW_FindNVPL_OPTIONS QUIET )
    elseif( FFTW_ENABLE_NVPL )
	set( FFTW_NVPL_REQUIRED TRUE )
    elseif( ENABLE_NVPL AND NOT DEFINED FFTW_ENABLE_NVPL )
	set( FFTW_ENABLE_NVPL ON )
    endif()

    if( FFTW_ENABLE_NVPL )
	if( NOT NVPL_FOUND )
	    find_package( NVPL ${FFTW_FindNVPL_OPTIONS} )
        endif()
	if( NVPL_FOUND )
            if( NOT FFTW_INCLUDE_DIRS )
		set( FFTW_INCLUDE_DIRS ${NVPL_INCLUDE_DIRS} )
            endif()
            if( NOT FFTW_LIBRARIES )
		set( FFTW_LIBRARIES ${NVPL_LIBRARIES} )
            endif()

            foreach( _component ${FFTW_FIND_COMPONENTS} )
                set( FFTW_${_component}_FOUND TRUE )
		set( FFTW_${_component}_LIBRARIES ${NVPL_LIBRARIES} )
            endforeach()
        else()
	    if( FFTW_NVPL_REQUIRED )
                if( FFTW_FIND_REQUIRED )
			message(CRITICAL "FindFFTW: NVPL required, but NVPL was not found" )
                else()
		    if( NOT FFTW_NVPL_FIND_QUIETLY )
			    message(STATUS "FindFFTW: NVPL required, but NVPL was not found" )
                    endif()
                    set( FFTW_FOUND FALSE )
                    return()
                endif()
            endif()
        endif()
    endif()
endif()

### Standard FFTW
if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTW_ROOT} )
    set( FFTW_ROOT $ENV{FFTW_ROOT} )
endif()
if( (NOT FFTW_ROOT) AND FFTW_DIR )
    set( FFTW_ROOT ${FFTW_DIR} )
endif()
if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTW_DIR} )
    set( FFTW_ROOT $ENV{FFTW_DIR} )
endif()
if( (NOT FFTW_ROOT) AND FFTWDIR )
    set( FFTW_ROOT ${FFTWDIR} )
endif()
if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTWDIR} )
    set( FFTW_ROOT $ENV{FFTWDIR} )
endif()
if( (NOT FFTW_ROOT) AND FFTW_PATH )
    set( FFTW_ROOT ${FFTW_PATH} )
endif()
if( (NOT FFTW_ROOT) AND EXISTS $ENV{FFTW_PATH})
    set( FFTW_ROOT $ENV{FFTW_PATH} )
endif()

if( FFTW_ROOT ) # On cc[a|b|t] FFTW_DIR is set to the lib directory :(
    get_filename_component(_dirname ${FFTW_ROOT} NAME)
    if( _dirname MATCHES "lib" )
        set( FFTW_ROOT "${FFTW_ROOT}/.." )
    endif()
endif()

if( NOT FFTW_ROOT )
    # Check if we can use PkgConfig
    find_package(PkgConfig)

    #Determine from PKG
    if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT )
        pkg_check_modules( PKG_FFTW QUIET "fftw3" )
    endif()
endif()

#Check whether to search static or dynamic libs
set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} )

if( ${FFTW_USE_STATIC_LIBS} )
    set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} )
else()
    set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX} )
endif()


if( FFTW_ROOT )
    set( _default_paths NO_DEFAULT_PATH )
    set( _lib_paths ${FFTW_ROOT} )
    set( _include_paths ${FFTW_ROOT} )
else()
    set( _lib_paths ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR} )
    set( _include_paths ${PKG_FFTW_INCLUDE_DIRS} ${INCLUDE_INSTALL_DIR} )
endif()

# find includes
if( NOT FFTW_INCLUDE_DIRS )
    find_path(
        FFTW_INCLUDE_DIR
        NAMES "fftw3.h"
        PATHS ${_include_paths}
        PATH_SUFFIXES "include"
        ${_default_paths}
        )
    if( NOT FFTW_INCLUDE_DIR )
        if( NOT FFTW_FIND_QUIETLY OR FFTW_FIND_REQUIRED )
            message( STATUS "FindFFTW: fftw include headers not found")
        endif()
    endif()

    set( FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR} )
endif()

# find libs
foreach( _component ${FFTW_FIND_COMPONENTS} )
    if( NOT FFTW_${_component}_LIBRARIES )
        find_library(
            FFTW_${_component}_LIB
            NAMES ${FFTW_${_component}_LIBRARY_NAME}
            PATHS ${_lib_paths}
            PATH_SUFFIXES "lib" "lib64"
            ${_default_paths}
            )
        set( FFTW_${_component}_LIBRARIES ${FFTW_${_component}_LIB} )
        if( FFTW_${_component}_LIBRARIES )
            set( FFTW_${_component}_FOUND TRUE )
        else()
            if( NOT FFTW_FIND_QUIETLY OR FFTW_FIND_REQUIRED )
                message(STATUS "FindFFTW: ${_component} precision required, but ${FFTW_${_component}_LIBRARY_NAME} was not found")
            endif()
            set( FFTW_${_component}_FOUND FALSE )
        endif()
    endif()
endforeach()

# Assemble FFTW_LIBRARIES
if( NOT FFTW_LIBRARIES )
    foreach( _component ${FFTW_FIND_COMPONENTS} )
        list( APPEND FFTW_LIBRARIES ${FFTW_${_component}_LIBRARIES} )
    endforeach()
    list( REMOVE_DUPLICATES FFTW_LIBRARIES )
endif()

# FFTW CREATE_INTERFACE_TARGETS
foreach( _component ${FFTW_FIND_COMPONENTS} )
    set( _target FFTW::${FFTW_${_component}_LIBRARY_NAME} )

    if( FFTW_${_component}_FOUND AND NOT TARGET ${_target} )
        add_library( ${_target} INTERFACE IMPORTED )
        target_link_libraries( ${_target} INTERFACE ${FFTW_${_component}_LIBRARIES} )
        target_include_directories( ${_target} INTERFACE ${FFTW_INCLUDE_DIRS} )
    endif()
endforeach()

if( NOT FFTW_FIND_QUIETLY AND FFTW_LIBRARIES )
  message( STATUS "FFTW targets:" )
  foreach( _component ${FFTW_FIND_COMPONENTS} )
    set( _target FFTW::${FFTW_${_component}_LIBRARY_NAME} )
    message( STATUS "    ${_target} (${_component} precision)  [${FFTW_${_component}_LIBRARIES}]")
  endforeach()
endif()


set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} )

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args( FFTW
                                   REQUIRED_VARS FFTW_INCLUDE_DIRS FFTW_LIBRARIES
                                   HANDLE_COMPONENTS )

set( FFTW_INCLUDES ${FFTW_INCLUDE_DIRS} ) # deprecated
set( FFTW_LIB ${FFTW_double_LIBRARIES} ) # deprecated
mark_as_advanced(FFTW_INCLUDE_DIRS FFTW_LIBRARIES FFTW_LIB)