commit f8f2f472d5f53827e69ffccee4c07c1a7f00a22c parent 84cb8116063ff59e80d298979dc0861f10f1a083 Author: Alexandre Bique <bique.alexandre@gmail.com> Date: Thu, 3 Nov 2022 16:16:42 +0100 Merge pull request #199 from robbert-vdh/feature/cmake-package-files Provide an installation target with CMake and pkg-config package files Diffstat:
M | CMakeLists.txt | | | 34 | ++++++++++++++++++++++++++++------ |
A | clap.pc.in | | | 8 | ++++++++ |
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -1,16 +1,38 @@ cmake_minimum_required(VERSION 3.17) enable_testing() -project(CLAP C CXX) +project(CLAP LANGUAGES C CXX VERSION 1.1.2) option(CLAP_BUILD_TESTS "Should CLAP build tests and the like?" OFF) # If you use clap as a submodule of your plugin you need some interface projects -# to allow you to link. clap-core gives you the include directory and clap-plugin-core -# gives you the core + plugin-glue. -add_library(clap-core INTERFACE) -target_include_directories(clap-core INTERFACE include) +# to allow you to link +add_library(clap INTERFACE) +target_include_directories(clap INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) -install(DIRECTORY include DESTINATION "." OPTIONAL EXCLUDE_FROM_ALL) +# Older versions of the CLAP interfaces only defined a `clap-core` library. +# Exposing the main library with the same name as the project makes it much +# simpler for build systems to find the CLAP package. +add_library(clap-core ALIAS clap) + +include(GNUInstallDirs) +install(DIRECTORY "include/clap" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(TARGETS clap EXPORT clap INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(EXPORT clap DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/clap" FILE "clap-config.cmake") + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/clap-config-version.cmake" + VERSION "${PROJECT_VERSION}" + COMPATIBILITY AnyNewerVersion) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/clap-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/clap") + +# In addition to the above generated `clap-config.cmake` file, we'll also +# provide a pkg-config file to make it easier to consume this library in a +# portable way +configure_file(clap.pc.in "${CMAKE_CURRENT_BINARY_DIR}/clap.pc" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/clap.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # clap-tests should always be available, to avoid build failing here and there # because the target doesn't exists diff --git a/clap.pc.in b/clap.pc.in @@ -0,0 +1,8 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: clap +Description: The interface headers for the CLAP audio plugin API +Version: @CMAKE_PROJECT_VERSION@ + +Cflags: -I${includedir}