FindLibrnnoise.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #[=======================================================================[.rst
  2. FindLibrnnoise
  3. ----------
  4. FindModule for Librnnoise 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 ``Librnnoise::Librnnoise``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``Librnnoise_FOUND``
  15. True, if all required components and the core library were found.
  16. ``Librnnoise_VERSION``
  17. Detected version of found Librnnoise libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``Librnnoise_LIBRARY``
  22. Path to the library component of Librnnoise.
  23. ``Librnnoise_INCLUDE_DIR``
  24. Directory containing ``rnnoise.h``.
  25. #]=======================================================================]
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_Librnnoise QUIET rnnoise)
  30. endif()
  31. # librrnoise_set_soname: Set SONAME on imported library target
  32. macro(librnnoise_set_soname)
  33. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  34. execute_process(
  35. COMMAND sh -c "otool -D '${Librnnoise_LIBRARY}' | grep -v '${Librnnoise_LIBRARY}'"
  36. OUTPUT_VARIABLE _output
  37. RESULT_VARIABLE _result
  38. )
  39. if(_result EQUAL 0 AND _output MATCHES "^@rpath/")
  40. set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_SONAME "${_output}")
  41. endif()
  42. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  43. execute_process(
  44. COMMAND sh -c "objdump -p '${Librnnoise_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 Librnnoise::Librnnoise PROPERTY IMPORTED_SONAME "${_soname}")
  51. unset(_soname)
  52. endif()
  53. endif()
  54. unset(_output)
  55. unset(_result)
  56. endmacro()
  57. find_path(
  58. Librnnoise_INCLUDE_DIR
  59. NAMES rnnoise.h
  60. HINTS ${PC_Librnnoise_INCLUDE_DIRS}
  61. PATHS /usr/include /usr/local/include
  62. DOC "Librnnoise include directory"
  63. )
  64. if(PC_Librnnoise_VERSION VERSION_GREATER 0)
  65. set(Librnnoise_VERSION ${PC_Librnnoise_VERSION})
  66. else()
  67. if(NOT Librnnoise_FIND_QUIETLY)
  68. message(AUTHOR_WARNING "Failed to find Librnnoise version.")
  69. endif()
  70. set(Librnnoise_VERSION 0.0.0)
  71. endif()
  72. find_library(
  73. Librnnoise_LIBRARY
  74. NAMES rnnoise librnnoise
  75. HINTS ${PC_Librnnoise_LIBRARY_DIRS}
  76. PATHS /usr/lib /usr/local/lib
  77. DOC "Librnnoise location"
  78. )
  79. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  80. set(Librnnoise_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(Librnnoise_ERROR_REASON "Ensure librnnoise libraries are available in local libary paths.")
  83. endif()
  84. find_package_handle_standard_args(
  85. Librnnoise
  86. REQUIRED_VARS Librnnoise_LIBRARY Librnnoise_INCLUDE_DIR
  87. VERSION_VAR Librnnoise_VERSION
  88. REASON_FAILURE_MESSAGE "${Librnnoise_ERROR_REASON}"
  89. )
  90. mark_as_advanced(Librnnoise_INCLUDE_DIR Librnnoise_LIBRARY)
  91. unset(Librnnoise_ERROR_REASON)
  92. if(Librnnoise_FOUND)
  93. if(NOT TARGET Librnnoise::Librnnoise)
  94. if(IS_ABSOLUTE "${Librnnoise_LIBRARY}")
  95. add_library(Librnnoise::Librnnoise UNKNOWN IMPORTED)
  96. librnnoise_set_soname()
  97. set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_LOCATION "${Librnnoise_LIBRARY}")
  98. else()
  99. add_library(Librnnoise::Librnnoise INTERFACE IMPORTED)
  100. set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_LIBNAME "${Librnnoise_LIBRARY}")
  101. endif()
  102. set_target_properties(
  103. Librnnoise::Librnnoise
  104. PROPERTIES
  105. INTERFACE_COMPILE_OPTIONS "${PC_Librnnoise_CFLAGS_OTHER}"
  106. INTERFACE_INCLUDE_DIRECTORIES "${Librnnoise_INCLUDE_DIR}"
  107. VERSION ${Librnnoise_VERSION}
  108. )
  109. endif()
  110. endif()
  111. include(FeatureSummary)
  112. set_package_properties(
  113. Librnnoise
  114. PROPERTIES
  115. URL "https://gitlab.xiph.org/xiph/rnnoise"
  116. DESCRIPTION "Recurrent neural network for audio noise reduction."
  117. )