Skip to content

Commit

Permalink
[eclipse-iceoryx#264] Create infrastructure for C++ bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Jul 2, 2024
1 parent a83c2ec commit ec98785
Show file tree
Hide file tree
Showing 27 changed files with 658 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ jobs:
-DBUILD_TESTING=ON \
-DRUST_TARGET_TRIPLET="i686-unknown-linux-gnu" \
-DCMAKE_C_FLAGS="-m32" \
-DCMAKE_CXX_FLAGS="-m32" \
${{ matrix.mode.cmake-build-type }}
cmake --build target/ffi/build
cmake --install target/ffi/build
Expand All @@ -163,6 +164,7 @@ jobs:
-B target/ffi/out-of-tree \
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/target/ffi/install \
-DCMAKE_C_FLAGS="-m32" \
-DCMAKE_CXX_FLAGS="-m32" \
-${{ matrix.mode.cmake-build-type }}
cmake --build target/ffi/out-of-tree
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ endmacro()

message(STATUS "iceoryx2 options:")

add_option(
NAME BUILD_CXX_BINDING
DESCRIPTION "Build C++ binding"
DEFAULT_VALUE ON
)

add_option(
NAME BUILD_EXAMPLES
DESCRIPTION "Build examples"
Expand All @@ -54,8 +60,18 @@ add_param(
DEFAULT_VALUE ""
)

# C binding
add_subdirectory(iceoryx2-ffi/c)

if(BUILD_EXAMPLES)
add_subdirectory(examples/c)
endif()

# C++ binding
if(BUILD_CXX_BINDING)
add_subdirectory(iceoryx2-ffi/cxx)

if(BUILD_EXAMPLES)
add_subdirectory(examples/cxx)
endif()
endif()
20 changes: 11 additions & 9 deletions examples/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Build

```console
cmake -B target/lang-c .
cmake --build target/lang-c
In the repository root folder, execute this steps.

```bash
cmake -S . -B target/ffi/build -DBUILD_EXAMPLES=ON
cmake --build target/ffi/build
```

## Run Examples
Expand All @@ -13,16 +15,16 @@ cmake --build target/lang-c

Run in two separate terminals. Note, currently the examples run for 10 seconds.

```console
target/lang-c/examples/c/publish_subscribe/example_c_publisher
```bash
target/ffi/build/examples/c/publish_subscribe/example_c_publisher
```

```console
target/lang-c/examples/c/publish_subscribe/example_c_subscriber
```bash
target/ffi/build/examples/c/publish_subscribe/example_c_subscriber
```

### Discovery

```console
target/lang-c/examples/c/discovery/example_c_discovery
```bash
target/ffi/build/examples/c/discovery/example_c_discovery
```
16 changes: 16 additions & 0 deletions examples/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

cmake_minimum_required(VERSION 3.22)
project(examples_cxx LANGUAGES CXX)

add_subdirectory(publish_subscribe)
33 changes: 33 additions & 0 deletions examples/cxx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Instructions

## Build

In the repository root folder, execute this steps.

```bash
cmake -S . -B target/ffi/build -DBUILD_EXAMPLES=ON
cmake --build target/ffi/build
```

## Run Examples

### Publish-Subscribe

Run in two separate terminals. Note, currently the examples run for 10 seconds.

<!-- TODO -->
```bash
target/ffi/build/examples/cxx/publish_subscribe/example_cxx_publisher
```

<!-- TODO -->
```bash
target/ffi/build/examples/cxx/publish_subscribe/example_cxx_subscriber
```

### Discovery

<!-- TODO -->
```bash
target/ffi/build/examples/cxx/discovery/example_cxx_discovery
```
22 changes: 22 additions & 0 deletions examples/cxx/publish_subscribe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

cmake_minimum_required(VERSION 3.22)
project(example_cxx_publish_subscribe LANGUAGES CXX)

find_package(iceoryx2-cxx REQUIRED)

add_executable(example_cxx_publisher src/publisher.cpp)
target_link_libraries(example_cxx_publisher iceoryx2-cxx::static-lib-cxx)

add_executable(example_cxx_subscriber src/subscriber.cpp)
target_link_libraries(example_cxx_subscriber iceoryx2-cxx::static-lib-cxx)
17 changes: 17 additions & 0 deletions examples/cxx/publish_subscribe/src/publisher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include "iox2/node.hpp"

int main() {
return 0;
}
17 changes: 17 additions & 0 deletions examples/cxx/publish_subscribe/src/subscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include "iox2/node.hpp"

int main() {
return 0;
}
2 changes: 2 additions & 0 deletions iceoryx2-ffi/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ target_include_directories(includes-only
add_library(static-lib INTERFACE)
add_library(iceoryx2-c::static-lib ALIAS static-lib)

# shared lib

add_library(shared-lib INTERFACE)
add_library(iceoryx2-c::shared-lib ALIAS shared-lib)

Expand Down
12 changes: 5 additions & 7 deletions iceoryx2-ffi/c/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
## Build instructions

```console
cmake -B target/lang-c
cmake --build target/lang-c
```

# Helpful iceoryx dev crates
In the repository root folder, execute this steps.

- https://github.com/corrosion-rs/corrosion
```bash
cmake -S . -B target/ffi/build
cmake --build target/ffi/build
```
1 change: 0 additions & 1 deletion iceoryx2-ffi/c/cmake/iceoryx2-cConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FOUND_PRINTED)
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

2 changes: 1 addition & 1 deletion iceoryx2-ffi/c/cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

# NOTE the file is included in '../CMakeLists.txt' and therefore all relative paths must be relative to '../'
# NOTE the file is included in '../CMakeLists.txt' and therefore all paths based on 'CMAKE_CURRENT_SOURCE_DIR' must be relative to '../'

#
########## set variables for export ##########
Expand Down
23 changes: 23 additions & 0 deletions iceoryx2-ffi/c/tests/src/test_c_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include "iox2/iceoryx2.h"

#include "test.hpp"

namespace {

TEST(Node, CreatingNodeWorks) {
ASSERT_THAT(true, Eq(true));
}

} // namespace
106 changes: 106 additions & 0 deletions iceoryx2-ffi/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

cmake_minimum_required(VERSION 3.22)

# TODO use this in fetch-iceoryx-hoofs.cmake
set(ICEORYX_HOOFS_VERSION 2.90.0)
include(cmake/fetch-iceoryx-hoofs.cmake)

project(iceoryx2-cxx VERSION ${IOX2_VERSION_STRING} LANGUAGES CXX)

set(PREFIX iceoryx2/v${CMAKE_PROJECT_VERSION})

find_package(iceoryx_hoofs REQUIRED)
find_package(iceoryx2-c REQUIRED)

# include only lib -> includes are installed only once despite being used in static lib as well as shared lib

add_library(includes-only-cxx INTERFACE)
add_library(iceoryx2-cxx::includes-only-cxx ALIAS includes-only-cxx)

target_include_directories(includes-only-cxx
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PREFIX}>
)

# object lib

add_library(iceoryx2-cxx-object-lib OBJECT
src/dummy.cpp
)

set_target_properties(iceoryx2-cxx-object-lib
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
)

target_link_libraries(iceoryx2-cxx-object-lib
PUBLIC
iceoryx_hoofs::iceoryx_hoofs
iceoryx2-c::includes-only
iceoryx2-cxx::includes-only-cxx
)

# static lib

add_library(static-lib-cxx STATIC $<TARGET_OBJECTS:iceoryx2-cxx-object-lib>)
add_library(iceoryx2-cxx::static-lib-cxx ALIAS static-lib-cxx)

set_target_properties(static-lib-cxx
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME "iceoryx2_cxx"
)

target_link_libraries(static-lib-cxx
PUBLIC
iceoryx_hoofs::iceoryx_hoofs
iceoryx2-c::shared-lib
iceoryx2-cxx::includes-only-cxx
)

# shared lib

add_library(shared-lib-cxx SHARED $<TARGET_OBJECTS:iceoryx2-cxx-object-lib>)
add_library(iceoryx2-cxx::shared-lib-cxx ALIAS shared-lib-cxx)

set_target_properties(shared-lib-cxx
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME "iceoryx2_cxx"
)

target_link_libraries(shared-lib-cxx
PUBLIC
iceoryx_hoofs::iceoryx_hoofs
iceoryx2-c::shared-lib
iceoryx2-cxx::includes-only-cxx
)

# include install setup

include(cmake/install.cmake)

# add tests

if(${BUILD_TESTING})
add_subdirectory(tests)
endif()

Loading

0 comments on commit ec98785

Please sign in to comment.