Skip to content

Commit 2bd0a52

Browse files
Added cmake installer for posix runtime
1 parent b44ffd6 commit 2bd0a52

5 files changed

Lines changed: 178 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ Examples/build/build.sh
4848
Examples/build/
4949
output/
5050
.codex_tmp/
51+
build/

Examples/hello_posix/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
99
get_filename_component(CMSIS_STREAM_ROOT "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
1010

1111
if(NOT TARGET posix_runtime)
12+
set(POSIX_RUNTIME_CONFIG_DIR "${CMAKE_CURRENT_LIST_DIR}/config" CACHE PATH "" FORCE)
1213
add_subdirectory("${CMSIS_STREAM_ROOT}/platform/posix_runtime" "${CMAKE_CURRENT_BINARY_DIR}/posix_runtime")
1314
endif()
1415

15-
target_include_directories(posix_runtime PRIVATE
16-
"${CMAKE_CURRENT_LIST_DIR}/config"
17-
)
18-
1916
add_executable(hello_posix
2017
main.cpp
2118
config/stream_init.cpp
Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,113 @@
11
cmake_minimum_required(VERSION 3.20)
22

3+
project(CMSISStreamPosixRuntime VERSION 0.0.0 LANGUAGES CXX)
4+
5+
include(GNUInstallDirs)
6+
include(CMakePackageConfigHelpers)
7+
8+
set(POSIX_RUNTIME_CONFIG_DIR "" CACHE PATH
9+
"Directory containing the client application's copied POSIX runtime configuration"
10+
)
11+
12+
if(POSIX_RUNTIME_CONFIG_DIR)
13+
set(POSIX_RUNTIME_BUILD_CONFIG_DIR ${POSIX_RUNTIME_CONFIG_DIR})
14+
else()
15+
set(POSIX_RUNTIME_BUILD_CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated_config)
16+
file(MAKE_DIRECTORY ${POSIX_RUNTIME_BUILD_CONFIG_DIR})
17+
file(WRITE ${POSIX_RUNTIME_BUILD_CONFIG_DIR}/stream_runtime_config.hpp
18+
"#pragma once\n"
19+
)
20+
endif()
321

422
add_library(posix_runtime STATIC
523
stream_event_queue.cpp
624
stream_runtime_init.cpp
725
)
826

27+
add_library(cmsis_stream::posix_runtime ALIAS posix_runtime)
28+
29+
set_target_properties(posix_runtime PROPERTIES
30+
OUTPUT_NAME cmsis_stream_runtime
31+
)
32+
933
target_include_directories(posix_runtime PUBLIC
10-
${CMAKE_CURRENT_SOURCE_DIR}
11-
${CMAKE_CURRENT_SOURCE_DIR}/..
34+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
35+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
36+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/CMSIS-Stream/platform/posix_runtime>
37+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/CMSIS-Stream/platform>
38+
)
39+
40+
target_include_directories(posix_runtime PRIVATE
41+
$<BUILD_INTERFACE:${POSIX_RUNTIME_BUILD_CONFIG_DIR}>
1242
)
1343

1444
target_compile_features(posix_runtime PUBLIC cxx_std_17)
1545

1646
if(UNIX AND NOT APPLE)
17-
target_link_libraries(posix_runtime PUBLIC pthread)
47+
find_package(Threads REQUIRED)
48+
target_link_libraries(posix_runtime PUBLIC Threads::Threads)
1849
endif()
50+
51+
set(POSIX_RUNTIME_CMAKE_INSTALL_DIR
52+
${CMAKE_INSTALL_LIBDIR}/cmake/cmsis-stream
53+
)
54+
55+
install(TARGETS posix_runtime
56+
EXPORT posix_runtimeTargets
57+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
58+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
59+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
60+
)
61+
62+
install(FILES
63+
stream_event_queue.hpp
64+
stream_platform_config.hpp
65+
stream_rtos_events.h
66+
stream_runtime_init.hpp
67+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CMSIS-Stream/platform/posix_runtime
68+
)
69+
70+
install(FILES
71+
${CMAKE_CURRENT_SOURCE_DIR}/../cg_enums.h
72+
${CMAKE_CURRENT_SOURCE_DIR}/../cg_pack.hpp
73+
${CMAKE_CURRENT_SOURCE_DIR}/../EventDisplay.hpp
74+
${CMAKE_CURRENT_SOURCE_DIR}/../EventQueue.hpp
75+
${CMAKE_CURRENT_SOURCE_DIR}/../GenericNodes.hpp
76+
${CMAKE_CURRENT_SOURCE_DIR}/../StreamNode.hpp
77+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CMSIS-Stream/platform
78+
)
79+
80+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../core_nodes
81+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CMSIS-Stream/platform
82+
FILES_MATCHING
83+
PATTERN "*.hpp"
84+
PATTERN "*.h"
85+
)
86+
87+
install(DIRECTORY config/
88+
DESTINATION ${CMAKE_INSTALL_DATADIR}/CMSIS-Stream/posix_runtime/config
89+
)
90+
91+
install(EXPORT posix_runtimeTargets
92+
FILE posix_runtimeTargets.cmake
93+
NAMESPACE cmsis_stream::
94+
DESTINATION ${POSIX_RUNTIME_CMAKE_INSTALL_DIR}
95+
)
96+
97+
configure_package_config_file(
98+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmsis-streamConfig.cmake.in
99+
${CMAKE_CURRENT_BINARY_DIR}/cmsis-streamConfig.cmake
100+
INSTALL_DESTINATION ${POSIX_RUNTIME_CMAKE_INSTALL_DIR}
101+
)
102+
103+
write_basic_package_version_file(
104+
${CMAKE_CURRENT_BINARY_DIR}/cmsis-streamConfigVersion.cmake
105+
VERSION ${PROJECT_VERSION}
106+
COMPATIBILITY AnyNewerVersion
107+
)
108+
109+
install(FILES
110+
${CMAKE_CURRENT_BINARY_DIR}/cmsis-streamConfig.cmake
111+
${CMAKE_CURRENT_BINARY_DIR}/cmsis-streamConfigVersion.cmake
112+
DESTINATION ${POSIX_RUNTIME_CMAKE_INSTALL_DIR}
113+
)

platform/posix_runtime/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,66 @@ for managing events.
1919

2020
The part related to inter process communication and buffer sharing
2121
without copy is not implemented in this runtime.
22+
23+
## CMake usage
24+
25+
When the runtime is used from source with `add_subdirectory`, point
26+
`POSIX_RUNTIME_CONFIG_DIR` to the client application's copied config folder
27+
before adding the runtime:
28+
29+
```cmake
30+
set(POSIX_RUNTIME_CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/config" CACHE PATH "" FORCE)
31+
add_subdirectory(path/to/CMSIS-Stream/platform/posix_runtime)
32+
33+
target_link_libraries(my_app PRIVATE cmsis_stream::posix_runtime)
34+
```
35+
36+
To install the runtime as a CMake package:
37+
38+
```sh
39+
cmake -S platform/posix_runtime -B build/posix_runtime -DCMAKE_INSTALL_PREFIX=/path/to/install
40+
cmake --build build/posix_runtime --config Release
41+
cmake --install build/posix_runtime --config Release
42+
```
43+
44+
CMake installs the package configuration file under:
45+
46+
```text
47+
<install-prefix>/lib/cmake/cmsis-stream/cmsis-streamConfig.cmake
48+
```
49+
50+
`find_package(cmsis-stream CONFIG REQUIRED)` searches known install prefixes for
51+
that file. On Linux, packages installed to common prefixes such as `/usr` or
52+
`/usr/local` are often found automatically. For a custom prefix, pass the install
53+
prefix when configuring the client application:
54+
55+
```sh
56+
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/install
57+
```
58+
59+
On Windows, custom install prefixes usually need to be provided explicitly:
60+
61+
```powershell
62+
cmake -S . -B build -DCMAKE_PREFIX_PATH=C:\path\to\install
63+
```
64+
65+
Alternatively, point directly to the package directory:
66+
67+
```powershell
68+
cmake -S . -B build -Dcmsis-stream_DIR=C:\path\to\install\lib\cmake\cmsis-stream
69+
```
70+
71+
Then a client project can use:
72+
73+
```cmake
74+
find_package(cmsis-stream CONFIG REQUIRED)
75+
76+
add_executable(my_app main.cpp config/stream_init.cpp generated/scheduler.cpp)
77+
target_include_directories(my_app PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/config")
78+
target_link_libraries(my_app PRIVATE cmsis_stream::posix_runtime)
79+
```
80+
81+
The package also defines `CMSIS_STREAM_POSIX_RUNTIME_CONFIG_TEMPLATE_DIR`,
82+
which points to the installed runtime config templates. Copy those files into
83+
the client application and customize the copy; do not include the installed
84+
template directory directly in the build.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@PACKAGE_INIT@
2+
3+
include(CMakeFindDependencyMacro)
4+
5+
if(UNIX AND NOT APPLE)
6+
find_dependency(Threads)
7+
endif()
8+
9+
include("${CMAKE_CURRENT_LIST_DIR}/posix_runtimeTargets.cmake")
10+
11+
set(CMSIS_STREAM_POSIX_RUNTIME_CONFIG_TEMPLATE_DIR
12+
"${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_DATADIR@/CMSIS-Stream/posix_runtime/config"
13+
)
14+
15+
check_required_components(cmsis-stream)

0 commit comments

Comments
 (0)