1cmake_minimum_required(VERSION 3.19)
2cmake_policy(SET CMP0114 NEW)
3
4include(ExternalProject)
5
6message(STATUS "Including the VirtGPU/Virglrenderer API Remoting")
7
8# Download venus_hw.h from virglrenderer repository
9ExternalProject_Add(
10 venus_hw_header
11 URL https://gitlab.freedesktop.org/virgl/virglrenderer/-/raw/virglrenderer-1.2.0/src/venus_hw.h
12 DOWNLOAD_NO_EXTRACT YES
13 DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include
14 DOWNLOAD_NAME venus_hw.h
15 CONFIGURE_COMMAND ""
16 BUILD_COMMAND ""
17 INSTALL_COMMAND ""
18 LOG_DOWNLOAD ON
19)
20
21if (NOT GGML_VIRTGPU_BACKEND STREQUAL "ONLY")
22 message(STATUS "Enable the VirtGPU/Virglrenderer API Remoting frontend library")
23
24 find_package(PkgConfig REQUIRED)
25 pkg_check_modules(DRM REQUIRED libdrm)
26 if (NOT GGML_BACKEND_DL)
27 # cannot simply use USE_VIRTGPU, as in the 'else()' case the
28 # frontend isn't compiled
29 target_compile_definitions(ggml PUBLIC "GGML_USE_VIRTGPU_FRONTEND")
30 endif()
31
32 ggml_add_backend_library(ggml-virtgpu
33 ggml-backend-buffer.cpp
34 ggml-backend.cpp
35 ggml-backend-device.cpp
36 ggml-backend-reg.cpp
37 ggml-backend-buffer-type.cpp
38 virtgpu-apir.h
39 virtgpu-forward.gen.h
40 virtgpu.cpp
41 virtgpu-shm.cpp
42 virtgpu-utils.cpp
43 virtgpu-forward-device.cpp
44 virtgpu-forward-buffer-type.cpp
45 virtgpu-forward-buffer.cpp
46 virtgpu-forward-backend.cpp
47 virtgpu-forward-impl.h
48 apir_cs_ggml-rpc-front.cpp
49 ../../include/ggml-virtgpu.h)
50
51 target_include_directories(ggml-virtgpu PUBLIC /usr/include/libdrm/)
52
53 target_link_libraries(ggml-virtgpu PUBLIC ${DRM_LIBRARIES})
54 target_include_directories(ggml-virtgpu PUBLIC ${DRM_INCLUDE_DIRS})
55 target_compile_options(ggml-virtgpu PUBLIC ${DRM_CFLAGS_OTHER})
56
57 target_include_directories(ggml-virtgpu PUBLIC ./include)
58 target_include_directories(ggml-virtgpu PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
59
60 # Ensure venus_hw.h is downloaded before building ggml-virtgpu
61 add_dependencies(ggml-virtgpu venus_hw_header)
62
63 target_compile_options(ggml-virtgpu PRIVATE -std=c++20)
64else()
65 message(STATUS "Not building the VirtGPU/Virglrenderer API Remoting frontend library")
66endif()
67
68if (NOT GGML_VIRTGPU_BACKEND STREQUAL "OFF")
69 add_subdirectory("backend")
70endif()