Files

63 lines
2.9 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# VDE 插件 SDK 模板:format(独立构建,不加入 VDE 默认构建)
#
# 用法(在模板目录或任意目录):
# cmake -S plugins/templates/format_plugin -B build/template_format -DVDE_SDK_DIR=<VDE 源码根|安装前缀>
# cmake --build build/template_format
# 产物:<build>/plugin/{vde_template_format.dll|libvde_template_format.so, vde-plugin.json}
#
# 只依赖纯 C ABI 头 include/vde/plugin/vde_plugin_api.h,不链接 VDE 内核库。
cmake_minimum_required(VERSION 3.16)
project(vde_template_format LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# 定位插件 SDK:
# 1) 安装后的 vde-plugin-sdk 包:find_package(vde-plugin-sdk CONFIG)
# 2) -DVDE_SDK_DIR=<VDE 源码根/安装前缀> 的兼容路径
find_package(vde-plugin-sdk CONFIG QUIET)
if(NOT TARGET vde::plugin-sdk)
set(_vde_include "${VDE_SDK_DIR}/include")
if(NOT VDE_SDK_DIR OR NOT EXISTS "${_vde_include}/vde/plugin/vde_plugin_api.h")
set(_vde_include "${CMAKE_CURRENT_SOURCE_DIR}/../../../include")
endif()
if(NOT EXISTS "${_vde_include}/vde/plugin/vde_plugin_api.h")
message(FATAL_ERROR "找不到 vde/plugin/vde_plugin_api.h;请安装 vde-plugin-sdk 或用 -DVDE_SDK_DIR=<源码根/安装前缀> 指定")
endif()
endif()
add_library(vde_template_format SHARED format_plugin.cpp)
if(TARGET vde::plugin-sdk)
target_link_libraries(vde_template_format PRIVATE vde::plugin-sdk)
else()
target_include_directories(vde_template_format PRIVATE "${_vde_include}")
endif()
target_compile_definitions(vde_template_format PRIVATE VDE_PLUGIN_IMPL=1)
set_target_properties(vde_template_format PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugin"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/plugin"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/plugin"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/plugin"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/plugin"
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/plugin"
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/plugin"
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/plugin"
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/plugin")
if(WIN32)
set_target_properties(vde_template_format PROPERTIES PREFIX "")
endif()
if(MSVC)
target_compile_options(vde_template_format PRIVATE /utf-8)
endif()
add_custom_command(TARGET vde_template_format POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/vde-plugin.json"
"${CMAKE_BINARY_DIR}/plugin/vde-plugin.json")
message(STATUS "template plugin output: ${CMAKE_BINARY_DIR}/plugin")