title: How to use FFTW library in cmake?
body: <p>I have C++ code which uses FFTW 3.3.4. Ubuntu 16.04, cmake version 3.7.2</p>
  
  <pre><code>$ locate *fftw*.so
  
  /usr/lib/libsfftw.so
  /usr/lib/libsfftw_mpi.so
  /usr/lib/libsfftw_threads.so
  /usr/lib/libsrfftw.so
  /usr/lib/libsrfftw_mpi.so
  /usr/lib/libsrfftw_threads.so
  /usr/lib/x86_64-linux-gnu/libfftw3.so
  /usr/lib/x86_64-linux-gnu/libfftw3_mpi.so
  /usr/lib/x86_64-linux-gnu/libfftw3_omp.so
  /usr/lib/x86_64-linux-gnu/libfftw3_threads.so
  /usr/lib/x86_64-linux-gnu/libfftw3f.so
  /usr/lib/x86_64-linux-gnu/libfftw3f_mpi.so
  /usr/lib/x86_64-linux-gnu/libfftw3f_omp.so
  /usr/lib/x86_64-linux-gnu/libfftw3f_threads.so
  /usr/lib/x86_64-linux-gnu/libfftw3l.so
  /usr/lib/x86_64-linux-gnu/libfftw3l_mpi.so
  /usr/lib/x86_64-linux-gnu/libfftw3l_omp.so
  /usr/lib/x86_64-linux-gnu/libfftw3l_threads.so
  /usr/lib/x86_64-linux-gnu/libfftw3q.so
  /usr/lib/x86_64-linux-gnu/libfftw3q_omp.so
  /usr/lib/x86_64-linux-gnu/libfftw3q_threads.so
  
  
  $ locate fftw3.h
  /usr/include/fftw3.h
  </code></pre>
  
  <p>I can compile it in this way:</p>
  
  <pre><code>g++ main.cpp -o main -lfftw3
  </code></pre>
  
  <p>but I have a problem with cmake.</p>
  
  <p>This is my CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.5.1)
  project (main)
  SET(CMAKE_C_COMPILER gcc)
  SET(CMAKE_CXX_COMPILER g++)
  file(GLOB SOURCES "*.cpp") 
  SET(CMAKE_CXX_FLAGS "-lm -lfftw3")
  SET(CMAKE_C_FLAGS   "-lm -lfftw3")
  INCLUDE_DIRECTORIES(/usr/include)
  LINK_DIRECTORIES(/usr/lib/x86_64-linux-gnu)
  add_library(fftw3 STATIC IMPORTED)
  set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) 
  set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
  add_executable(main ${SOURCES})
  
  cmake . &amp;&amp; make
  </code></pre>
  
  <p>gives </p>
  
  <pre><code>undefined reference to `fftw_malloc'
  </code></pre>
  
  <p>and the same for the other fftw functions.</p>