qt-tracing/ui/impl.cmake
numzero e40a729048 replace custom FFI with Diplomat
adapted from: qt-wgpu-skel:
* 751408ea92268a16a6931862cb00e8dbccb4e47e replace custom FFI with Diplomat
* 46ce52c2bf2f8ab76a68c284a2f70556a29d7c3b reduce the unsafe part to the GPU initialization
* 784e99b31c4ae3ab0f97ec26045511d00683d66b move the GPU initialization out of the bridge
2026-10-27 19:43:26 +03:00

59 lines
1.5 KiB
CMake

# build the Rust side as a static library
set(impl_basename "${CARGO_TARGET_DIR}/release/libphoton_light")
set(cargo_cmake_args)
set(diplomat_cmake_args)
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.27")
list(APPEND cargo_cmake_args DEPENDS_EXPLICIT_ONLY)
list(APPEND diplomat_cmake_args DEPENDS_EXPLICIT_ONLY)
endif()
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.28")
list(APPEND cargo_cmake_args JOB_SERVER_AWARE TRUE)
endif()
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.31")
list(APPEND diplomat_cmake_args CODEGEN)
endif()
add_custom_command(
OUTPUT "${impl_basename}.a"
COMMAND env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" ${CARGO} build --release --package photon-light
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPFILE "${impl_basename}.d"
USES_TERMINAL
VERBATIM
${cargo_cmake_args}
)
# HACK ensure CMake *actually adds* the command above
add_custom_target(build_impl
DEPENDS "${impl_basename}.a"
)
add_library(photon_light_impl STATIC IMPORTED)
set_target_properties(photon_light_impl PROPERTIES
IMPORTED_LOCATION "${impl_basename}.a"
)
# generate the bindings
set(bindings_dir "${CMAKE_CURRENT_BINARY_DIR}/include")
file(MAKE_DIRECTORY "${bindings_dir}")
set(bindings
"${bindings_dir}/Core.hpp"
)
add_custom_command(
OUTPUT ${bindings}
COMMAND ${diplomat} cpp "${bindings_dir}"
MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/src/lib.rs"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VERBATIM
${diplomat_cmake_args}
)
target_sources(photon_light_impl INTERFACE ${bindings})
target_include_directories(photon_light_impl INTERFACE "${bindings_dir}")