From a1527df67fac637c3e7c9a2d9c7764517e6da01f Mon Sep 17 00:00:00 2001 From: Erik Rigtorp Date: Thu, 16 Apr 2020 17:51:27 -0700 Subject: [PATCH] Add CMake install support --- CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6560f0b..86cf0ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.6) -project(SPSCQueue LANGUAGES CXX) +project(SPSCQueue VERSION 1.0 LANGUAGES CXX) add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11) -target_include_directories(SPSCQueue INTERFACE +target_include_directories(${PROJECT_NAME} INTERFACE $ $) @@ -42,4 +42,43 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) enable_testing() add_test(SPSCQueueTest SPSCQueueTest) +endif() + +# Install +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY SameMajorVersion +) + +export( + TARGETS ${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}:: + FILE "${PROJECT_NAME}Config.cmake" +) + +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + install( + DIRECTORY "include/" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + + install( + TARGETS ${PROJECT_NAME} + EXPORT "${PROJECT_NAME}Config" + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + + install( + EXPORT "${PROJECT_NAME}Config" + NAMESPACE ${PROJECT_NAME}:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) + + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) endif() \ No newline at end of file