FindLibspeexdsp.cmake 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #[=======================================================================[.rst
  2. FindLibspeexdsp
  3. ----------
  4. FindModule for Libspeexdsp and associated libraries
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. .. versionadded:: 2.0
  10. This module defines the :prop_tgt:`IMPORTED` target ``SpeexDSP::Libspeexdsp``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``Libspeexdsp_FOUND``
  15. True, if all required components and the core library were found.
  16. ``Libspeexdsp_VERSION``
  17. Detected version of found Libspeexdsp libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``Libspeexdsp_LIBRARY``
  22. Path to the library component of Libspeexdsp.
  23. ``Libspeexdsp_INCLUDE_DIR``
  24. Directory containing ``speex/speex_preprocess.h``.
  25. #]=======================================================================]
  26. # cmake-format: off
  27. # cmake-lint: disable=C0103
  28. # cmake-lint: disable=C0307
  29. # cmake-format: on
  30. include(FindPackageHandleStandardArgs)
  31. find_package(PkgConfig QUIET)
  32. if(PKG_CONFIG_FOUND)
  33. pkg_search_module(PC_Libspeexdsp QUIET speexdsp)
  34. endif()
  35. # libspeexdsp_set_soname: Set SONAME on imported library target
  36. macro(libspeexdsp_set_soname)
  37. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  38. execute_process(
  39. COMMAND sh -c "otool -D '${Libspeexdsp_LIBRARY}' | grep -v '${Libspeexdsp_LIBRARY}'"
  40. OUTPUT_VARIABLE _output
  41. RESULT_VARIABLE _result)
  42. if(_result EQUAL 0 AND _output MATCHES "^@rpath/")
  43. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_SONAME "${_output}")
  44. endif()
  45. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  46. execute_process(
  47. COMMAND sh -c "objdump -p '${Libspeexdsp_LIBRARY}' | grep SONAME"
  48. OUTPUT_VARIABLE _output
  49. RESULT_VARIABLE _result)
  50. if(_result EQUAL 0)
  51. string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}")
  52. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_SONAME "${_soname}")
  53. unset(_soname)
  54. endif()
  55. endif()
  56. unset(_output)
  57. unset(_result)
  58. endmacro()
  59. find_path(
  60. Libspeexdsp_INCLUDE_DIR
  61. NAMES speex/speex_preprocess.h
  62. HINTS ${PC_Libspeexdsp_INCLUDE_DIRS}
  63. PATHS /usr/include /usr/local/include
  64. DOC "Libspeexdsp include directory")
  65. if(PC_Libspeexdsp_VERSION VERSION_GREATER 0)
  66. set(Libspeexdsp_VERSION ${PC_Libspeexdsp_VERSION})
  67. else()
  68. if(NOT Libspeexdsp_FIND_QUIETLY)
  69. message(AUTHOR_WARNING "Failed to find Libspeexdsp version.")
  70. endif()
  71. set(Libspeexdsp_VERSION 0.0.0)
  72. endif()
  73. find_library(
  74. Libspeexdsp_LIBRARY
  75. NAMES speexdsp libspeexdsp
  76. HINTS ${PC_Libspeexdsp_LIBRARY_DIRS}
  77. PATHS /usr/lib /usr/local/lib
  78. DOC "Libspeexdsp location")
  79. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  80. set(Libspeexdsp_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
  81. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  82. set(Libspeexdsp_ERROR_REASON "Ensure that libspeexdsp is installed on the system.")
  83. endif()
  84. find_package_handle_standard_args(
  85. Libspeexdsp
  86. REQUIRED_VARS Libspeexdsp_LIBRARY Libspeexdsp_INCLUDE_DIR
  87. VERSION_VAR Libspeexdsp_VERSION REASON_FAILURE_MESSAGE "${Libspeexdsp_ERROR_REASON}")
  88. mark_as_advanced(Libspeexdsp_INCLUDE_DIR Libspeexdsp_LIBRARY)
  89. unset(Libspeexdsp_ERROR_REASON)
  90. if(Libspeexdsp_FOUND)
  91. if(NOT TARGET SpeexDSP::Libspeexdsp)
  92. if(IS_ABSOLUTE "${Libspeexdsp_LIBRARY}")
  93. add_library(SpeexDSP::Libspeexdsp UNKNOWN IMPORTED)
  94. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_LOCATION "${Libspeexdsp_LIBRARY}")
  95. else()
  96. add_library(SpeexDSP::Libspeexdsp INTERFACE IMPORTED)
  97. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_LIBNAME "${Libspeexdsp_LIBRARY}")
  98. endif()
  99. libspeexdsp_set_soname()
  100. set_target_properties(
  101. SpeexDSP::Libspeexdsp
  102. PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Libspeexdsp_CFLAGS_OTHER}"
  103. INTERFACE_INCLUDE_DIRECTORIES "${Libspeexdsp_INCLUDE_DIR}"
  104. VERSION ${Libspeexdsp_VERSION})
  105. endif()
  106. endif()
  107. include(FeatureSummary)
  108. set_package_properties(
  109. Libspeexdsp PROPERTIES
  110. URL "https://gitlab.xiph.org/xiph/speexdsp"
  111. DESCRIPTION "DSP library derived from speex.")