Now that there is no separate UI-specific wrapper, it belongs to the implementation rather than to the UI, probably
64 lines
1.6 KiB
CMake
64 lines
1.6 KiB
CMake
# build the Rust side as a static library
|
|
set(impl_basename "${CARGO_TARGET_DIR}/release/libPROJECT_NAME")
|
|
|
|
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 PROJECT-NAME
|
|
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(PROJECT_NAME_impl STATIC IMPORTED GLOBAL)
|
|
|
|
set_target_properties(PROJECT_NAME_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 "lib.rs"
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
VERBATIM
|
|
${diplomat_cmake_args}
|
|
)
|
|
|
|
# HACK ensure CMake *actually adds* the command above
|
|
add_custom_target(codegen_impl
|
|
DEPENDS ${bindings}
|
|
)
|
|
|
|
target_sources(PROJECT_NAME_impl INTERFACE ${bindings})
|
|
target_include_directories(PROJECT_NAME_impl INTERFACE "${bindings_dir}")
|