PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.37k stars 286 forks source link

CMake install files cannot be found using find_package #912

Open stac21 opened 1 month ago

stac21 commented 1 month ago

(Please use the mailing list for support requests and general discussion. This is only for actual bugs.)

Describe the bug After building and installing via CMake, I tried to include the library in my CMake project but was met with the following error and was unable to build my CMake project

CMake Warning at CMakeLists.txt:8 (find_package):
  By not providing "Findportaudio.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "portaudio", but CMake did not find one.

  Could not find a package configuration file provided by "portaudio" with
  any of the following names:

    portaudioConfig.cmake
    portaudio-config.cmake

  Add the installation prefix of "portaudio" to CMAKE_PREFIX_PATH or set
  "portaudio_DIR" to a directory containing one of the above files.  If
  "portaudio" provides a separate development package or SDK, be sure it has
  been installed.

To Reproduce Steps to reproduce the behavior. Include code if applicable.

  1. Clone PortAudio repo master branch
  2. Build and install PortAudio using cmake
    cd build
    cmake ..
    sudo make install
  3. In a separate CMake project, include the following lines in your CMakeLists.txt file
    find_package(port_audio)
    target_link_libraries(${TARGET} PortAudio::PortAudio)

Expected behavior Obviously, the expected behavior is for my project to build with portaudio included. I was able to successfully build my project after manually going to the location where the portaudio .cmake files were installed and renaming them to match the expected CMake naming convention.

/usr/local/lib/cmake/portaudio# ls
PortAudioConfig.cmake            PortAudioTargets.cmake          portaudio-targets-noconfig.cmake
PortAudioConfigVersion.cmake     portaudio-config-version.cmake  portaudio-targets.cmake
PortAudioTargets-noconfig.cmake  portaudio-config.cmake

Desktop (please complete the following information):

Additional context Full CMake project CMakeLists.txt script

cmake_minimum_required(VERSION 3.14)

project(audio-sandbox VERSION 0.0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED 20)

find_package(portaudio)

if (portaudio_FOUND)
    message(STATUS "PortAudio version: " ${portaudio_VERSION})
else()
    message(FATAL_ERROR "PortAudio NOT found!")
endif()

set(SOURCE_FILES
    main.cpp
)

set(TARGET sandbox)

add_executable(${TARGET} ${SOURCE_FILES})
target_link_libraries(${TARGET} PortAudio::PortAudio)

Note: PortAudio is a community supported project. If you have a solution, please create a Pull Request for us to consider.