Commit 31554d84 authored by Florent Pruvost's avatar Florent Pruvost

update FindFFTW to be found with pkg-config

parent 129cf214
......@@ -156,22 +156,63 @@ if (FFTW_LOOK_FOR_OMP)
endif()
endif()
# Looking for include
# -------------------
# Add system include paths to search include
# ------------------------------------------
unset(_inc_env)
set(ENV_MKLROOT "$ENV{MKLROOT}")
set(ENV_FFTW_DIR "$ENV{FFTW_DIR}")
set(ENV_FFTW_INCDIR "$ENV{FFTW_INCDIR}")
if(ENV_FFTW_INCDIR)
set(ENV_FFTW_LIBDIR "$ENV{FFTW_LIBDIR}")
set(FFTW_GIVEN_BY_USER "FALSE")
if ( FFTW_DIR OR ( FFTW_INCDIR AND FFTW_LIBDIR) OR ENV_FFTW_DIR OR (ENV_FFTW_INCDIR AND ENV_FFTW_LIBDIR) )
set(FFTW_GIVEN_BY_USER "TRUE")
endif()
# Optionally use pkg-config to detect include/library dirs (if pkg-config is available)
# -------------------------------------------------------------------------------------
include(FindPkgConfig)
find_package(PkgConfig QUIET)
if( PKG_CONFIG_EXECUTABLE AND NOT FFTW_GIVEN_BY_USER )
pkg_search_module(FFTW fftw3)
if (NOT FFTW_FIND_QUIETLY)
if (FFTW_FOUND AND FFTW_LIBRARIES)
message(STATUS "Looking for FFTW - found using PkgConfig")
#if(NOT FFTW_INCLUDE_DIRS)
# message("${Magenta}FFTW_INCLUDE_DIRS is empty using PkgConfig."
# "Perhaps the path to hwloc headers is already present in your"
# "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}")
#endif()
else()
message("${Magenta}Looking for FFTW - not found using PkgConfig."
"Perhaps you should add the directory containing fftw3.pc to"
"the PKG_CONFIG_PATH environment variable.${ColourReset}")
endif()
endif()
set(FFTW_INCLUDE_DIRS_DEP "${FFTW_INCLUDE_DIRS}")
set(FFTW_LIBRARY_DIRS_DEP "${FFTW_LIBRARY_DIRS}")
set(FFTW_LIBRARIES_DEP "${FFTW_LIBRARIES}")
set(FFTW_WORKS TRUE)
endif( PKG_CONFIG_EXECUTABLE AND NOT FFTW_GIVEN_BY_USER )
if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT FFTW_FOUND) OR (FFTW_GIVEN_BY_USER) )
# Looking for include
# -------------------
# Add system include paths to search include
# ------------------------------------------
unset(_inc_env)
set(ENV_MKLROOT "$ENV{MKLROOT}")
set(ENV_FFTW_DIR "$ENV{FFTW_DIR}")
set(ENV_FFTW_INCDIR "$ENV{FFTW_INCDIR}")
if(ENV_FFTW_INCDIR)
list(APPEND _inc_env "${ENV_FFTW_INCDIR}")
elseif(ENV_FFTW_DIR)
elseif(ENV_FFTW_DIR)
list(APPEND _inc_env "${ENV_FFTW_DIR}")
list(APPEND _inc_env "${ENV_FFTW_DIR}/include")
list(APPEND _inc_env "${ENV_FFTW_DIR}/include/fftw")
else()
else()
if (ENV_MKLROOT)
list(APPEND _inc_env "${ENV_MKLROOT}/include/fftw")
endif()
......@@ -189,23 +230,23 @@ else()
string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
list(APPEND _inc_env "${_path_env}")
endif()
endif()
list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
list(REMOVE_DUPLICATES _inc_env)
endif()
list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
list(REMOVE_DUPLICATES _inc_env)
# set paths where to look for
set(PATH_TO_LOOK_FOR "${_inc_env}")
# set paths where to look for
set(PATH_TO_LOOK_FOR "${_inc_env}")
# Try to find the fftw header in the given paths
# -------------------------------------------------
# call cmake macro to find the header path
if(FFTW_INCDIR)
# Try to find the fftw header in the given paths
# -------------------------------------------------
# call cmake macro to find the header path
if(FFTW_INCDIR)
set(FFTW_fftw3.h_DIRS "FFTW_fftw3.h_DIRS-NOTFOUND")
find_path(FFTW_fftw3.h_DIRS
NAMES fftw3.h
HINTS ${FFTW_INCDIR})
else()
else()
if(FFTW_DIR)
set(FFTW_fftw3.h_DIRS "FFTW_fftw3.h_DIRS-NOTFOUND")
find_path(FFTW_fftw3.h_DIRS
......@@ -219,31 +260,31 @@ else()
HINTS ${PATH_TO_LOOK_FOR}
PATH_SUFFIXES "fftw")
endif()
endif()
mark_as_advanced(FFTW_fftw3.h_DIRS)
endif()
mark_as_advanced(FFTW_fftw3.h_DIRS)
# Add path to cmake variable
# ------------------------------------
if (FFTW_fftw3.h_DIRS)
# Add path to cmake variable
# ------------------------------------
if (FFTW_fftw3.h_DIRS)
set(FFTW_INCLUDE_DIRS "${FFTW_fftw3.h_DIRS}")
else ()
else ()
set(FFTW_INCLUDE_DIRS "FFTW_INCLUDE_DIRS-NOTFOUND")
if(NOT FFTW_FIND_QUIETLY)
message(STATUS "Looking for FFTW -- fftw3.h not found")
endif()
endif ()
endif ()
# Looking for lib
# ---------------
# Looking for lib
# ---------------
# Add system library paths to search lib
# --------------------------------------
unset(_lib_env)
set(ENV_FFTW_LIBDIR "$ENV{FFTW_LIBDIR}")
if(ENV_FFTW_LIBDIR)
# Add system library paths to search lib
# --------------------------------------
unset(_lib_env)
set(ENV_FFTW_LIBDIR "$ENV{FFTW_LIBDIR}")
if(ENV_FFTW_LIBDIR)
list(APPEND _lib_env "${ENV_FFTW_LIBDIR}")
elseif(ENV_FFTW_DIR)
elseif(ENV_FFTW_DIR)
list(APPEND _lib_env "${ENV_FFTW_DIR}")
list(APPEND _lib_env "${ENV_FFTW_DIR}/lib")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
......@@ -253,7 +294,7 @@ elseif(ENV_FFTW_DIR)
list(APPEND _lib_env "${ENV_FFTW_DIR}/lib32")
list(APPEND _lib_env "${ENV_FFTW_DIR}/lib/ia32")
endif()
else()
else()
if (ENV_MKLROOT)
list(APPEND _lib_env "${ENV_MKLROOT}/lib")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
......@@ -276,27 +317,27 @@ else()
list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
endif()
endif()
list(REMOVE_DUPLICATES _lib_env)
endif()
list(REMOVE_DUPLICATES _lib_env)
# set paths where to look for
set(PATH_TO_LOOK_FOR "${_lib_env}")
# set paths where to look for
set(PATH_TO_LOOK_FOR "${_lib_env}")
if(FFTW_LOOK_FOR_FFTW_SIMPLE)
if(FFTW_LOOK_FOR_FFTW_SIMPLE)
set(FFTW_PREC "f")
set(FFTW_PREC_TESTFUNC "s")
elseif(FFTW_LOOK_FOR_FFTW_DOUBLE)
elseif(FFTW_LOOK_FOR_FFTW_DOUBLE)
set(FFTW_PREC "")
set(FFTW_PREC_TESTFUNC "d")
elseif(FFTW_LOOK_FOR_FFTW_LONG)
elseif(FFTW_LOOK_FOR_FFTW_LONG)
set(FFTW_PREC "l")
set(FFTW_PREC_TESTFUNC "l")
elseif(FFTW_LOOK_FOR_FFTW_QUAD)
elseif(FFTW_LOOK_FOR_FFTW_QUAD)
set(FFTW_PREC "q")
set(FFTW_PREC_TESTFUNC "q")
endif()
endif()
if (FFTW_LOOK_FOR_MKL)
if (FFTW_LOOK_FOR_MKL)
set(FFTW_libs_to_find "mkl_intel_lp64;mkl_sequential;mkl_core")
......@@ -330,7 +371,7 @@ if (FFTW_LOOK_FOR_MKL)
endif()
endif()
else(FFTW_LOOK_FOR_MKL)
else(FFTW_LOOK_FOR_MKL)
if (FFTW_LOOK_FOR_THREADS)
set(FFTW_libs_to_find "fftw3${FFTW_PREC}_threads;fftw3${FFTW_PREC};fftw3")
......@@ -370,13 +411,13 @@ else(FFTW_LOOK_FOR_MKL)
endif()
endif()
endif(FFTW_LOOK_FOR_MKL)
endif(FFTW_LOOK_FOR_MKL)
# If found, add path to cmake variable
# ------------------------------------
set(FFTW_LIBRARIES "")
set(FFTW_LIBRARY_DIRS "")
foreach(fftw_lib ${FFTW_libs_to_find})
# If found, add path to cmake variable
# ------------------------------------
set(FFTW_LIBRARIES "")
set(FFTW_LIBRARY_DIRS "")
foreach(fftw_lib ${FFTW_libs_to_find})
if (FFTW_${fftw_lib}_LIBRARY)
get_filename_component(${fftw_lib}_lib_path "${FFTW_${fftw_lib}_LIBRARY}" PATH)
......@@ -391,13 +432,13 @@ foreach(fftw_lib ${FFTW_libs_to_find})
endif ()
mark_as_advanced(FFTW_${fftw_lib}_LIBRARY)
endforeach()
endforeach()
list(REMOVE_DUPLICATES FFTW_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS)
list(REMOVE_DUPLICATES FFTW_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS)
# check a function to validate the find
if(FFTW_LIBRARIES)
# check a function to validate the find
if(FFTW_LIBRARIES)
set(REQUIRED_FLAGS)
set(REQUIRED_LDFLAGS)
......@@ -483,7 +524,9 @@ if(FFTW_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_LIBRARIES)
endif(FFTW_LIBRARIES)
endif(FFTW_LIBRARIES)
endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT FFTW_FOUND) OR (FFTW_GIVEN_BY_USER) )
if (FFTW_LIBRARIES)
list(GET FFTW_LIBRARIES 0 first_lib)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment