# ExternalProject\_Add install permission denied

**URL:** https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846
**Category:** Usage
**Tags:** os:linux
**Created:** [June 12, 2022, 8:09am UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846 "2022-06-12T08:09:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![StefanSchmelz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@StefanSchmelz](https://discourse.cmake.org/u/StefanSchmelz)
#### Post date: [June 12, 2022, 8:09am UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846/1 "2022-06-12T08:09:22Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [June 12, 2022, 9:35pm UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846/2 "2022-06-12T21:35:45Z")

</div>

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:

```cmake
ExternalProject_Add(something
    ...
    INSTALL_DIR <PREFIX>/install
    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
    ...
)

```

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.

---

<div class="post-metadata">

### Author: ![StefanSchmelz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@StefanSchmelz](https://discourse.cmake.org/u/StefanSchmelz)
#### Post date: [June 12, 2022, 9:46pm UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846/3 "2022-06-12T21:46:33Z")

</div>

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.

> **[GitHub - jcelerier/libremidi: A modern C++ MIDI real-time & file I/O...](https://github.com/jcelerier/libremidi)**
>
> A modern C++ MIDI real-time & file I/O library. Supports Windows, macOS, Linux and WebMIDI. - GitHub - jcelerier/libremidi: A modern C++ MIDI real-time & file I/O library. Supports Windows,...

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [June 12, 2022, 9:53pm UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846/4 "2022-06-12T21:53:17Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![StefanSchmelz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@StefanSchmelz](https://discourse.cmake.org/u/StefanSchmelz)
#### Post date: [June 12, 2022, 11:07pm UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846/5 "2022-06-12T23:07:59Z")

</div>

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?

```auto
ExternalProject_Add( libremidi
        GIT_REPOSITORY git@github.com:jcelerier/libremidi.git
        GIT_TAG origin/master
        GIT_PROGRESS true
        GIT_REMOTE_UPDATE_STRATEGY CHECKOUT
        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?

---

<div class="post-metadata">

### Author: ![StefanSchmelz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@StefanSchmelz](https://discourse.cmake.org/u/StefanSchmelz)
#### Post date: [June 13, 2022, 2:15am UTC](https://discourse.cmake.org/t/externalproject-add-install-permission-denied/5846/6 "2022-06-13T02:15:51Z")

</div>

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:  
`LIBREMIDI_HEADER_ONLY=1`  
`LIBREMIDI_ALSA=1`  
Could you halp me to get them working, so it builds as header only?
