1# Copyright 2019 The libgav1 Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15if(LIBGAV1_CMAKE_LIBGAV1_CPU_DETECTION_CMAKE_) 16 return() 17endif() # LIBGAV1_CMAKE_LIBGAV1_CPU_DETECTION_CMAKE_ 18set(LIBGAV1_CMAKE_LIBGAV1_CPU_DETECTION_CMAKE_ 1) 19 20# Detect optimizations available for the current target CPU. 21macro(libgav1_optimization_detect) 22 if(LIBGAV1_ENABLE_OPTIMIZATIONS) 23 string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" cpu_lowercase) 24 if(cpu_lowercase MATCHES "^arm|^aarch64") 25 set(libgav1_have_neon ON) 26 elseif(cpu_lowercase MATCHES "^x86|amd64") 27 set(libgav1_have_avx2 ON) 28 set(libgav1_have_sse4 ON) 29 endif() 30 endif() 31 32 if(libgav1_have_avx2 AND LIBGAV1_ENABLE_AVX2) 33 list(APPEND libgav1_defines "LIBGAV1_ENABLE_AVX2=1") 34 else() 35 list(APPEND libgav1_defines "LIBGAV1_ENABLE_AVX2=0") 36 endif() 37 38 if(libgav1_have_neon AND LIBGAV1_ENABLE_NEON) 39 list(APPEND libgav1_defines "LIBGAV1_ENABLE_NEON=1") 40 else() 41 list(APPEND libgav1_defines "LIBGAV1_ENABLE_NEON=0") 42 endif() 43 44 if(libgav1_have_sse4 AND LIBGAV1_ENABLE_SSE4_1) 45 list(APPEND libgav1_defines "LIBGAV1_ENABLE_SSE4_1=1") 46 else() 47 list(APPEND libgav1_defines "LIBGAV1_ENABLE_SSE4_1=0") 48 endif() 49endmacro() 50