From 0630eaa692e66216c023d55b133226ed0f5a8a6f Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Wed, 13 Dec 2023 07:19:03 +0100 Subject: [PATCH] Say hello to AuroraScanner CMake module Add a module with macros to generate client and server protocols. This will avoid users from directly depending on aurora-client or aurora-compositor. Closes: #2 --- .../AuroraScannerConfig.cmake.in | 6 + src/waylandscanner/AuroraScannerMacros.cmake | 164 ++++++++++++++++++ src/waylandscanner/CMakeLists.txt | 34 +++- 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 src/waylandscanner/AuroraScannerConfig.cmake.in create mode 100644 src/waylandscanner/AuroraScannerMacros.cmake diff --git a/src/waylandscanner/AuroraScannerConfig.cmake.in b/src/waylandscanner/AuroraScannerConfig.cmake.in new file mode 100644 index 0000000..ffb02b3 --- /dev/null +++ b/src/waylandscanner/AuroraScannerConfig.cmake.in @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2023 Pier Luigi Fiorini +# SPDX-License-Identifier: BSD-3-Clause + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/AuroraScannerMacros.cmake") diff --git a/src/waylandscanner/AuroraScannerMacros.cmake b/src/waylandscanner/AuroraScannerMacros.cmake new file mode 100644 index 0000000..105b09a --- /dev/null +++ b/src/waylandscanner/AuroraScannerMacros.cmake @@ -0,0 +1,164 @@ +# SPDX-FileCopyrightText: 2021-2023 Pier Luigi Fiorini +# SPDX-License-Identifier: BSD-3-Clause + +include(CMakeParseArguments) + +function(aurora_generate_wayland_protocol_client_sources target) + cmake_parse_arguments(_arg "" "" "FILES" ${ARGN}) + if(DEFINED _arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown arguments passed to aurora_generate_wayland_protocol_client_sources: (${_arg_UNPARSED_ARGUMENTS}).") + endif() + + get_target_property(target_binary_dir "${target}" BINARY_DIR) + + if(NOT TARGET Wayland::waylandscanner) + find_program(__wayland_scanner_exe NAMES "wayland-scanner" NO_CACHE REQUIRED) + add_executable(Wayland::waylandscanner IMPORTED) + set_target_properties(Wayland::waylandscanner PROPERTIES IMPORTED_LOCATION "${__wayland_scanner_exe}") + endif() + + if(NOT TARGET Aurora::waylandscanner) + find_program(__aurora_wayland_scanner_exe NAMES "aurora-wayland-scanner" NO_CACHE REQUIRED) + add_executable(Aurora::waylandscanner IMPORTED) + set_target_properties(Aurora::waylandscanner PROPERTIES IMPORTED_LOCATION "${__aurora_wayland_scanner_exe}") + endif() + + foreach(protocol_file IN LISTS _arg_FILES) + get_filename_component(protocol_name "${protocol_file}" NAME_WLE) + + set(c_code_path "${target_binary_dir}/wayland_generated/wayland-${protocol_name}-protocol.c") + set(c_header_path "${target_binary_dir}/wayland_generated/wayland-${protocol_name}-client-protocol.h") + set(cpp_code_path "${target_binary_dir}/wayland_generated/aurora-client-${protocol_name}.cpp") + set(cpp_header_path "${target_binary_dir}/wayland_generated/aurora-client-${protocol_name}.h") + + file(MAKE_DIRECTORY "${target_binary_dir}/wayland_generated") + + set_source_files_properties( + "${c_code_path}" + "${c_header_path}" + "${cpp_code_path}" + "${cpp_header_path}" + PROPERTIES + GENERATED ON + SKIP_AUTOMOC ON + ) + set_source_files_properties( + "${c_header_path}" + "${cpp_header_path}" + PROPERTIES + LIRI_PRIVATE_HEADER ON + ) + + add_custom_command( + OUTPUT "${c_header_path}" + COMMAND Wayland::waylandscanner --strict --include-core-only client-header "${protocol_file}" "${c_header_path}" + DEPENDS "${protocol_file}" + ) + add_custom_command( + OUTPUT "${c_code_path}" + COMMAND Wayland::waylandscanner --strict --include-core-only public-code "${protocol_file}" "${c_code_path}" + DEPENDS "${protocol_file}" "${c_header_path}" + ) + + add_custom_command( + OUTPUT "${cpp_header_path}" + COMMAND Aurora::waylandscanner client-header "${protocol_file}" "" > "${cpp_header_path}" + DEPENDS "${protocol_file}" "${c_header_path}" + ) + add_custom_command( + OUTPUT "${cpp_code_path}" + COMMAND Aurora::waylandscanner client-code "${protocol_file}" "" > "${cpp_code_path}" + DEPENDS "${protocol_file}" "${c_header_path}" "${cpp_header_path}" + ) + + target_sources("${target}" + PRIVATE + "${c_code_path}" + "${c_header_path}" + "${cpp_code_path}" + "${cpp_header_path}" + ) + endforeach() + + target_include_directories("${target}" PRIVATE "${target_binary_dir}/wayland_generated") +endfunction() + +function(aurora_generate_wayland_protocol_server_sources target) + cmake_parse_arguments(_arg "" "" "FILES" ${ARGN}) + if(DEFINED _arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown arguments passed to aurora_generate_wayland_protocol_server_sources: (${_arg_UNPARSED_ARGUMENTS}).") + endif() + + get_target_property(target_binary_dir "${target}" BINARY_DIR) + + if(NOT TARGET Wayland::waylandscanner) + find_program(__wayland_scanner_exe NAMES "wayland-scanner" NO_CACHE REQUIRED) + add_executable(Wayland::waylandscanner IMPORTED) + set_target_properties(Wayland::waylandscanner PROPERTIES IMPORTED_LOCATION "${__wayland_scanner_exe}") + endif() + + if(NOT TARGET Aurora::waylandscanner) + find_program(__aurora_wayland_scanner_exe NAMES "aurora-wayland-scanner" NO_CACHE REQUIRED) + add_executable(Aurora::waylandscanner IMPORTED) + set_target_properties(Aurora::waylandscanner PROPERTIES IMPORTED_LOCATION "${__aurora_wayland_scanner_exe}") + endif() + + foreach(protocol_file IN LISTS _arg_FILES) + get_filename_component(protocol_name "${protocol_file}" NAME_WLE) + + set(c_code_path "${target_binary_dir}/wayland_generated/wayland-${protocol_name}-protocol.c") + set(c_header_path "${target_binary_dir}/wayland_generated/wayland-${protocol_name}-server-protocol.h") + set(cpp_code_path "${target_binary_dir}/wayland_generated/aurora-server-${protocol_name}.cpp") + set(cpp_header_path "${target_binary_dir}/wayland_generated/aurora-server-${protocol_name}.h") + + file(MAKE_DIRECTORY "${target_binary_dir}/wayland_generated") + + set_source_files_properties( + "${c_code_path}" + "${c_header_path}" + "${cpp_code_path}" + "${cpp_header_path}" + PROPERTIES + GENERATED ON + SKIP_AUTOMOC ON + ) + set_source_files_properties( + "${c_header_path}" + "${cpp_header_path}" + PROPERTIES + LIRI_PRIVATE_HEADER ON + ) + + add_custom_command( + OUTPUT "${c_header_path}" + COMMAND Wayland::waylandscanner --strict --include-core-only server-header "${protocol_file}" "${c_header_path}" + DEPENDS "${protocol_file}" + ) + add_custom_command( + OUTPUT "${c_code_path}" + COMMAND Wayland::waylandscanner --strict --include-core-only public-code "${protocol_file}" "${c_code_path}" + DEPENDS "${protocol_file}" "${c_header_path}" + ) + + add_custom_command( + OUTPUT "${cpp_header_path}" + COMMAND Aurora::waylandscanner server-header "${protocol_file}" "" > "${cpp_header_path}" + DEPENDS "${protocol_file}" "${c_header_path}" + ) + add_custom_command( + OUTPUT "${cpp_code_path}" + COMMAND Aurora::waylandscanner server-code "${protocol_file}" "" > "${cpp_code_path}" + DEPENDS "${protocol_file}" "${c_header_path}" "${cpp_header_path}" + ) + + target_sources("${target}" + PRIVATE + "${c_code_path}" + "${c_header_path}" + "${cpp_code_path}" + "${cpp_header_path}" + ) + endforeach() + + target_include_directories("${target}" PRIVATE "${target_binary_dir}/wayland_generated") +endfunction() diff --git a/src/waylandscanner/CMakeLists.txt b/src/waylandscanner/CMakeLists.txt index 0d13df0..83b15cf 100644 --- a/src/waylandscanner/CMakeLists.txt +++ b/src/waylandscanner/CMakeLists.txt @@ -11,9 +11,41 @@ target_link_libraries(waylandscanner Qt6::Xml ) -add_executable(Liri::waylandscanner ALIAS waylandscanner) +add_executable(Aurora::waylandscanner ALIAS waylandscanner) install( TARGETS waylandscanner DESTINATION ${KDE_INSTALL_BINDIR} ) + +## Package: + +set(_cmakeconfig_install_dir "${KDE_INSTALL_CMAKEPACKAGEDIR}/AuroraScanner") + +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/AuroraScannerConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/AuroraScannerConfig.cmake" + INSTALL_DESTINATION + "${_cmakeconfig_install_dir}" +) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/AuroraScannerConfigVersion.cmake" + VERSION + "${PROJECT_VERSION}" + COMPATIBILITY + AnyNewerVersion +) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/AuroraScannerConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/AuroraScannerConfigVersion.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/AuroraScannerMacros.cmake" + DESTINATION + "${_cmakeconfig_install_dir}" + COMPONENT + Devel +)