|
| 1 | +# ============================================================================== |
| 2 | +# |
| 3 | +# This file is part of the YUP library. |
| 4 | +# Copyright (c) 2025 - [email protected] |
| 5 | +# |
| 6 | +# YUP is an open source library subject to open-source licensing. |
| 7 | +# |
| 8 | +# The code included in this file is provided under the terms of the ISC license |
| 9 | +# http://www.isc.org/downloads/software-support-policy/isc-license. Permission |
| 10 | +# To use, copy, modify, and/or distribute this software for any purpose with or |
| 11 | +# without fee is hereby granted provided that the above copyright notice and |
| 12 | +# this permission notice appear in all copies. |
| 13 | +# |
| 14 | +# YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER |
| 15 | +# EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE |
| 16 | +# DISCLAIMED. |
| 17 | +# |
| 18 | +# ============================================================================== |
| 19 | + |
| 20 | +# ============================================================================== |
| 21 | + |
| 22 | +set (PLUGINVAL_VERSION "v1.0.4") |
| 23 | + |
| 24 | +# ============================================================================== |
| 25 | + |
| 26 | +function (yup_setup_pluginval) |
| 27 | + if (NOT YUP_ENABLE_PLUGINVAL) |
| 28 | + return() |
| 29 | + endif() |
| 30 | + |
| 31 | + # Only supported on desktop platforms |
| 32 | + if (NOT YUP_PLATFORM_DESKTOP) |
| 33 | + _yup_message (WARNING "pluginval is only supported on desktop platforms") |
| 34 | + return() |
| 35 | + endif() |
| 36 | + |
| 37 | + # Determine platform-specific download URL and executable name |
| 38 | + if (YUP_PLATFORM_WINDOWS) |
| 39 | + if (CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 40 | + set (PLUGINVAL_PLATFORM "Windows") |
| 41 | + set (PLUGINVAL_ARCHIVE "pluginval_Windows.zip") |
| 42 | + else() |
| 43 | + _yup_message (WARNING "pluginval does not support 32-bit Windows") |
| 44 | + return() |
| 45 | + endif() |
| 46 | + set (PLUGINVAL_EXECUTABLE "pluginval.exe") |
| 47 | + elseif (YUP_PLATFORM_MAC) |
| 48 | + set (PLUGINVAL_PLATFORM "macOS") |
| 49 | + set (PLUGINVAL_ARCHIVE "pluginval_macOS.zip") |
| 50 | + set (PLUGINVAL_EXECUTABLE "pluginval.app/Contents/MacOS/pluginval") |
| 51 | + elseif (YUP_PLATFORM_LINUX) |
| 52 | + set (PLUGINVAL_PLATFORM "Linux") |
| 53 | + set (PLUGINVAL_ARCHIVE "pluginval_Linux.zip") |
| 54 | + set (PLUGINVAL_EXECUTABLE "pluginval") |
| 55 | + else() |
| 56 | + _yup_message (WARNING "Unsupported platform for pluginval") |
| 57 | + return() |
| 58 | + endif() |
| 59 | + |
| 60 | + # Set up download URL |
| 61 | + set (PLUGINVAL_URL "https://github.com/Tracktion/pluginval/releases/download/${PLUGINVAL_VERSION}/${PLUGINVAL_ARCHIVE}") |
| 62 | + |
| 63 | + # Set up local paths |
| 64 | + set (PLUGINVAL_DIR "${CMAKE_BINARY_DIR}/pluginval") |
| 65 | + set (PLUGINVAL_ARCHIVE_PATH "${PLUGINVAL_DIR}/${PLUGINVAL_ARCHIVE}") |
| 66 | + set (PLUGINVAL_EXECUTABLE_PATH "${PLUGINVAL_DIR}/${PLUGINVAL_EXECUTABLE}") |
| 67 | + |
| 68 | + # Create pluginval directory |
| 69 | + file (MAKE_DIRECTORY "${PLUGINVAL_DIR}") |
| 70 | + |
| 71 | + # Download pluginval if not already present |
| 72 | + if (NOT EXISTS "${PLUGINVAL_EXECUTABLE_PATH}") |
| 73 | + _yup_message (STATUS "Downloading pluginval ${PLUGINVAL_VERSION} for ${PLUGINVAL_PLATFORM}") |
| 74 | + |
| 75 | + # Download the archive |
| 76 | + file (DOWNLOAD "${PLUGINVAL_URL}" "${PLUGINVAL_ARCHIVE_PATH}" |
| 77 | + SHOW_PROGRESS |
| 78 | + STATUS DOWNLOAD_STATUS) |
| 79 | + |
| 80 | + # Check if download was successful |
| 81 | + list (GET DOWNLOAD_STATUS 0 DOWNLOAD_ERROR) |
| 82 | + if (NOT DOWNLOAD_ERROR EQUAL 0) |
| 83 | + list (GET DOWNLOAD_STATUS 1 DOWNLOAD_ERROR_MESSAGE) |
| 84 | + _yup_message (FATAL_ERROR "Failed to download pluginval: ${DOWNLOAD_ERROR_MESSAGE}") |
| 85 | + endif() |
| 86 | + |
| 87 | + # Extract the archive |
| 88 | + _yup_message (STATUS "Extracting pluginval archive") |
| 89 | + execute_process( |
| 90 | + COMMAND ${CMAKE_COMMAND} -E tar xzf "${PLUGINVAL_ARCHIVE_PATH}" |
| 91 | + WORKING_DIRECTORY "${PLUGINVAL_DIR}" |
| 92 | + RESULT_VARIABLE EXTRACT_RESULT) |
| 93 | + |
| 94 | + if (NOT EXTRACT_RESULT EQUAL 0) |
| 95 | + _yup_message (FATAL_ERROR "Failed to extract pluginval archive") |
| 96 | + endif() |
| 97 | + |
| 98 | + # Make executable (Posix platforms) |
| 99 | + if (YUP_PLATFORM_POSIX) |
| 100 | + execute_process( |
| 101 | + COMMAND chmod +x "${PLUGINVAL_EXECUTABLE_PATH}" |
| 102 | + RESULT_VARIABLE CHMOD_RESULT) |
| 103 | + |
| 104 | + if (NOT CHMOD_RESULT EQUAL 0) |
| 105 | + _yup_message (WARNING "Failed to make pluginval executable") |
| 106 | + endif() |
| 107 | + endif() |
| 108 | + |
| 109 | + # Clean up archive |
| 110 | + file (REMOVE "${PLUGINVAL_ARCHIVE_PATH}") |
| 111 | + endif() |
| 112 | + |
| 113 | + # Verify pluginval executable exists |
| 114 | + if (NOT EXISTS "${PLUGINVAL_EXECUTABLE_PATH}") |
| 115 | + _yup_message (FATAL_ERROR "pluginval executable not found at: ${PLUGINVAL_EXECUTABLE_PATH}") |
| 116 | + endif() |
| 117 | + |
| 118 | + # Set global variable for use in other cmake files |
| 119 | + set (PLUGINVAL_EXECUTABLE "${PLUGINVAL_EXECUTABLE_PATH}" CACHE INTERNAL "Path to pluginval executable") |
| 120 | + |
| 121 | + _yup_message (STATUS "pluginval is available at: ${PLUGINVAL_EXECUTABLE_PATH}") |
| 122 | +endfunction() |
| 123 | + |
| 124 | +# ============================================================================== |
| 125 | + |
| 126 | +function (yup_validate_plugin target_name plugin_path) |
| 127 | + if (NOT YUP_ENABLE_PLUGINVAL OR NOT PLUGINVAL_EXECUTABLE) |
| 128 | + return() |
| 129 | + endif() |
| 130 | + |
| 131 | + set (validation_target_name "${target_name}_pluginval") |
| 132 | + |
| 133 | + add_custom_command( |
| 134 | + TARGET ${target_name} POST_BUILD |
| 135 | + COMMAND ${CMAKE_COMMAND} -E echo "[PLUGINVAL] Starting validation of ${target_name}..." |
| 136 | + COMMAND "${PLUGINVAL_EXECUTABLE}" --strictness-level 5 --validate-in-process --output-dir "${CMAKE_BINARY_DIR}/pluginval_reports" "${plugin_path}" |
| 137 | + COMMAND ${CMAKE_COMMAND} -E echo "[PLUGINVAL] Validation of ${target_name} completed" |
| 138 | + COMMENT "Running pluginval validation on ${target_name}" |
| 139 | + VERBATIM) |
| 140 | +endfunction() |
0 commit comments