From 87467048df10e72540a5abcac9dd5c0c4df3a712 Mon Sep 17 00:00:00 2001 From: Sam Fuller Date: Fri, 4 Jan 2019 14:53:04 -0700 Subject: [PATCH] Adding install commands and cmake build config file support --- CMakeLists.txt | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- Config.cmake.in | 4 ++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 37fdd7b..6a18637 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,54 @@ cmake_minimum_required(VERSION 3.10) -project(lzokay) +include(CMakePackageConfigHelpers) + +project(lzokay VERSION 0.1 LANGUAGES CXX) add_library(lzokay lzokay.hpp lzokay.cpp) set(LZOKAY_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "lzokay include path" FORCE) add_executable(lzokaytest test.cpp) -target_link_libraries(lzokaytest lzokay) \ No newline at end of file +target_link_libraries(lzokaytest lzokay) +set_target_properties(lzokay lzokaytest PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON) + +# Set installation for headers +install( + FILES "${PROJECT_SOURCE_DIR}/lzokay.hpp" + DESTINATION "include/lzokay" +) + +set(version_config_file "${PROJECT_BINARY_DIR}/lzokayConfigVersion.cmake") +set(config_file "${PROJECT_BINARY_DIR}/lzokayConfig.cmake") +set(config_install_dir "lib/cmake/lzokay") + +# Associate target with export +install( + TARGETS lzokay + EXPORT lzokayTargets + ARCHIVE DESTINATION "lib" + INCLUDES DESTINATION "include/lzokay" # This sets the INTERFACE_INCLUDE_DIRECTORIES property of the target. +) + +# Install the target config files +install( + EXPORT lzokayTargets + NAMESPACE "lzokay::" + DESTINATION "${config_install_dir}" +) + +# Generate version config file +write_basic_package_version_file( + "${version_config_file}" + COMPATIBILITY SameMajorVersion +) + +# Generate config file +configure_package_config_file( + "Config.cmake.in" + "${config_file}" + INSTALL_DESTINATION "lib/cmake/lzokay" +) + +# Install the config files +install( + FILES "${config_file}" "${version_config_file}" + DESTINATION ${config_install_dir} +) + diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 0000000..fde202f --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/lzokayTargets.cmake") +check_required_components(lzokay)