From 3226325016558c5a139cb5569b04bb7fe0005d74 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Fri, 3 Feb 2017 16:47:59 +0100 Subject: [PATCH] Add a flag to disable SIMD optimizations. Change-Id: I83c33076e8afd1b20de1e9b191bdad6669998a0b --- CMakeLists.txt | 1 + cmake/cpu.cmake | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7203315..aa023935 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.7) project(libwebp C) # Options for coder / decoder executables. +option(WEBP_ENABLE_SIMD "Enable any SIMD optimization." ON) option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." OFF) option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." OFF) option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." OFF) diff --git a/cmake/cpu.cmake b/cmake/cpu.cmake index 95fafcb9..94c021a1 100644 --- a/cmake/cpu.cmake +++ b/cmake/cpu.cmake @@ -1,6 +1,11 @@ ## Check for SIMD extensions. -function(webp_check_compiler_flag WEBP_SIMD_FLAG) +function(webp_check_compiler_flag WEBP_SIMD_FLAG ENABLE_SIMD) + if(NOT ENABLE_SIMD) + message(STATUS "Disabling ${WEBP_SIMD_FLAG} optimization.") + set(WEBP_HAVE_${WEBP_SIMD_FLAG} 0 PARENT_SCOPE) + return() + endif() unset(WEBP_HAVE_FLAG_${WEBP_SIMD_FLAG} CACHE) check_c_source_compiles(" #include \"${CMAKE_CURRENT_LIST_DIR}/../src/dsp/dsp.h\" @@ -56,11 +61,11 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE}) # (especially on Android). unset(WEBP_HAVE_${WEBP_SIMD_FLAG} CACHE) set(CMAKE_REQUIRED_FLAGS) - webp_check_compiler_flag(${WEBP_SIMD_FLAG}) + webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD}) if(NOT WEBP_HAVE_${WEBP_SIMD_FLAG}) list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG) set(CMAKE_REQUIRED_FLAGS ${SIMD_COMPILE_FLAG}) - webp_check_compiler_flag(${WEBP_SIMD_FLAG}) + webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD}) else() set(SIMD_COMPILE_FLAG " ") endif()