FindFFT?[F] scripts can use a path provided in FFTWx[F]_ROOT_DIR environment variable...
[alexxy/gromacs.git] / cmake / FindFFTW2.cmake
index b41a5818aaa41aae4ef75d4e82a0e14547a5b5ef..34b6aa8d63291a447d8bcb95321b51f2ff2e6f87 100644 (file)
@@ -4,6 +4,8 @@
 #  FFTW2_INCLUDE_DIR - where to find [d]fftw.h
 #  FFTW2_LIBRARIES   - List of libraries when using FFTW.
 #  FFTW2_FOUND       - True if FFTW found.
+#
+# The FFTW2 root installation directory can be provided in the FFTW2_ROOT_DIR
 
 if (FFTW2_INCLUDE_DIR)
   # Already in cache, be silent
@@ -12,14 +14,22 @@ endif (FFTW2_INCLUDE_DIR)
 
 set(FFTW2_FOUND 0)
 
+file(TO_CMAKE_PATH "$ENV{FFTW2_ROOT_DIR}" _env_FFTW2_ROOT_DIR)
 
 foreach(fftw2_name dfftw fftw)
     string(TOUPPER ${fftw2_name} fftw2_uname)
     string(REPLACE "fftw" "rfftw" rfftw2_name ${fftw2_name})
     if(NOT FFTW2_FOUND)
-        find_path (FFTW2_INCLUDE_DIR ${fftw2_name}.h)
-       find_library (CFFTW2_LIBRARIES  ${fftw2_name})          
-        find_library (RFFTW2_LIBRARIES ${rfftw2_name})
+        find_path (FFTW2_INCLUDE_DIR 
+                    PATHS "${_env_FFTW2_ROOT_DIR}/include"
+                    ${fftw2_name}.h)
+                    CACHE STRING "Path to double precision FFTW2 headers")
+       find_library (CFFTW2_LIBRARIES  ${fftw2_name}
+                        PATHS "${_env_FFTW2_ROOT_DIR}/lib"
+                       CACHE STRING "Double precision CFFTW2 libraries")
+        find_library (RFFTW2_LIBRARIES ${rfftw2_name}
+                        PATHS "${_env_FFTW2_ROOT_DIR}/lib"
+                       CACHE STRING "Double precision RFFTW2 libraries")
        TRY_COMPILE(FFTW2_FOUND "${CMAKE_BINARY_DIR}"
                     "${CMAKE_SOURCE_DIR}/cmake/TestFFTW2.c"
                    COMPILE_DEFINITIONS "-I${FFTW2_INCLUDE_DIR} -DDOUBLE -D${fftw2_uname}" )
@@ -36,7 +46,8 @@ endif(FFTW2_FOUND)
 # handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
 # all listed variables are TRUE
 include (FindPackageHandleStandardArgs)
-find_package_handle_standard_args (FFTW2 DEFAULT_MSG FFTW2_LIBRARIES FFTW2_INCLUDE_DIR)
+set(__MSG "Could not find FFTW2. Provide the fftw2 install directory in the FFTW2_ROOT_DIR environment variable.")
+find_package_handle_standard_args (FFTW2 ${__MSG} FFTW2_LIBRARIES FFTW2_INCLUDE_DIR)
 
 mark_as_advanced (RFFTW2_LIBRARIES CFFTW2_LIBRARIES FFTW2_LIBRARIES FFTW2_INCLUDE_DIR)