From 442a5e9d262275504280229857aeb08d6547b228 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 1 Jun 2024 16:35:51 +0200 Subject: [PATCH] [#210] Generate the cbindgen header into the target directory --- iceoryx2-lang/c/CMakeLists.txt | 10 ++++------ iceoryx2-lang/c/build.rs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/iceoryx2-lang/c/CMakeLists.txt b/iceoryx2-lang/c/CMakeLists.txt index 2697b8f3..8d5d5b74 100644 --- a/iceoryx2-lang/c/CMakeLists.txt +++ b/iceoryx2-lang/c/CMakeLists.txt @@ -26,24 +26,22 @@ set(RUST_ARCH_TRIPLET_FLAG "") set(RUST_TARGET_DIR ${CMAKE_BINARY_DIR}/rust) set(RUST_ARCH_TARGET_DIR ${RUST_TARGET_DIR}/${RUST_ARCH_TRIPLET}) +# TODO switch for Windows set(ICEORYX2_LANG_C_LIB ${RUST_ARCH_TARGET_DIR}/${RUST_BUILD_TYPE}/libiceoryx2_lang_c.a) +set(ICEORYX2_LANG_C_INCLUDE_DIR ${RUST_ARCH_TARGET_DIR}/${RUST_BUILD_TYPE}/iceoryx2_lang_c_cbindgen/include) # run cargo add_custom_target( iceoryx2 ALL COMMAND cargo build ${RUST_BUILD_TYPE_FLAG} --target-dir=${RUST_TARGET_DIR} ${RUST_ARCH_TRIPLET_FLAG} BYPRODUCTS - "${CMAKE_CURRENT_SOURCE_DIR}/iceoryx2.h" + ${ICEORYX2_LANG_C_INCLUDE_DIR}/iox2/iceoryx2.h ${ICEORYX2_LANG_C_LIB} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} VERBATIM USES_TERMINAL ) -# TODO remove once generation works as expected ... have a look at iceoryx-rs -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iceoryx2.h" - "${CMAKE_BINARY_DIR}/generated/include/iox2/iceoryx2.h" @ONLY) - # set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") # list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so") # list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll") @@ -56,7 +54,7 @@ add_library(${PROJECT_NAME} INTERFACE) add_dependencies(${PROJECT_NAME} iceoryx2) -target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_BINARY_DIR}/generated/include) +target_include_directories(${PROJECT_NAME} INTERFACE ${ICEORYX2_LANG_C_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} INTERFACE ${ICEORYX2_LANG_C_LIB}) diff --git a/iceoryx2-lang/c/build.rs b/iceoryx2-lang/c/build.rs index b8f6634b..9620a0e8 100644 --- a/iceoryx2-lang/c/build.rs +++ b/iceoryx2-lang/c/build.rs @@ -1,11 +1,19 @@ extern crate cbindgen; use std::env; +use std::path::Path; use cbindgen::Config; fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + // this is the out dir of the iceoryx2-lang C crate not the workspace out dir, + // therefore we need to traverse to a known location and create the path for the header + let out_dir = env::var("OUT_DIR").expect("Target output directory"); + + let mut header_path = Path::new(&out_dir).join("../../../").canonicalize().expect("Path to iceoryx2 base dir for header generation"); + header_path.push("iceoryx2_lang_c_cbindgen/include/iox2/iceoryx2.h"); + + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("Cargo manifest dir"); let mut config = Config::default(); config.language = cbindgen::Language::C; @@ -15,5 +23,5 @@ fn main() { .with_config(config) .generate() .expect("Unable to generate c bindings") - .write_to_file("iceoryx2.h"); + .write_to_file(header_path); }