From 4eecec17eaae0f6621e1c0c983225b44234a431c Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Wed, 29 Apr 2015 14:11:12 +0200 Subject: [PATCH] Config-mode install --- CMakeLists.txt | 51 +++++++++++++++++++++++++++++++++++++------ cmake/Config.cmake.in | 1 + 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f43dcc2..ef44bbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,13 +105,6 @@ target_link_libraries(bzip2_bin bz2) set_target_properties(bzip2_bin PROPERTIES OUTPUT_NAME bzip2) -install(TARGETS bz2 bzip2recover bzip2_bin - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include - ) - file(GLOB man1 ${bzip2_SOURCE_DIR}/*.1) @@ -195,3 +188,47 @@ add_test(NAME decompress_block_size_3 ) endif() + +#### +# Installation (https://github.com/forexample/package-example) + +set(config_install_dir "lib/cmake/${PROJECT_NAME}") +set(include_install_dir "include") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") + +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(CMakePackageConfigHelpers) + +# Note: PROJECT_VERSION is used as a VERSION +write_basic_package_version_file( + "${version_config}" COMPATIBILITY SameMajorVersion +) + +# Note: variable 'targets_export_name' used +configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY) + +install( + TARGETS bz2 bzip2recover bzip2_bin + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" + PUBLIC_HEADER DESTINATION "${include_install_dir}" +) + +install( + FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" +) + +install( + EXPORT "${targets_export_name}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" +) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..6e9256e --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")