# Install executable

**URL:** https://discourse.cmake.org/t/install-executable/2989
**Category:** Code
**Created:** [March 22, 2021, 9:21pm UTC](https://discourse.cmake.org/t/install-executable/2989 "2021-03-22T21:21:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [March 22, 2021, 9:21pm UTC](https://discourse.cmake.org/t/install-executable/2989/1 "2021-03-22T21:21:17Z")

</div>

Hi,

I currently can’t figure out how to install an application. Thought with modern cmake it should pretty much only be:

```
add_exectuable(Test ...) 
install(TARGETS Test)

```

And that’s it. That does literally install everything, all libaries Test depends on (headers, libs, documentation and whatnot), but not the executable itself.

What do I miss here?

 ![image](https://discourse.cmake.org/uploads/default/original/2X/3/3f714ee7a660b790704463ed01e0b8b9d0059de5.png)

Shouldn’t Test.out (or Test.exe on Windows) land into bin? Do I need anymore configuration?

I would be happy if my exetuable install, but as I’m already asking: Is there also a way to just install my executable (and perhaps libaries it needs) rather than literally everything (like headers, documentation, cmake files)?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 22, 2021, 9:26pm UTC](https://discourse.cmake.org/t/install-executable/2989/2 "2021-03-22T21:26:13Z")

</div>

Could you please share the full CMake around the executable? I suspect that you might be running into some corner of CMake that assumes things about CMake’s builtin targets (of which `test`, with a lowercase `t` is one). Does it work if you rename the executable target name?

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [March 22, 2021, 9:32pm UTC](https://discourse.cmake.org/t/install-executable/2989/3 "2021-03-22T21:32:47Z")

</div>

In src/CMakeLists.txt, stripped to the most relevant (I hope)

```
add_library(BeansCore STATIC)
target_link_libraries(BeansCore PUBLIC BeansVersion CLI11 sqlpp11::sqlite3 spdlog::spdlog)
target_include_directories(BeansCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(BeansApp Main.cpp)
target_link_libraries(BeansApp PRIVATE BeansCore)

```

In packing/CMakeListst.txt

```
include(GNUInstallDirs)

install(TARGETS BeansApp)

```

In CMakeLists.txt (Not sure if relevant, but I figure I messed with paths here?):

```
include(GNUInstallDirs)
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT WIN32 AND CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  set(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}")
endif()

```

I use:

`sudo cmake --install build --config Release`

but also tried with executing the install target.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 22, 2021, 9:48pm UTC](https://discourse.cmake.org/t/install-executable/2989/4 "2021-03-22T21:48:34Z")

</div>

This looks OK to me. Did you, perhaps, forget an `add_subdirectory(packing)`? Is there a `packing/cmake_install.cmake` script in the build tree? Does it mention `BeansApp`?

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [March 22, 2021, 9:56pm UTC](https://discourse.cmake.org/t/install-executable/2989/5 "2021-03-22T21:56:43Z")

</div>

> [@ben.boeckel](#):
>
> add\_subdirectory(packing)

I’m so stupid 🙄 Yeah that was it!

Is there any way to now only install my App and no deps?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 22, 2021, 11:04pm UTC](https://discourse.cmake.org/t/install-executable/2989/6 "2021-03-22T23:04:45Z")

</div>

You can assign install commands to specific components and then select them at install time.
