ExternalProject_Add install permission denied

Hi, I wanted to use a library that does not have a system Package, or a package from any package manager like conan or vcpkg. I tried using ExternalProjecct_Add and when I managed not not misstype half the parameters it worked pretty well. But on the install step I got a Permission Denied error that I could not really track down. Running the toplevel cmake command as root did not change the error message in the slightest.
Am I stupid, do I even need to install the library, if I want to link against it?

You probably want to override the default install location, otherwise it will try to install the package to the system area (e.g. /usr/local on Unix-based systems). The essential elements you are missing would be something like these:

    INSTALL_DIR <PREFIX>/install

That’s just one way to do it. I chose to use INSTALL_DIR mostly to be explicit about what I’m doing, but you could just put the install location directly in the CMAKE_ARGS line. The <PREFIX> and <INSTALL_DIR> parts will be automatically substituted when constructing the commands to run at build time.

In some cases, you don’t need to install the project in order to use it. Sometimes you can use the binaries directly from the build directory of the package. It’s probably not advisable to do that unless the package doesn’t have robust install rules defined. If you want to disable the install step, set INSTALL_COMMAND to an empty string.

Do I need to do something special, if I want to dynamically link aganist the library, or would you recommend using fetch_content?
Maybe I can link the github of the project that I try to include in my project, so you could tell if you would prefer fetch or ExternalProject.

You have to decide what works best for you. There are advantages and disadvantages to both approaches. FetchContent tends to be simpler, but some dependencies don’t expect to be pulled in that way and may do things which make it hard to take that path (e.g. using CMAKE_SOURCE_DIR instead of CMAKE_CURRENT_SOURCE_DIR, using target names that your main project also defines).

I personally would prefer ExternalProject, because It does everything for me. But now I have to figure it out myself. What impact does the install dir have? Do I need to be aware of more things than simply changing the install dir, if I want to install my project later?

ExternalProject_Add( libremidi
        GIT_REPOSITORY              git@github.com:jcelerier/libremidi.git
        GIT_TAG                     origin/master
        GIT_PROGRESS                true
        PREFIX                      external/libremidi
        CMAKE_GENERATOR             Ninja
        STEP_TARGETS                build
        BUILD_ALWAYS                true

This is my code for this library. What would you change, so I can use it and it gets installed if i run cmake install in my own project?

I noticed, that this library supports to be used as header only. So I’m going to try it, since I’m not getting the library to be includable the normal way.
I would only need some Dfinitions, so it can work:
Could you halp me to get them working, so it builds as header only?