a13470d8bf94a2b00a84518a23260214d2f2cbf3
[alexxy/gromacs.git] / cmake / FindclFFT.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2018, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 # - Find clFFT, AMD's OpenCL FFT library
36 #
37 # This script does define cache variables
38 #   CLFFT_INCLUDE_DIR    - Location of clFFT's include directory.
39 #   CLFFT_LIBRARY        - Location of clFFT's libraries
40 # however the preferred use is simply to link to the imported
41 # CMake target clFFT, which is constructed to behave as if clFFT
42 # was built within the parent project, and correctly populates
43 # the required include directories and linker flags.
44 #
45 # If your clFFT installation is not in a standard installation
46 # directory, you may provide a hint to where it may be found. Simply
47 # set the value clFFT_ROOT to the directory containing
48 # 'include/clFFT.h" prior to calling find_package().
49
50 if(clFFT_INCLUDE_DIR)
51   # Already in cache, be silent
52   set (clFFT_FIND_QUIETLY TRUE)
53 endif()
54
55 find_package(PkgConfig)
56 pkg_check_modules(PC_clFFT QUIET clFFT)
57
58 find_path(clFFT_ROOT_DIR
59     NAMES include/clFFT.h
60     HINTS ${clFFT_ROOT}
61     DOC "clFFT root directory.")
62
63 find_path(clFFT_INCLUDE_DIR
64     NAMES clFFT.h
65     HINTS
66     ${clFFT_ROOT_DIR}/include
67     ${PC_clFFT_INCLUDE_DIRS}
68     DOC "clFFT Include directory")
69
70 find_library(clFFT_LIBRARY
71     NAMES clFFT
72     HINTS
73     ${clFFT_ROOT_DIR}/lib64
74     ${clFFT_ROOT_DIR}/lib
75     ${PC_clFFT_LIBRARY_DIRS}
76     )
77
78 # handle the QUIETLY and REQUIRED arguments and set clFFT_FOUND to TRUE if
79 # all listed variables are TRUE
80 include(FindPackageHandleStandardArgs)
81 find_package_handle_standard_args(clFFT
82     REQUIRED_VARS clFFT_INCLUDE_DIR clFFT_LIBRARY
83 )
84
85 mark_as_advanced(clFFT_ROOT_DIR clFFT_LIBRARY clFFT_INCLUDE_DIR)
86
87 # Prepare a faux link target that can be used as if the clFFT
88 # that was found was actually built in this project.
89 if(clFFT_FOUND)
90     add_library(clFFT INTERFACE IMPORTED)
91     # When we depend on cmake 3.11, this work-around (specific to
92     # imported targets) can be done more simply by using the normal
93     # target_include_directories() and target_link_libraries()
94     set_target_properties(clFFT PROPERTIES
95         INTERFACE_INCLUDE_DIRECTORIES "${clFFT_INCLUDE_DIR}"
96         INTERFACE_LINK_LIBRARIES "${clFFT_LIBRARY};${CMAKE_DL_LIBS}"
97         )
98 endif()
99