@@ -30,7 +30,7 @@ in your repo and add the cib directory in your CMakeLists.txt file:
30
30
31
31
``` cmake
32
32
add_subdirectory(lib/compile-time-init-build)
33
- target_link_libraries(your_target PRIVATE Cib )
33
+ target_link_libraries(your_target PRIVATE cib )
34
34
```
35
35
36
36
With either of these methods, include the cib.hpp header in your code to use it.
@@ -40,101 +40,51 @@ With either of these methods, include the cib.hpp header in your code to use it.
40
40
Since * cib* is a library for efficiently building firmware through composition
41
41
a simple example takes a few more lines than a typical "Hello, world!"
42
42
43
- #### core.hpp
44
- The ` core ` component of this example ** exports** the ` say_message ` ** service** . Pay close
45
- attention to the ` #include ` directives in each file.
46
43
``` c++
47
44
#include < cib/cib.hpp>
45
+ #include < iostream>
48
46
49
47
struct say_message : public cib ::callback_meta<>{};
50
48
49
+ // the 'core' component exposes the 'say_message' service for others to extend
51
50
struct core {
52
- constexpr static auto config =
53
- cib::config(cib::exports<say_message>);
51
+ constexpr static auto config = cib::exports<say_message>;
54
52
};
55
- ```
56
- #### hello_world.hpp
57
- The `hello_world` component **extends** the `say_message` **service** with new
58
- contained in a lambda.
59
- ```c++
60
- #include <iostream>
61
- #include <cib/cib.hpp>
62
53
63
- struct hello_world {
54
+ // the 'say_hello_world' component extends 'say_message' with its own functionality
55
+ struct say_hello_world {
64
56
constexpr static auto config =
65
- cib::config(
66
- cib::extend<say_message>([](){
67
- std::cout << "Hello, world!" << std::endl;
68
- })
69
- );
57
+ cib::extend<say_message>([ ] ( ) {
58
+ std::cout << "Hello, world!" << std::endl;
59
+ });
70
60
};
71
- ```
72
- #### lazy_dog.hpp
73
- Another component, ` lazy_dog ` is also extending the ` say_message ` ** service** .
74
- This time it is using a function pointer instead of a lambda. The function
75
- definition of ` talk_about_the_dog ` could also be placed in a ` lazy_dog.cpp `
76
- file if desired.
77
- ``` c++
78
- #include < iostream>
79
- #include < cib/cib.hpp>
80
61
81
- struct lazy_dog {
82
- static void talk_about_the_dog() {
83
- std::cout << "The quick brown fox jumps over the lazy dog." << std::endl;
84
- }
85
-
86
- constexpr static auto config =
87
- cib::config(
88
- cib::extend<say_message>(talk_about_the_dog)
89
- );
90
- };
91
- ```
92
- #### my_project.hpp
93
- All the components are brought together in the project configuration, `my_project`.
94
- ```c++
95
- #include "core.hpp"
96
- #include "hello_world.hpp"
97
- #include "lazy_dog.hpp"
98
-
99
- struct my_project {
62
+ // the 'hello_world' project composes 'core' and 'say_hello_world'
63
+ struct hello_world {
100
64
constexpr static auto config =
101
- cib::components<core, hello_world, lazy_dog >;
65
+ cib::components<core, say_hello_world >;
102
66
};
103
- ```
104
- #### main.cpp
105
- The ` cib::nexus ` brings all the ** services** and ** features** together. This is
106
- where the compile-time initialization and build process actually occurs.
107
- ``` c++
108
- #include " my_project.hpp"
109
67
110
- cib::nexus<my_project> nexus{};
68
+ // the nexus instantiates the project
69
+ cib::nexus<hello_world> nexus{};
111
70
112
71
int main() {
113
- // services can be accessed directly from the nexus...
72
+ // the fully extended and built services are ready to be used
114
73
nexus.service<say_message>();
115
-
116
- // ...or they can be accessed anywhere through cib::service
117
- nexus.init();
118
- cib::service<say_message>();
74
+ return 0;
119
75
}
120
76
```
121
- #### Execution
122
- All of the initialization and registration occurs at compile-time, but the
123
- new functionality is still executed at run-time:
124
- ```
125
- shell> ./my_project
126
- Hello, world!
127
- The quick brown fox jumps over the lazy dog.
128
- Hello, world!
129
- The quick brown fox jumps over the lazy dog.
130
- ```
77
+
78
+ A larger and more illustrative example can be found in this repo at
79
+ [examples/hello_world](examples/hello_world).
131
80
132
81
### Building
133
82
134
83
*cib* is built with CMake. The single header is built with the
135
84
`release_header` target:
136
85
137
86
```shell
87
+ git clone https://github.com/intel/compile-time-init-build.git
138
88
cmake -B build
139
89
cmake --build build -t release_header
140
90
ls build/include/cib/ | grep cib.hpp
@@ -143,6 +93,10 @@ ls build/include/cib/ | grep cib.hpp
143
93
This combines all the * cib* header files in the ` include ` tree by recursively
144
94
including the ` #include ` directives and ignoring all other macros.
145
95
96
+ ** NOTE:** * cib* uses git submodules to include its testing dependencies. The
97
+ CMake configuration * should* fetch the submodules for you, but only if the
98
+ repository was cloned as a git repo and not downloaded as an archive.
99
+
146
100
Unit tests are registered with CTest:
147
101
148
102
``` shell
0 commit comments