Skip to content

RtMidi is creating target "uninstall" without checking if such a target exists and causing CMake config to fail #369

Description

@IronAttorney

As stated in the title, RTMidi is creating a target uninstall without checking if such a target exists and causing CMake config to fail.

The other 3rd party libs I'm linking against that also try to create the target uninstall check first if such a target already exists, which might be what needs to happen in the RTMidi CMake too. This wasn't a problem until I upgraded CMake to 4.1 so I'm ready for the impending C++26... Apparently before that it was just silently ignoring the conflict or something.

Incase anyone else encounters this, my messy workaround currently is using this patch command to string replace a guard into your CMake during CPM package installation:

I have the following patch script ${PROJECT_SOURCE_DIR}/cmake/patch_rtmidi.cmake:

file(READ "${RTMIDI_SOURCE_DIR}/CMakeLists.txt" content)

string(REPLACE
        "add_custom_target(\${RTMIDI_TARGETNAME_UNINSTALL}"
        "if(NOT TARGET \${RTMIDI_TARGETNAME_UNINSTALL})\nadd_custom_target(\${RTMIDI_TARGETNAME_UNINSTALL}"
        content "${content}")

string(REPLACE
        "COMMAND \${CMAKE_COMMAND} -P \${CMAKE_BINARY_DIR}/RtMidiConfigUninstall.cmake)"
        "COMMAND \${CMAKE_COMMAND} -P \${CMAKE_BINARY_DIR}/RtMidiConfigUninstall.cmake)\nendif()"
        content "${content}")

file(WRITE "${RTMIDI_SOURCE_DIR}/CMakeLists.txt" "${content}")

And the modified CPM command to patch after it downloads the repo is as follows:

CPMAddPackage(
        NAME rtmidi
        GIT_REPOSITORY https://github.com/thestk/rtmidi
        GIT_TAG 5.0.0
        PATCH_COMMAND ${CMAKE_COMMAND} -DRTMIDI_SOURCE_DIR=<SOURCE_DIR> -P ${PROJECT_SOURCE_DIR}/cmake/patch_rtmidi.cmake
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions