Files
dora-zed/DoraTargets.cmake
T
cristhian b4144dfba5 match the cargo profile to CMAKE_BUILD_TYPE
The dora bindings were always built with the debug profile and linked
from target/debug, so a release build still pulled in unoptimized arrow,
zenoh and opentelemetry code -- a 640 MB dora_zed against 48 MB once the
profile follows the build type.
2026-09-07 14:33:50 -03:00

122 lines
4.6 KiB
CMake

set(DORA_ROOT_DIR "" CACHE FILEPATH "Path to the root of dora")
set(dora_c_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/c")
set(dora_cxx_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/cxx")
set(node_bridge "${CMAKE_CURRENT_BINARY_DIR}/node_bridge.cc")
# Match the cargo profile to the CMake build type, so a release build does not
# link unoptimized dora bindings.
if(CMAKE_BUILD_TYPE MATCHES "^(Release|RelWithDebInfo|MinSizeRel)$")
set(_cargo_profile_flag --release)
set(_cargo_target_subdir release)
else()
set(_cargo_profile_flag "")
set(_cargo_target_subdir debug)
endif()
if(DORA_ROOT_DIR AND EXISTS "${DORA_ROOT_DIR}/Cargo.toml")
include(ExternalProject)
ExternalProject_Add(Dora
SOURCE_DIR ${DORA_ROOT_DIR}
BUILD_IN_SOURCE True
CONFIGURE_COMMAND ""
BUILD_COMMAND
cargo build ${_cargo_profile_flag}
--package dora-node-api-c
&&
cargo build ${_cargo_profile_flag}
--package dora-node-api-cxx
INSTALL_COMMAND ""
)
add_custom_command(OUTPUT ${node_bridge} ${dora_cxx_include_dir} ${dora_c_include_dir}
WORKING_DIRECTORY ${DORA_ROOT_DIR}
DEPENDS Dora
COMMAND
mkdir ${dora_cxx_include_dir} -p
&&
mkdir ${CMAKE_CURRENT_BINARY_DIR}/include/c -p
&&
cp target/cxxbridge/dora-node-api-cxx/src/lib.rs.cc ${node_bridge}
&&
cp target/cxxbridge/dora-node-api-cxx/src/lib.rs.h ${dora_cxx_include_dir}/dora-node-api.h
&&
cp apis/c/node ${CMAKE_CURRENT_BINARY_DIR}/include/c -r
)
add_custom_target(Dora_c DEPENDS ${dora_c_include_dir})
add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_include_dir})
set(dora_link_dirs ${DORA_ROOT_DIR}/target/${_cargo_target_subdir})
else()
include(ExternalProject)
# This node targets dora 1.0+. Set DORA_GIT_TAG to pin a tag explicitly;
# left empty it follows the installed dora CLI so the bindings match the
# runtime, and falls back to the default below when no CLI is present.
set(DORA_GIT_TAG "" CACHE STRING "dora-rs git tag to build against (empty: follow the dora CLI)")
set(_dora_tag "${DORA_GIT_TAG}")
if(NOT _dora_tag)
set(_dora_tag "v1.0.1")
find_program(DORA_CLI dora)
if(DORA_CLI)
execute_process(
COMMAND ${DORA_CLI} --version
RESULT_VARIABLE _dora_version_result
OUTPUT_VARIABLE _dora_version_out
ERROR_VARIABLE _dora_version_err
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(_dora_version_result EQUAL 0)
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" _dora_version_match "${_dora_version_out}")
if(_dora_version_match)
set(_dora_tag "v${CMAKE_MATCH_1}")
if(CMAKE_MATCH_1 VERSION_LESS 1.0)
message(WARNING "dora CLI ${CMAKE_MATCH_1} is older than the 1.0 this node targets")
endif()
endif()
endif()
endif()
endif()
message(STATUS "dora-rs: building C++ bindings from ${_dora_tag}")
ExternalProject_Add(Dora
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dora
GIT_REPOSITORY https://github.com/dora-rs/dora.git
GIT_TAG ${_dora_tag}
BUILD_IN_SOURCE True
CONFIGURE_COMMAND ""
BUILD_COMMAND
cargo build ${_cargo_profile_flag}
--package dora-node-api-c
--target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
&&
cargo build ${_cargo_profile_flag}
--package dora-node-api-cxx
--target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
INSTALL_COMMAND ""
)
add_custom_command(OUTPUT ${node_bridge} ${dora_cxx_include_dir} ${dora_c_include_dir}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
DEPENDS Dora
COMMAND
mkdir ${CMAKE_CURRENT_BINARY_DIR}/include/c -p
&&
mkdir ${dora_cxx_include_dir} -p
&&
cp cxxbridge/dora-node-api-cxx/src/lib.rs.cc ${node_bridge}
&&
cp cxxbridge/dora-node-api-cxx/src/lib.rs.h ${dora_cxx_include_dir}/dora-node-api.h
&&
cp ../apis/c/node ${CMAKE_CURRENT_BINARY_DIR}/include/c -r
)
set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target/${_cargo_target_subdir})
add_custom_target(Dora_c DEPENDS ${dora_c_include_dir})
add_custom_target(Dora_cxx DEPENDS ${node_bridge} ${dora_cxx_include_dir})
endif()