| --- a/lib/cpp/CMakeLists.txt 2021-03-19 12:05:26.400154009 +0000 |
| +++ b/lib/cpp/CMakeLists.txt 2021-03-19 12:06:51.220154009 +0000 |
| @@ -214,6 +214,86 @@ |
| install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}" |
| FILES_MATCHING PATTERN "*.h") |
| |
| +# Installation (https://github.com/forexample/package-example) |
| + |
| +# Introduce variables: |
| +# * CMAKE_INSTALL_LIBDIR |
| +# * CMAKE_INSTALL_BINDIR |
| +# * CMAKE_INSTALL_INCLUDEDIR |
| +include(GNUInstallDirs) |
| + |
| +# Layout. This works for all platforms: |
| +# * <prefix>/lib*/cmake/<PROJECT-NAME> |
| +# * <prefix>/lib*/ |
| +# * <prefix>/include/ |
| +set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") |
| + |
| +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") |
| + |
| +# Configuration |
| +set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") |
| +set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") |
| +set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") |
| +set(namespace "${PROJECT_NAME}::") |
| + |
| +# Include module with fuction 'write_basic_package_version_file' |
| +include(CMakePackageConfigHelpers) |
| + |
| +# Configure '<PROJECT-NAME>ConfigVersion.cmake' |
| +# Use: |
| +# * PROJECT_VERSION |
| +write_basic_package_version_file( |
| + "${version_config}" COMPATIBILITY SameMajorVersion |
| +) |
| + |
| +# Configure '<PROJECT-NAME>Config.cmake' |
| +# Use variables: |
| +# * TARGETS_EXPORT_NAME |
| +# * PROJECT_NAME |
| +configure_package_config_file( |
| + "${PROJECT_SOURCE_DIR}/build/cmake/Config.cmake.in" |
| + "${project_config}" |
| + INSTALL_DESTINATION "${config_install_dir}" |
| +) |
| + |
| +# Targets: |
| +# * <prefix>/lib/libthrift.a |
| +# * <prefix>/lib/libthrift.so |
| +# * header location after install: <prefix>/include/thrift/Thrift.h |
| +# * headers can be included by C++ code `#include <thrift/Thrift.h>` |
| +install( |
| + TARGETS ${thrift_lib_targets} |
| + EXPORT "${TARGETS_EXPORT_NAME}" |
| + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| +) |
| + |
| +# Headers: |
| +# * src/thrift/Thrift.h -> <prefix>/include/thrift/Thrift.h |
| +install( |
| + DIRECTORY "src/thrift" |
| + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| + FILES_MATCHING PATTERN "*.h" |
| +) |
| + |
| +# Config |
| +# * <prefix>/lib/cmake/thrift/thriftConfig.cmake |
| +# * <prefix>/lib/cmake/thrift/thriftConfigVersion.cmake |
| +install( |
| + FILES "${project_config}" "${version_config}" |
| + DESTINATION "${config_install_dir}" |
| +) |
| + |
| +# Config |
| +# * <prefix>/lib/cmake/thrift/thriftTargets.cmake |
| +install( |
| + EXPORT "${TARGETS_EXPORT_NAME}" |
| + NAMESPACE "${namespace}" |
| + DESTINATION "${config_install_dir}" |
| +) |
| + |
| if(BUILD_TESTING) |
| add_subdirectory(test) |
| endif() |