cmake_minimum_required(VERSION 3.21)
project(___name___ LANGUAGES C)
set(DORA_ROOT_DIR "__DORA_PATH__" CACHE FILEPATH "Path to the root of dora")
set(dora_c_include_dir "${CMAKE_CURRENT_BINARY_DIR}/include/c")
# Map CMake's CMAKE_BUILD_TYPE to Cargo's profile so a Release build
# links against target/release/ and a Debug build (or no build type
# specified) links against target/debug/. Without this the template
# would hardcode target/debug regardless of the user's build config.
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR NOT CMAKE_BUILD_TYPE)
set(dora_cargo_profile_dir "debug")
set(dora_cargo_release_arg "")
else()
set(dora_cargo_profile_dir "release")
set(dora_cargo_release_arg "--release")
endif()
if(DORA_ROOT_DIR)
include(ExternalProject)
ExternalProject_Add(Dora
SOURCE_DIR ${DORA_ROOT_DIR}
BUILD_IN_SOURCE True
CONFIGURE_COMMAND ""
BUILD_COMMAND
cargo build
${dora_cargo_release_arg}
--package dora-node-api-c
INSTALL_COMMAND ""
)
add_custom_command(OUTPUT ${dora_c_include_dir}
WORKING_DIRECTORY ${DORA_ROOT_DIR}
DEPENDS Dora
COMMAND ${CMAKE_COMMAND} -E make_directory ${dora_c_include_dir}
COMMAND ${CMAKE_COMMAND} -E copy_directory apis/c/node ${dora_c_include_dir}/node
)
add_custom_target(Dora_c DEPENDS ${dora_c_include_dir})
set(dora_link_dirs ${DORA_ROOT_DIR}/target/${dora_cargo_profile_dir})
else()
include(ExternalProject)
ExternalProject_Add(Dora
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dora
GIT_REPOSITORY https://github.com/dora-rs/dora.git
GIT_TAG main
BUILD_IN_SOURCE True
CONFIGURE_COMMAND ""
BUILD_COMMAND
cargo build
${dora_cargo_release_arg}
--package dora-node-api-c
--target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
INSTALL_COMMAND ""
)
add_custom_command(OUTPUT ${dora_c_include_dir}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
DEPENDS Dora
COMMAND ${CMAKE_COMMAND} -E make_directory ${dora_c_include_dir}
COMMAND ${CMAKE_COMMAND} -E copy_directory ../apis/c/node ${dora_c_include_dir}/node
)
set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target/${dora_cargo_profile_dir})
add_custom_target(Dora_c DEPENDS ${dora_c_include_dir})
endif()
link_directories(${dora_link_dirs})
add_executable(___name___ node.c)
add_dependencies(___name___ Dora_c)
target_include_directories(___name___ PRIVATE ${dora_c_include_dir})
if(WIN32)
target_link_libraries(___name___ dora_node_api_c ws2_32 userenv ntdll bcrypt)
elseif(APPLE)
# CoreFoundation: chrono time-zone APIs (CFRelease, CFTimeZoneCopySystem).
# Security + SystemConfiguration: pulled by transitive Rust deps that
# touch TLS and network config. Without these the link fails on macOS
# with missing _CF* and _Sec* symbols.
target_link_libraries(___name___
dora_node_api_c
m
z
"-framework CoreFoundation"
"-framework Security"
"-framework SystemConfiguration"
)
else()
target_link_libraries(___name___ dora_node_api_c m z)
endif()
install(TARGETS ___name___ DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin)