From 2dc739e9b8f1e30f32e263dd9d65875f7feec366 Mon Sep 17 00:00:00 2001 From: Artur Sharafutdinov Date: Mon, 31 Mar 2025 11:24:10 +0200 Subject: [PATCH 1/2] Add CMake installation rules --- CMakeLists.txt | 21 +++++++++++++++++++++ README.md | 1 + 2 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb7e764..974464c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ if(WIN32) endif() option(CLIP_EXAMPLES "Compile clip examples" on) option(CLIP_TESTS "Compile clip tests" on) +option(CLIP_INSTALL "Enable clip installation" on) if(UNIX AND NOT APPLE) option(CLIP_X11_WITH_PNG "Compile with libpng to support copy/paste image in png format" on) endif() @@ -104,3 +105,23 @@ if(CLIP_TESTS) enable_testing() add_subdirectory(tests) endif() + +if(CLIP_INSTALL) + include(GNUInstallDirs) + + install( + FILES clip.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + install( + TARGETS clip + EXPORT clip-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + install( + EXPORT clip-targets + NAMESPACE clip:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip + ) +endif() diff --git a/README.md b/README.md index e9695db..1a52e84 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ int main() { [list_clip_formats](examples/list_clip_formats.cpp) example. * `CLIP_EXAMPLES`: Compile [examples](examples/). * `CLIP_TESTS`: Compile [tests](tests/). +* `CLIP_INSTALL`: Generate installation rules for CMake. * `CLIP_X11_WITH_PNG` (only for Linux/X11): Enables support to copy/paste images using the `libpng` library on Linux. From 40c2876ea2ccea5d49a1d01cc2754c3ffdcb209b Mon Sep 17 00:00:00 2001 From: Artur Sharafutdinov Date: Mon, 31 Mar 2025 22:13:33 +0200 Subject: [PATCH 2/2] Fix config --- CMakeLists.txt | 12 ++++++++++++ clip-config.cmake.in | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 clip-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 974464c..21e31bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,4 +124,16 @@ if(CLIP_INSTALL) NAMESPACE clip:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip ) + + include(CMakePackageConfigHelpers) + + configure_package_config_file( + clip-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/clip-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip + ) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clip-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/clip + ) endif() diff --git a/clip-config.cmake.in b/clip-config.cmake.in new file mode 100644 index 0000000..a3086e8 --- /dev/null +++ b/clip-config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@CMAKE_PROJECT_NAME@-targets.cmake") +check_required_components("@CMAKE_PROJECT_NAME@")