draco_intrinsics.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_INTRINSICS_CMAKE_)
  15. return()
  16. endif() # DRACO_CMAKE_DRACO_INTRINSICS_CMAKE_
  17. set(DRACO_CMAKE_DRACO_INTRINSICS_CMAKE_ 1)
  18. # Returns the compiler flag for the SIMD intrinsics suffix specified by the
  19. # SUFFIX argument via the variable specified by the VARIABLE argument:
  20. # draco_get_intrinsics_flag_for_suffix(SUFFIX <suffix> VARIABLE <var name>)
  21. macro(draco_get_intrinsics_flag_for_suffix)
  22. unset(intrinsics_SUFFIX)
  23. unset(intrinsics_VARIABLE)
  24. unset(optional_args)
  25. unset(multi_value_args)
  26. set(single_value_args SUFFIX VARIABLE)
  27. cmake_parse_arguments(intrinsics "${optional_args}" "${single_value_args}"
  28. "${multi_value_args}" ${ARGN})
  29. if(NOT (intrinsics_SUFFIX AND intrinsics_VARIABLE))
  30. message(FATAL_ERROR "draco_get_intrinsics_flag_for_suffix: SUFFIX and "
  31. "VARIABLE required.")
  32. endif()
  33. if(intrinsics_SUFFIX MATCHES "neon")
  34. if(NOT MSVC)
  35. set(${intrinsics_VARIABLE} "${DRACO_NEON_INTRINSICS_FLAG}")
  36. endif()
  37. elseif(intrinsics_SUFFIX MATCHES "sse4")
  38. if(NOT MSVC)
  39. set(${intrinsics_VARIABLE} "-msse4.1")
  40. endif()
  41. else()
  42. message(FATAL_ERROR "draco_get_intrinsics_flag_for_suffix: Unknown "
  43. "instrinics suffix: ${intrinsics_SUFFIX}")
  44. endif()
  45. if(DRACO_VERBOSE GREATER 1)
  46. message("draco_get_intrinsics_flag_for_suffix: "
  47. "suffix:${intrinsics_SUFFIX} flag:${${intrinsics_VARIABLE}}")
  48. endif()
  49. endmacro()
  50. # Processes source files specified by SOURCES and adds intrinsics flags as
  51. # necessary: draco_process_intrinsics_sources(SOURCES <sources>)
  52. #
  53. # Detects requirement for intrinsics flags using source file name suffix.
  54. # Currently supports only SSE4.1.
  55. macro(draco_process_intrinsics_sources)
  56. unset(arg_TARGET)
  57. unset(arg_SOURCES)
  58. unset(optional_args)
  59. set(single_value_args TARGET)
  60. set(multi_value_args SOURCES)
  61. cmake_parse_arguments(arg "${optional_args}" "${single_value_args}"
  62. "${multi_value_args}" ${ARGN})
  63. if(NOT (arg_TARGET AND arg_SOURCES))
  64. message(FATAL_ERROR "draco_process_intrinsics_sources: TARGET and "
  65. "SOURCES required.")
  66. endif()
  67. if(DRACO_ENABLE_SSE4_1 AND draco_have_sse4)
  68. unset(sse4_sources)
  69. list(APPEND sse4_sources ${arg_SOURCES})
  70. list(FILTER sse4_sources INCLUDE REGEX "${draco_sse4_source_file_suffix}$")
  71. if(sse4_sources)
  72. unset(sse4_flags)
  73. draco_get_intrinsics_flag_for_suffix(
  74. SUFFIX ${draco_sse4_source_file_suffix} VARIABLE sse4_flags)
  75. if(sse4_flags)
  76. draco_set_compiler_flags_for_sources(SOURCES ${sse4_sources} FLAGS
  77. ${sse4_flags})
  78. endif()
  79. endif()
  80. endif()
  81. if(DRACO_ENABLE_NEON AND draco_have_neon)
  82. unset(neon_sources)
  83. list(APPEND neon_sources ${arg_SOURCES})
  84. list(FILTER neon_sources INCLUDE REGEX "${draco_neon_source_file_suffix}$")
  85. if(neon_sources AND DRACO_NEON_INTRINSICS_FLAG)
  86. unset(neon_flags)
  87. draco_get_intrinsics_flag_for_suffix(
  88. SUFFIX ${draco_neon_source_file_suffix} VARIABLE neon_flags)
  89. if(neon_flags)
  90. draco_set_compiler_flags_for_sources(SOURCES ${neon_sources} FLAGS
  91. ${neon_flags})
  92. endif()
  93. endif()
  94. endif()
  95. endmacro()