Fix linking with fftw when thread support is enabled.

--- gmic-qt/CMakeLists.txt
+++ gmic-qt/CMakeLists.txt
@@ -13,6 +13,7 @@
 set(CMAKE_AUTOUIC OFF)
 set(CMAKE_AUTORCC ON)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(EXTRA_LIBRARIES)
 
 set (GMIC_QT_HOST "gimp" CACHE STRING "Define for which host qmic-qt will be built: gimp, krita, none, paintdotnet, or digikam.")
 if (${GMIC_QT_HOST} STREQUAL "none")
@@ -145,8 +146,13 @@
 #
 find_package(FFTW3 REQUIRED)
 add_definitions(-Dcimg_use_fftw3 )
-add_definitions(-Dcimg_use_fftw3_singlethread )
 include_directories(${FFTW3_INCLUDE_DIR})
+find_library(FFTW3_THREADS_LIB fftw3_threads PATHS ${FFTW3_LIBRARY_DIRS})
+if(FFTW3_THREADS_LIB STREQUAL "FFTW3_THREADS_LIB-NOTFOUND")
+    add_definitions(-Dcimg_use_fftw3_singlethread)
+else()
+    list(APPEND EXTRA_LIBRARIES "-lfftw3_threads")
+endif()
 
 #
 # CURL
@@ -187,6 +193,7 @@
         ${PNG_LIBRARIES}
         ${FFTW3_LIBRARIES}
         ${ZLIB_LIBRARIES}
+        ${EXTRA_LIBRARIES}
 )
 
 if (CURL_FOUND)
