Skip to content

Instantly share code, notes, and snippets.

@bjoernsauer
Last active September 18, 2022 16:49
Show Gist options
  • Save bjoernsauer/85308853c50bcef4f1ee362633e219a8 to your computer and use it in GitHub Desktop.
Save bjoernsauer/85308853c50bcef4f1ee362633e219a8 to your computer and use it in GitHub Desktop.
CMake install with Configuration Directory CMake. Shows how to use the install() command to install into a directory that includes the current configuration type as subfolder. For Example lib/MyLibrary/Release or lib/MyLibrary/Debug
project(cmake-install)
cmake_minimum_required(VERSION 3.12)
add_library(MyLibrary main.cpp)
target_include_directories(MyLibrary
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
include(GNUInstallDirs)
install(TARGETS MyLibrary
EXPORT MyLibraryExports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/MyLibrary/$<CONFIG>
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/MyLibrary/$<CONFIG>
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/MyLibrary/$<CONFIG>)
install(EXPORT MyLibraryExports DESTINATION lib/MyLibrary/cmake)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment