From 3abba6bcbf044a6a5611260a8d7bf84b9c96bcb7 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 May 2024 21:19:08 +0200 Subject: [PATCH] [#210] Initial cmake integration with example --- CMakeLists.txt | 12 +++++++++ examples/c/CMakeLists.txt | 4 +++ examples/c/discovery/CMakeLists.txt | 8 ++++++ examples/c/discovery/src/main.c | 6 +++++ iceoryx2-lang/CMakeLists.txt | 8 ++++++ iceoryx2-lang/c/CMakeLists.txt | 25 +++++++++++++++++++ iceoryx2-lang/c/cmake/Config.cmake.in | 5 ++++ .../c/cmake/iceoryx2_lang_cConfig.cmake | 7 ++++++ 8 files changed, 75 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 examples/c/CMakeLists.txt create mode 100644 examples/c/discovery/CMakeLists.txt create mode 100644 examples/c/discovery/src/main.c create mode 100644 iceoryx2-lang/CMakeLists.txt create mode 100644 iceoryx2-lang/c/CMakeLists.txt create mode 100644 iceoryx2-lang/c/cmake/Config.cmake.in create mode 100644 iceoryx2-lang/c/cmake/iceoryx2_lang_cConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..9ab2c7dcc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.28) +project(iceoryx2) + +#TODO build iceoryx2 +#TODO how to handle feature flags + +add_subdirectory(iceoryx2-lang) + +#TODO add flags +# if(EXAMPLES) + add_subdirectory(examples/c) +# endif() diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt new file mode 100644 index 000000000..c14a65d80 --- /dev/null +++ b/examples/c/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.28) +project(examples_c) + +add_subdirectory(discovery) diff --git a/examples/c/discovery/CMakeLists.txt b/examples/c/discovery/CMakeLists.txt new file mode 100644 index 000000000..966315258 --- /dev/null +++ b/examples/c/discovery/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.28) +project(example_c_discovery) + +find_package(iceoryx2_lang_c REQUIRED) + +add_executable(example_c_discovery src/main.c) + +target_link_libraries(example_c_discovery iceoryx2_lang_c) diff --git a/examples/c/discovery/src/main.c b/examples/c/discovery/src/main.c new file mode 100644 index 000000000..89a286ecf --- /dev/null +++ b/examples/c/discovery/src/main.c @@ -0,0 +1,6 @@ + +#include "iox2/iceoryx2.h" + +int main(void) { + zero_copy_service_list(); +} diff --git a/iceoryx2-lang/CMakeLists.txt b/iceoryx2-lang/CMakeLists.txt new file mode 100644 index 000000000..2f1342047 --- /dev/null +++ b/iceoryx2-lang/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.28) +project(iceoryx2-lang) + +add_subdirectory(c) + +if(BUILD_TESTING) + add_subdirectory(tests/tbd) +endif() diff --git a/iceoryx2-lang/c/CMakeLists.txt b/iceoryx2-lang/c/CMakeLists.txt new file mode 100644 index 000000000..953457eec --- /dev/null +++ b/iceoryx2-lang/c/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.28) +project(iceoryx2_lang_c) + +# 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") + +find_library(ICEORYX2_LANG_C_LIB ${PROJECT_NAME} HINTS ${iceoryx2_SOURCE_DIR}/target/release) + +add_library(${PROJECT_NAME} INTERFACE) + +target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_BINARY_DIR}/generated/include) + +target_link_libraries(${PROJECT_NAME} INTERFACE ${ICEORYX2_LANG_C_LIB}) + +########## find_package in source tree ########## +set(${PROJECT_NAME}_DIR ${PROJECT_SOURCE_DIR}/cmake + CACHE FILEPATH + "${PROJECT_NAME}Config.cmake to make find_package(${PROJECT_NAME}) work in source tree!" + FORCE +) diff --git a/iceoryx2-lang/c/cmake/Config.cmake.in b/iceoryx2-lang/c/cmake/Config.cmake.in new file mode 100644 index 000000000..5bcba53b0 --- /dev/null +++ b/iceoryx2-lang/c/cmake/Config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +# TODO check if this is correct +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/iceoryx2-lang/c/cmake/iceoryx2_lang_cConfig.cmake b/iceoryx2-lang/c/cmake/iceoryx2_lang_cConfig.cmake new file mode 100644 index 000000000..aa9b384eb --- /dev/null +++ b/iceoryx2-lang/c/cmake/iceoryx2_lang_cConfig.cmake @@ -0,0 +1,7 @@ +if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FOUND_PRINTED) + message(STATUS "The package '${CMAKE_FIND_PACKAGE_NAME}' is used in source code version.") + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND_PRINTED true CACHE INTERNAL "") +endif() + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) +