From abbade08f129154edc3eaf54f365e2ff39159fc9 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Sun, 28 Apr 2024 17:48:42 +0500 Subject: [PATCH] cmake: add hyprwayland-scanner-config (#1) This allows us to add wayland protocol dependencies to other cmake-based projects with minimum extra code. Example: find_package(hyprwayland-scanner REQUIRED) add_executable(target main.c) hyprwayland_protocol( target "linux-dmabuf-v1" "${WAYLAND_PROTOCOLS}/linux-dmabuf/" "${CMAKE_SOURCE_DIR}/protocols" ) --- CMakeLists.txt | 9 +++++++++ hyprwayland-scanner-config.cmake.in | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 hyprwayland-scanner-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index d709c00..9800fef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ project(hyprwayland-scanner ) include(GNUInstallDirs) +include(CMakePackageConfigHelpers) set(PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -42,6 +43,14 @@ file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") add_executable(hyprwayland-scanner ${SRCFILES}) target_link_libraries(hyprwayland-scanner PRIVATE rt Threads::Threads PkgConfig::deps) +configure_package_config_file( + hyprwayland-scanner-config.cmake.in + hyprwayland-scanner-config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hyprwayland-scanner" + PATH_VARS CMAKE_INSTALL_BINDIR +) + # Installation install(TARGETS hyprwayland-scanner) install(FILES ${CMAKE_BINARY_DIR}/hyprwayland-scanner.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(FILES ${CMAKE_BINARY_DIR}/hyprwayland-scanner-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hyprwayland-scanner) diff --git a/hyprwayland-scanner-config.cmake.in b/hyprwayland-scanner-config.cmake.in new file mode 100644 index 0000000..02096fe --- /dev/null +++ b/hyprwayland-scanner-config.cmake.in @@ -0,0 +1,15 @@ +@PACKAGE_INIT@ + +set_and_check(BINDIR "@PACKAGE_CMAKE_INSTALL_BINDIR@") + +function(hyprwayland_protocol targets protoName protoPath outputPath) + add_custom_command( + OUTPUT "${outputPath}/${protoName}.cpp" + COMMAND "${BINDIR}/hyprwayland-scanner" "${protoPath}/${protoName}.xml" "${outputPath}" + ) + foreach(target ${targets}) + target_sources(${target} PRIVATE "${outputPath}/${protoName}.cpp") + endforeach() +endfunction() + +check_required_components(hyprwayland-scanner)