Skip to content

Commit

Permalink
[eclipse-iceoryx#210] Initial cmake integration with example
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Jun 1, 2024
1 parent 4fc24f8 commit 468b4e4
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/lang_c)
# endif()
4 changes: 4 additions & 0 deletions examples/lang_c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.28)
project(examples_lang_c)

add_subdirectory(discovery)
8 changes: 8 additions & 0 deletions examples/lang_c/discovery/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.28)
project(example_lang_c_discovery)

find_package(iceoryx2_lang_c REQUIRED)

add_executable(lang_c_discovery src/main.c)

target_link_libraries(lang_c_discovery iceoryx2_lang_c)
6 changes: 6 additions & 0 deletions examples/lang_c/discovery/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#include "iox2/iceoryx2.h"

int main(void) {
zero_copy_service_list();
}
8 changes: 8 additions & 0 deletions iceoryx2-lang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.28)
project(iceoryx2-lang)

add_subdirectory(c)

if(BUILD_TESTING)
add_subdirectory(tests/tbd)
endif()
25 changes: 25 additions & 0 deletions iceoryx2-lang/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
5 changes: 5 additions & 0 deletions iceoryx2-lang/c/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

# TODO check if this is correct
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
7 changes: 7 additions & 0 deletions iceoryx2-lang/c/cmake/iceoryx2_lang_cConfig.cmake
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 468b4e4

Please sign in to comment.