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"
)
This commit is contained in:
Yaroslav 2024-04-28 17:48:42 +05:00 committed by GitHub
parent 126dad854f
commit abbade08f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -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)

View File

@ -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)