From fff178a94677314514ed3ea70d5d00bfe3ffb6da Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 13 May 2024 10:07:36 +0200 Subject: [PATCH] [#210] Make cmake build the Rust project --- CMakeLists.txt | 1 - iceoryx2-lang/c/CMakeLists.txt | 51 +++++++++++++++++++++++++++++++--- iceoryx2-lang/c/README.md | 12 ++++++-- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ab2c7dcc..34c3c20bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.28) project(iceoryx2) -#TODO build iceoryx2 #TODO how to handle feature flags add_subdirectory(iceoryx2-lang) diff --git a/iceoryx2-lang/c/CMakeLists.txt b/iceoryx2-lang/c/CMakeLists.txt index 953457eec..2697b8f39 100644 --- a/iceoryx2-lang/c/CMakeLists.txt +++ b/iceoryx2-lang/c/CMakeLists.txt @@ -1,18 +1,61 @@ cmake_minimum_required(VERSION 3.28) project(iceoryx2_lang_c) +########## Rust target ########## + +set(RUST_BUILD_TYPE "release") +set(RUST_BUILD_TYPE_FLAG "--${RUST_BUILD_TYPE}") +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(RUST_BUILD_TYPE "debug") + set(RUST_BUILD_TYPE_FLAG "") +endif() + +set(RUST_ARCH_TRIPLET "") +set(RUST_ARCH_TRIPLET_FLAG "") +# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i486") +# set(RUST_ARCH_TRIPLET "i686-unknown-linux-gnu") +# set(RUST_ARCH_TRIPLET_FLAG "--target=${RUST_ARCH_TRIPLET}") +# elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") +# set(RUST_ARCH_TRIPLET "armv7-unknown-linux-gnueabihf") +# set(RUST_ARCH_TRIPLET_FLAG "--target=${RUST_ARCH_TRIPLET}") +# elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") +# set(RUST_ARCH_TRIPLET "${CMAKE_SYSTEM_PROCESSOR}-unknown-linux-gnu") +# set(RUST_ARCH_TRIPLET_FLAG "--target=${RUST_ARCH_TRIPLET}") +# endif() + +set(RUST_TARGET_DIR ${CMAKE_BINARY_DIR}/rust) +set(RUST_ARCH_TARGET_DIR ${RUST_TARGET_DIR}/${RUST_ARCH_TRIPLET}) + +set(ICEORYX2_LANG_C_LIB ${RUST_ARCH_TARGET_DIR}/${RUST_BUILD_TYPE}/libiceoryx2_lang_c.a) + +# 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_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") +# set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +# list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so") +# list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll") +# +# find_library(ICEORYX2_LANG_C_LIB ${PROJECT_NAME} HINTS ${iceoryx2_SOURCE_DIR}/target/release) -find_library(ICEORYX2_LANG_C_LIB ${PROJECT_NAME} HINTS ${iceoryx2_SOURCE_DIR}/target/release) +########## C target ########## add_library(${PROJECT_NAME} INTERFACE) +add_dependencies(${PROJECT_NAME} iceoryx2) + target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_BINARY_DIR}/generated/include) target_link_libraries(${PROJECT_NAME} INTERFACE ${ICEORYX2_LANG_C_LIB}) diff --git a/iceoryx2-lang/c/README.md b/iceoryx2-lang/c/README.md index 438dc7b9f..6b9d55fda 100644 --- a/iceoryx2-lang/c/README.md +++ b/iceoryx2-lang/c/README.md @@ -1,4 +1,10 @@ - * compile: `gcc example.c -Ltarget/debug -liceoryx2_lang_c` - * set library path: `set -gx LD_LIBRARY_PATH $HOME/Development/iceoryx2/target/debug/` +## Build instructions - * see: https://github.com/corrosion-rs/corrosion +```console +cmake -B target/lang-c +cmake --build target/lang-c +``` + +# Helpful iceoryx dev crates + +- https://github.com/corrosion-rs/corrosion