mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
Merge "cmake: fix per-file assembly flags"
This commit is contained in:
commit
fef789f366
@ -31,9 +31,17 @@ endfunction()
|
|||||||
set(WEBP_SIMD_FLAGS "SSE41;SSE2;MIPS32;MIPS_DSP_R2;NEON;MSA")
|
set(WEBP_SIMD_FLAGS "SSE41;SSE2;MIPS32;MIPS_DSP_R2;NEON;MSA")
|
||||||
set(WEBP_SIMD_FILE_EXTENSIONS
|
set(WEBP_SIMD_FILE_EXTENSIONS
|
||||||
"_sse41.c;_sse2.c;_mips32.c;_mips_dsp_r2.c;_neon.c;_msa.c")
|
"_sse41.c;_sse2.c;_mips32.c;_mips_dsp_r2.c;_neon.c;_msa.c")
|
||||||
if(MSVC)
|
if(MSVC AND CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||||
# MSVC does not have a SSE4 flag but AVX support implies SSE4 support.
|
# With at least Visual Studio 12 (2013)+ /arch is not necessary to build SSE2
|
||||||
set(SIMD_ENABLE_FLAGS "/arch:AVX;/arch:SSE2;;;;")
|
# or SSE4 code unless a lesser /arch is forced. MSVC does not have a SSE4
|
||||||
|
# flag, but an AVX one. Using that with SSE4 code risks generating illegal
|
||||||
|
# instructions when used on machines with SSE4 only. The flags are left for
|
||||||
|
# older (untested) versions to avoid any potential compatibility issues.
|
||||||
|
if(MSVC_VERSION GREATER_EQUAL 1800 AND NOT CMAKE_C_FLAGS MATCHES "/arch:")
|
||||||
|
set(SIMD_ENABLE_FLAGS)
|
||||||
|
else()
|
||||||
|
set(SIMD_ENABLE_FLAGS "/arch:AVX;/arch:SSE2;;;;")
|
||||||
|
endif()
|
||||||
set(SIMD_DISABLE_FLAGS)
|
set(SIMD_DISABLE_FLAGS)
|
||||||
else()
|
else()
|
||||||
set(SIMD_ENABLE_FLAGS
|
set(SIMD_ENABLE_FLAGS
|
||||||
@ -57,9 +65,14 @@ endif()
|
|||||||
|
|
||||||
list(LENGTH WEBP_SIMD_FLAGS WEBP_SIMD_FLAGS_LENGTH)
|
list(LENGTH WEBP_SIMD_FLAGS WEBP_SIMD_FLAGS_LENGTH)
|
||||||
math(EXPR WEBP_SIMD_FLAGS_RANGE "${WEBP_SIMD_FLAGS_LENGTH} - 1")
|
math(EXPR WEBP_SIMD_FLAGS_RANGE "${WEBP_SIMD_FLAGS_LENGTH} - 1")
|
||||||
unset(HIGHEST_SSE_FLAG)
|
|
||||||
|
|
||||||
foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||||
|
# With Emscripten 2.0.9 -msimd128 -mfpu=neon will enable NEON, but the
|
||||||
|
# source will fail to compile.
|
||||||
|
if(EMSCRIPTEN AND ${I_SIMD} GREATER_EQUAL 2)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
|
||||||
list(GET WEBP_SIMD_FLAGS ${I_SIMD} WEBP_SIMD_FLAG)
|
list(GET WEBP_SIMD_FLAGS ${I_SIMD} WEBP_SIMD_FLAG)
|
||||||
|
|
||||||
# First try with no extra flag added as the compiler might have default flags
|
# First try with no extra flag added as the compiler might have default flags
|
||||||
@ -67,43 +80,33 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
|||||||
unset(WEBP_HAVE_${WEBP_SIMD_FLAG} CACHE)
|
unset(WEBP_HAVE_${WEBP_SIMD_FLAG} CACHE)
|
||||||
cmake_push_check_state()
|
cmake_push_check_state()
|
||||||
set(CMAKE_REQUIRED_FLAGS)
|
set(CMAKE_REQUIRED_FLAGS)
|
||||||
if(NOT simd_found)
|
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
if(NOT WEBP_HAVE_${WEBP_SIMD_FLAG})
|
||||||
if(NOT WEBP_HAVE_${WEBP_SIMD_FLAG})
|
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||||
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
if(EMSCRIPTEN)
|
||||||
if(EMSCRIPTEN)
|
set(SIMD_COMPILE_FLAG "-msimd128 ${SIMD_COMPILE_FLAG}")
|
||||||
set(SIMD_COMPILE_FLAG "-msimd128 ${SIMD_COMPILE_FLAG}")
|
endif()
|
||||||
endif()
|
set(CMAKE_REQUIRED_FLAGS ${SIMD_COMPILE_FLAG})
|
||||||
set(CMAKE_REQUIRED_FLAGS ${SIMD_COMPILE_FLAG})
|
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
else()
|
||||||
else()
|
if(MSVC AND SIMD_ENABLE_FLAGS)
|
||||||
if(MSVC)
|
# The detection for SSE2/SSE4 support under MSVC is based on the compiler
|
||||||
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
# version so e.g., clang-cl will require flags to enable the assembly.
|
||||||
else()
|
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||||
set(SIMD_COMPILE_FLAG " ")
|
else()
|
||||||
endif()
|
set(SIMD_COMPILE_FLAG " ")
|
||||||
endif()
|
endif()
|
||||||
elseif(${I_SIMD} LESS 2)
|
|
||||||
set(WEBP_HAVE_${WEBP_SIMD_FLAG} 1)
|
|
||||||
endif()
|
endif()
|
||||||
# Check which files we should include or not.
|
# Check which files we should include or not.
|
||||||
list(GET WEBP_SIMD_FILE_EXTENSIONS ${I_SIMD} WEBP_SIMD_FILE_EXTENSION)
|
list(GET WEBP_SIMD_FILE_EXTENSIONS ${I_SIMD} WEBP_SIMD_FILE_EXTENSION)
|
||||||
file(GLOB SIMD_FILES "${CMAKE_CURRENT_LIST_DIR}/../"
|
file(GLOB SIMD_FILES "${CMAKE_CURRENT_LIST_DIR}/../"
|
||||||
"src/dsp/*${WEBP_SIMD_FILE_EXTENSION}")
|
"src/dsp/*${WEBP_SIMD_FILE_EXTENSION}")
|
||||||
if(WEBP_HAVE_${WEBP_SIMD_FLAG})
|
if(WEBP_HAVE_${WEBP_SIMD_FLAG})
|
||||||
if(${I_SIMD} LESS 2 AND NOT HIGHEST_SSE_FLAG)
|
|
||||||
set(HIGHEST_SSE_FLAG ${SIMD_COMPILE_FLAG})
|
|
||||||
endif()
|
|
||||||
# Memorize the file and flags.
|
# Memorize the file and flags.
|
||||||
foreach(FILE ${SIMD_FILES})
|
foreach(FILE ${SIMD_FILES})
|
||||||
list(APPEND WEBP_SIMD_FILES_TO_INCLUDE ${FILE})
|
list(APPEND WEBP_SIMD_FILES_TO_INCLUDE ${FILE})
|
||||||
if(${I_SIMD} LESS 2)
|
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${SIMD_COMPILE_FLAG})
|
||||||
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${HIGHEST_SSE_FLAG})
|
|
||||||
else()
|
|
||||||
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${SIMD_COMPILE_FLAG})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
set(simd_found 1)
|
|
||||||
else()
|
else()
|
||||||
# Remove the file from the list.
|
# Remove the file from the list.
|
||||||
foreach(FILE ${SIMD_FILES})
|
foreach(FILE ${SIMD_FILES})
|
||||||
|
Loading…
Reference in New Issue
Block a user