draco_cpu_detection.cmake 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2021 The Draco Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  4. # use this file except in compliance with the License. You may obtain a copy of
  5. # 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, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations under
  13. # the License.
  14. if(DRACO_CMAKE_DRACO_CPU_DETECTION_CMAKE_)
  15. return()
  16. endif() # DRACO_CMAKE_DRACO_CPU_DETECTION_CMAKE_
  17. set(DRACO_CMAKE_DRACO_CPU_DETECTION_CMAKE_ 1)
  18. # Detect optimizations available for the current target CPU.
  19. macro(draco_optimization_detect)
  20. if(DRACO_ENABLE_OPTIMIZATIONS)
  21. string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" cpu_lowercase)
  22. if(cpu_lowercase MATCHES "^arm|^aarch64")
  23. set(draco_have_neon ON)
  24. elseif(cpu_lowercase MATCHES "^x86|amd64")
  25. set(draco_have_sse4 ON)
  26. endif()
  27. endif()
  28. if(draco_have_neon AND DRACO_ENABLE_NEON)
  29. list(APPEND draco_defines "DRACO_ENABLE_NEON=1")
  30. else()
  31. list(APPEND draco_defines "DRACO_ENABLE_NEON=0")
  32. endif()
  33. if(draco_have_sse4 AND DRACO_ENABLE_SSE4_1)
  34. list(APPEND draco_defines "DRACO_ENABLE_SSE4_1=1")
  35. else()
  36. list(APPEND draco_defines "DRACO_ENABLE_SSE4_1=0")
  37. endif()
  38. endmacro()