Created
October 25, 2021 16:55
-
-
Save dvigne/5b540c9c131befc74b6fa0dd79c76355 to your computer and use it in GitHub Desktop.
Shared Library Packaging wth Cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project(MyLib) | |
cmake_minimum_required(VERSION 3.22) | |
include(GNUInstallDirs) | |
add_library(MyLib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/MyLib.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/MyLib.hpp) | |
target_include_directories(MyLib PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>" "$<INSTALL_INTERFACE:include>") | |
install(TARGETS MyLib | |
EXPORT MyLibTargets | |
LIBRARY DESTINATION lib | |
INCLUDES DESTINATION include | |
) | |
install(FILES ${CMAKE_CURRENT_LIST_DIR}/src/MyLib.hpp DESTINATION include) | |
install(EXPORT MyLibTargets | |
FILE MyLibTargets.cmake | |
NAMESPACE MyLib:: | |
DESTINATION lib/cmake/MyLib | |
) | |
export(TARGETS MyLib FILE lib/MyLibConfig.cmake) | |
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON) | |
export(PACKAGE MyLib) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment