portaudio.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2020 Fangjun Kuang (csukuangfj@gmail.com)
  2. # See ../LICENSE for clarification regarding multiple authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. function(download_portaudio)
  16. if(CMAKE_VERSION VERSION_LESS 3.11)
  17. # FetchContent is available since 3.11,
  18. # we've copied it to ${CMAKE_SOURCE_DIR}/cmake/Modules
  19. # so that it can be used in lower CMake versions.
  20. message(STATUS "Use FetchContent provided by sherpa-ncnn")
  21. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  22. endif()
  23. include(FetchContent)
  24. set(portaudio_URL "http://files.portaudio.com/archives/pa_stable_v190700_20210406.tgz")
  25. set(portaudio_HASH "SHA256=47efbf42c77c19a05d22e627d42873e991ec0c1357219c0d74ce6a2948cb2def")
  26. if(BUILD_SHARED_LIBS)
  27. set(PA_BUILD_SHARED ON CACHE BOOL "" FORCE)
  28. set(PA_BUILD_STATIC OFF CACHE BOOL "" FORCE)
  29. else()
  30. set(PA_BUILD_SHARED OFF CACHE BOOL "" FORCE)
  31. set(PA_BUILD_STATIC ON CACHE BOOL "" FORCE)
  32. endif()
  33. FetchContent_Declare(portaudio
  34. URL ${portaudio_URL}
  35. URL_HASH ${portaudio_HASH}
  36. )
  37. FetchContent_GetProperties(portaudio)
  38. if(NOT portaudio_POPULATED)
  39. message(STATUS "Downloading portaudio")
  40. FetchContent_Populate(portaudio)
  41. endif()
  42. message(STATUS "portaudio is downloaded to ${portaudio_SOURCE_DIR}")
  43. message(STATUS "portaudio's binary dir is ${portaudio_BINARY_DIR}")
  44. if(APPLE)
  45. set(CMAKE_MACOSX_RPATH ON) # to solve the following warning on macOS
  46. endif()
  47. add_subdirectory(${portaudio_SOURCE_DIR} ${portaudio_BINARY_DIR} EXCLUDE_FROM_ALL)
  48. endfunction()
  49. download_portaudio()
  50. # Note
  51. # See http://portaudio.com/docs/v19-doxydocs/tutorial_start.html
  52. # for how to use portaudio