Skip to content

Commit

Permalink
cmake: Set SIMD flags on appropriate source files only.
Browse files Browse the repository at this point in the history
Doing this matches the behavior of the configure script and makefiles.

Previously, enabling a set of SIMD instructions with the CMake build
would build the whole library with that flag enabled, allowing the
compiler to optimize by using that set of instructions anywhere. That
would then require that any SIMD instructions enabled at build time
would have to be present at run time. This change enables the intended
behavior of using SIMD instructions only when they are detected at run
time.
  • Loading branch information
ryanvolz committed Apr 6, 2023
1 parent c277d55 commit a983a1f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,29 @@ if (MSVC AND NOT (CMAKE_C_COMPILER_ID STREQUAL "Intel"))
target_compile_definitions (${fftw3_lib} PRIVATE /bigobj)
endif ()
if (HAVE_SSE)
target_compile_options (${fftw3_lib} PRIVATE ${SSE_FLAG})
set_source_files_properties (${fftw_dft_simd_sse2_SOURCE}
${fftw_rdft_simd_sse2_SOURCE}
PROPERTIES COMPILE_FLAGS "${SSE_FLAG}")
endif ()
if (HAVE_SSE2)
target_compile_options (${fftw3_lib} PRIVATE ${SSE2_FLAG})
set_source_files_properties (${fftw_dft_simd_sse2_SOURCE}
${fftw_rdft_simd_sse2_SOURCE}
PROPERTIES COMPILE_FLAGS "${SSE2_FLAG}")
endif ()
if (HAVE_AVX)
target_compile_options (${fftw3_lib} PRIVATE ${AVX_FLAG})
set_source_files_properties (${fftw_dft_simd_avx_SOURCE}
${fftw_rdft_simd_avx_SOURCE}
PROPERTIES COMPILE_FLAGS "${AVX_FLAG}")
endif ()
if (HAVE_AVX2)
target_compile_options (${fftw3_lib} PRIVATE ${AVX2_FLAG})
set_source_files_properties (${fftw_dft_simd_avx2_SOURCE}
${fftw_rdft_simd_avx2_SOURCE}
PROPERTIES COMPILE_FLAGS "${AVX2_FLAG}")
endif ()
if (HAVE_FMA)
target_compile_options (${fftw3_lib} PRIVATE ${FMA_FLAG})
set_source_files_properties (${fftw_dft_simd_avx2_SOURCE}
${fftw_rdft_simd_avx2_SOURCE}
PROPERTIES COMPILE_FLAGS "${FMA_FLAG}")
endif ()
if (HAVE_LIBM)
target_link_libraries (${fftw3_lib} m)
Expand Down

0 comments on commit a983a1f

Please sign in to comment.