Skip to content

Commit 37e0809

Browse files
authored
Merge pull request COVESA#62 from nayakned/zephyr_support
Zephyr support
2 parents 6a6103b + 73edf54 commit 37e0809

25 files changed

+1199
-367
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
1515

1616
# [Optional] Uncomment this section to install additional packages.
1717
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18-
&& apt-get -y install --no-install-recommends meson libcmocka0 \
18+
&& apt-get -y install --no-install-recommends libcmocka0 \
1919
libcmocka-dev lcov gcovr gcc-aarch64-linux-gnu \
2020
libc6-dev-arm64-cross binutils-aarch64-linux-gnu

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Generated directories
2-
/build
2+
/build*
33
/bin
44
/lib
55
/release

CMakeLists.txt

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,31 @@
2828
#
2929

3030
cmake_minimum_required(VERSION 3.20)
31+
32+
# Check first if we are building for Zephyr and include its dependencies accordingly.
33+
if (DEFINED ENV{ZEPHYR_BASE})
34+
if (${OPEN1722_ZEPHYR_APP} STREQUAL "acf-can-bridge")
35+
set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/examples/acf-can/zephyr/Kconfig)
36+
endif()
37+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
38+
39+
zephyr_get_include_directories_for_lang_as_string( C includes)
40+
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
41+
zephyr_get_compile_definitions_for_lang_as_string( C definitions)
42+
zephyr_get_compile_options_for_lang_as_string( C options)
43+
44+
if(DEFINED CMAKE_C_COMPILER_TARGET)
45+
set(target_flag "--target=${CMAKE_C_COMPILER_TARGET}")
46+
endif()
47+
48+
set(external_project_cflags
49+
"${target_flag} ${includes} ${definitions} ${options} ${system_includes}"
50+
)
51+
endif()
52+
3153
project(open1722 VERSION 0.1.0 LANGUAGES C DESCRIPTION "Library implementing IEEE 1722")
54+
55+
# Set the compiler options and flags
3256
set(CMAKE_C_STANDARD 99)
3357
set(CMAKE_C_STANDARD_REQUIRED TRUE)
3458

@@ -39,56 +63,60 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
3963
add_compile_options(-Wfatal-errors)
4064
find_program(CCACHE_BIN ccache)
4165
if(CCACHE_BIN)
42-
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_BIN})
43-
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_BIN})
44-
message("Use ccache from ${CCACHE_BIN}")
66+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_BIN})
67+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_BIN})
68+
message("Use ccache from ${CCACHE_BIN}")
4569
endif()
4670

4771
add_subdirectory(src)
4872
add_custom_target(examples)
4973
add_subdirectory(examples EXCLUDE_FROM_ALL)
5074

51-
enable_testing()
52-
add_custom_target(unittests)
53-
add_subdirectory(unit EXCLUDE_FROM_ALL)
75+
# Build tests and install artefacts only for Linux systems
76+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
77+
enable_testing()
78+
add_custom_target(unittests)
79+
add_subdirectory(unit EXCLUDE_FROM_ALL)
80+
81+
install(DIRECTORY include/ DESTINATION include)
82+
install(TARGETS open1722 EXPORT Open1722Targets DESTINATION lib)
5483

55-
install(DIRECTORY include/ DESTINATION include)
56-
install(TARGETS open1722 EXPORT Open1722Targets DESTINATION lib)
84+
#### Export Configuration #####################################################
5785

58-
#### Export Configuration #####################################################
86+
install(EXPORT Open1722Targets FILE Open1722Targets.cmake DESTINATION lib/cmake/Open1722)
5987

60-
install(EXPORT Open1722Targets FILE Open1722Targets.cmake DESTINATION lib/cmake/Open1722)
88+
include(CMakePackageConfigHelpers)
6189

62-
include(CMakePackageConfigHelpers)
90+
configure_package_config_file(
91+
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
92+
"${CMAKE_CURRENT_BINARY_DIR}/Open1722Config.cmake"
93+
INSTALL_DESTINATION "lib/cmake/Open1722")
6394

64-
configure_package_config_file(
65-
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
66-
"${CMAKE_CURRENT_BINARY_DIR}/Open1722Config.cmake"
67-
INSTALL_DESTINATION "lib/cmake/Open1722")
95+
write_basic_package_version_file(
96+
${CMAKE_CURRENT_BINARY_DIR}/Open1722ConfigVersion.cmake
97+
VERSION "${open1722_VERSION_MAJOR}.${open1722_VERSION_MINOR}"
98+
COMPATIBILITY AnyNewerVersion)
6899

69-
write_basic_package_version_file(
70-
${CMAKE_CURRENT_BINARY_DIR}/Open1722ConfigVersion.cmake
71-
VERSION "${open1722_VERSION_MAJOR}.${open1722_VERSION_MINOR}"
72-
COMPATIBILITY AnyNewerVersion)
100+
install(FILES
101+
${CMAKE_CURRENT_BINARY_DIR}/Open1722Config.cmake
102+
${CMAKE_CURRENT_BINARY_DIR}/Open1722ConfigVersion.cmake
103+
DESTINATION lib/cmake/Open1722)
73104

74-
install(FILES
75-
${CMAKE_CURRENT_BINARY_DIR}/Open1722Config.cmake
76-
${CMAKE_CURRENT_BINARY_DIR}/Open1722ConfigVersion.cmake
77-
DESTINATION lib/cmake/Open1722)
105+
export(EXPORT Open1722Targets FILE ${CMAKE_CURRENT_BINARY_DIR}/Open1722Targets.cmake)
78106

79-
export(EXPORT Open1722Targets FILE ${CMAKE_CURRENT_BINARY_DIR}/Open1722Targets.cmake)
80107

81-
#### Packaging ################################################################
108+
#### Packaging ################################################################
82109

83-
include(InstallRequiredSystemLibraries)
84-
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
85-
set(CPACK_PACKAGE_VERSION_MAJOR "${open1722_VERSION_MAJOR}")
86-
set(CPACK_PACKAGE_VERSION_MINOR "${open1722_VERSION_MINOR}")
87-
set(CPACK_GENERATOR "TGZ" "DEB")
88-
set(CPACK_SOURCE_GENERATOR "TGZ" "DEB")
110+
include(InstallRequiredSystemLibraries)
111+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
112+
set(CPACK_PACKAGE_VERSION_MAJOR "${open1722_VERSION_MAJOR}")
113+
set(CPACK_PACKAGE_VERSION_MINOR "${open1722_VERSION_MINOR}")
114+
set(CPACK_GENERATOR "TGZ" "DEB")
115+
set(CPACK_SOURCE_GENERATOR "TGZ" "DEB")
89116

90-
# Debian package
91-
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
92-
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Adriaan Niess [Robert Bosch GmbH]")
117+
# Debian package
118+
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
119+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Adriaan Niess [Robert Bosch GmbH]")
93120

94-
include(CPack)
121+
include(CPack)
122+
endif()

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Open1722 is under BSD License. For more information see LICENSE file.
4545

4646
This repository is organized as follows:
4747
- The `src/` and `include/` folders contain the IEEE 1722 protocol implementation. We strive to make the implementation platform independant and avoid usage of platform specific headers or libraries. For now the implementation is tested only on Linux.
48-
- The `examples/` folder contains various applications that use our Open1722 library. The applications are targeted to Linux platforms.
48+
- The `examples/` folder contains various applications that use our Open1722 library. Most applications are targeted to Linux platforms. Few applications (e.g. [_acf-can-bridge_](./examples/acf-can/zephyr/)) are also ported for Zephyr RTOS. Compilation instructions for Zephyr is available in the corresponding folder of the application.
4949

5050
Before building Open1722 make sure you have installed the following software :
5151
* CMake >= 3.20
@@ -118,7 +118,7 @@ The `examples/` directory provides sample applications which demonstrate the Ope
118118

119119
To execute the IEEE 1722 CAN Talker application:
120120
```
121-
$ ./build/acf-can-talker
121+
$ ./build/examples/acf-can/linux/acf-can-talker
122122
```
123123

124124
### Programming Tutorial

examples/CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@
2727
# SPDX-License-Identifier: BSD-3-Clause
2828
#
2929

30+
3031
add_library(open1722examples STATIC "common/common.c")
3132
target_include_directories(open1722examples PRIVATE
32-
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
3333
$<INSTALL_INTERFACE:include>
3434
${CMAKE_CURRENT_SOURCE_DIR})
35-
35+
if (DEFINED ENV{ZEPHYR_BASE})
36+
target_link_libraries(open1722examples PRIVATE zephyr_interface)
37+
endif()
3638
add_dependencies(examples open1722examples)
3739

38-
add_subdirectory(aaf)
40+
# These examples can be also built for Zephyr
3941
add_subdirectory(acf-can)
40-
add_subdirectory(acf-vss)
41-
add_subdirectory(crf)
42-
add_subdirectory(cvf)
43-
add_subdirectory(hello-world)
42+
43+
# These examples are currently exclusively for Linux
44+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
45+
add_subdirectory(aaf)
46+
add_subdirectory(crf)
47+
add_subdirectory(cvf)
48+
add_subdirectory(hello-world)
49+
add_subdirectory(acf-vss)
50+
endif()
51+
52+

examples/acf-can/CMakeLists.txt

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,8 @@
2727
# SPDX-License-Identifier: BSD-3-Clause
2828
#
2929

30-
add_executable(acf-can-talker acf-can-talker.c acf-can-common.c)
31-
target_link_libraries(acf-can-talker open1722 open1722examples)
32-
target_include_directories(acf-can-talker PUBLIC ${CMAKE_SOURCE_DIR}/include ../)
33-
34-
add_executable(acf-can-listener acf-can-listener.c acf-can-common.c)
35-
target_link_libraries(acf-can-listener open1722 open1722examples)
36-
target_include_directories(acf-can-listener PUBLIC ${CMAKE_SOURCE_DIR}/include ../)
37-
38-
add_executable(acf-can-bridge acf-can-bridge.c acf-can-common.c)
39-
target_link_libraries(acf-can-bridge open1722 open1722examples)
40-
target_include_directories(acf-can-bridge PUBLIC ${CMAKE_SOURCE_DIR}/include ../)
41-
42-
add_dependencies(examples acf-can-talker acf-can-listener acf-can-bridge)
43-
44-
install(TARGETS
45-
acf-can-listener
46-
acf-can-talker
47-
acf-can-bridge
48-
RUNTIME DESTINATION bin)
30+
if (DEFINED ENV{ZEPHYR_BASE})
31+
add_subdirectory(zephyr)
32+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
33+
add_subdirectory(linux)
34+
endif()

0 commit comments

Comments
 (0)