-# Testing shows FFTW configured with --enable-avx is never better than --enable-sse2, so we do the latter always.
-if(${GMX_SIMD} MATCHES "^(SSE|AVX)")
- set(GMX_BUILD_OWN_FFTW_OPTIMIZATION_CONFIGURATION --enable-sse2 CACHE INTERNAL "Optimization flags for FFTW compilation")
+# Set library optimizations
+set(_fftw_simd_support_level "")
+if(${GMX_SIMD} MATCHES "^(SSE|AVX)" AND APPLE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+ # OS X with gcc and --enable-avx causes compilation issues. It's
+ # not an important enough performance loss to bother warning the
+ # user about.
+ set(_fftw_simd_support_level "--enable-sse2")
+elseif(${GMX_SIMD} MATCHES "^(SSE)")
+ set(_fftw_simd_support_level "--enable-sse2")
+elseif(${GMX_SIMD} MATCHES "^(AVX)")
+ # Testing shows FFTW configured with --enable-sse2 --enable-avx is
+ # slightly faster on most architectures than --enable-sse2 alone
+ set(_fftw_simd_support_level "--enable-sse2 --enable-avx")