Install executable

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?

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

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?

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.

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?

I’m so stupid :roll_eyes: Yeah that was it!

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

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

1 Like