FindLibspeexdsp.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_Libspeexdsp QUIET speexdsp)
  30. endif()
  31. # libspeexdsp_set_soname: Set SONAME on imported library target
  32. macro(libspeexdsp_set_soname)
  33. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  34. execute_process(
  35. COMMAND sh -c "otool -D '${Libspeexdsp_LIBRARY}' | grep -v '${Libspeexdsp_LIBRARY}'"
  36. OUTPUT_VARIABLE _output
  37. RESULT_VARIABLE _result
  38. )
  39. if(_result EQUAL 0 AND _output MATCHES "^@rpath/")
  40. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_SONAME "${_output}")
  41. endif()
  42. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  43. execute_process(
  44. COMMAND sh -c "objdump -p '${Libspeexdsp_LIBRARY}' | grep SONAME"
  45. OUTPUT_VARIABLE _output
  46. RESULT_VARIABLE _result
  47. )
  48. if(_result EQUAL 0)
  49. string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}")
  50. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_SONAME "${_soname}")
  51. unset(_soname)
  52. endif()
  53. endif()
  54. unset(_output)
  55. unset(_result)
  56. endmacro()
  57. find_path(
  58. Libspeexdsp_INCLUDE_DIR
  59. NAMES speex/speex_preprocess.h
  60. HINTS ${PC_Libspeexdsp_INCLUDE_DIRS}
  61. PATHS /usr/include /usr/local/include
  62. DOC "Libspeexdsp include directory"
  63. )
  64. if(PC_Libspeexdsp_VERSION VERSION_GREATER 0)
  65. set(Libspeexdsp_VERSION ${PC_Libspeexdsp_VERSION})
  66. else()
  67. if(NOT Libspeexdsp_FIND_QUIETLY)
  68. message(AUTHOR_WARNING "Failed to find Libspeexdsp version.")
  69. endif()
  70. set(Libspeexdsp_VERSION 0.0.0)
  71. endif()
  72. find_library(
  73. Libspeexdsp_LIBRARY
  74. NAMES speexdsp libspeexdsp
  75. HINTS ${PC_Libspeexdsp_LIBRARY_DIRS}
  76. PATHS /usr/lib /usr/local/lib
  77. DOC "Libspeexdsp location"
  78. )
  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
  88. REASON_FAILURE_MESSAGE "${Libspeexdsp_ERROR_REASON}"
  89. )
  90. mark_as_advanced(Libspeexdsp_INCLUDE_DIR Libspeexdsp_LIBRARY)
  91. unset(Libspeexdsp_ERROR_REASON)
  92. if(Libspeexdsp_FOUND)
  93. if(NOT TARGET SpeexDSP::Libspeexdsp)
  94. if(IS_ABSOLUTE "${Libspeexdsp_LIBRARY}")
  95. add_library(SpeexDSP::Libspeexdsp UNKNOWN IMPORTED)
  96. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_LOCATION "${Libspeexdsp_LIBRARY}")
  97. else()
  98. add_library(SpeexDSP::Libspeexdsp INTERFACE IMPORTED)
  99. set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_LIBNAME "${Libspeexdsp_LIBRARY}")
  100. endif()
  101. libspeexdsp_set_soname()
  102. set_target_properties(
  103. SpeexDSP::Libspeexdsp
  104. PROPERTIES
  105. INTERFACE_COMPILE_OPTIONS "${PC_Libspeexdsp_CFLAGS_OTHER}"
  106. INTERFACE_INCLUDE_DIRECTORIES "${Libspeexdsp_INCLUDE_DIR}"
  107. VERSION ${Libspeexdsp_VERSION}
  108. )
  109. endif()
  110. endif()
  111. include(FeatureSummary)
  112. set_package_properties(
  113. Libspeexdsp
  114. PROPERTIES URL "https://gitlab.xiph.org/xiph/speexdsp" DESCRIPTION "DSP library derived from speex."
  115. )