thestk / rtaudio

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.
Other
1.49k stars 318 forks source link

rtaudio and rtmidi have CMake target collisions #339

Open charliehuge opened 2 years ago

charliehuge commented 2 years ago

I was using rtmidi in a CMake project using FetchContent like this:

    FetchContent_Declare(
            rtmidi
            GIT_REPOSITORY https://github.com/thestk/rtmidi.git)
    FetchContent_MakeAvailable(rtmidi)

This worked fine until I wanted to also include rtaudio. If I do the same as above to get rtaudio and make it available to my targets, I get an error like this:

CMake Error at rtmidi/CMakeLists.txt:271 (add_custom_target):
  add_custom_target cannot create target "uninstall" because another target
  with the same name already exists.  The existing target is a custom target
  created in source directory "/blah/blah/rtaudio".
  See documentation for policy CMP0002 for more details.

I can get around this by including rtaudio and rtmidi directly in my project as submodules, then modifying the CMakeLists.txt for each library to either change the names or just remove the targets (I don't need them). But now I have a fork of each library to maintain just to use both things.

First off, am I missing something obvious? If not, how do users of both libraries typically handle this?

sonoro1234 commented 2 years ago

Perhaps you could try this:

https://github.com/sonoro1234/LuaJIT-rtaudio/blob/0a80f698a8e7188c95725d71ec63665935a39b0c/CMakeLists.txt#L26

garyscavone commented 2 years ago

Not clear to me whether this is still a problematic issue or not. If I don't see further discussion, I'll close it then next time I cull the issues list.

DrZlo13 commented 1 year ago

@garyscavone set(RTAUDIO_TARGETNAME_UNINSTALL "uninstall_rtaudio" ... solves the current issue for me.

If anybody after me will face error:

add_custom_target cannot create target "uninstall" because another target with the same name already exists.

This can be fixed with the following lines in your CMakeLists.txt:


set(RTAUDIO_BUILD_TESTING OFF CACHE INTERNAL "RTAudio: Build without tests")
set(RTAUDIO_TARGETNAME_UNINSTALL "uninstall_rtaudio" CACHE INTERNAL "RTAudio: change uninstall target name" FORCE)
add_subdirectory("lib/rtaudio" "rtaudio")

set(RTMIDI_BUILD_TESTING OFF CACHE INTERNAL "RTMidi: Build without tests")
set(RTMIDI_TARGETNAME_UNINSTALL "uninstall_rtmidi" CACHE INTERNAL "RTMidi: change uninstall target name" FORCE)
add_subdirectory("lib/rtmidi" "rtmidi")
DrZlo13 commented 1 year ago

I think the current issue can be closed, but documentation is needed for using rtmidi and rtaudio in the same project.

witte commented 7 months ago

It would be nice to have an option to disable the uninstall target completely, I could make a PR for that if there's interest 👍