@@ -30,7 +30,7 @@ in your repo and add the cib directory in your CMakeLists.txt file:
3030
3131``` cmake
3232add_subdirectory(lib/compile-time-init-build)
33- target_link_libraries(your_target PRIVATE Cib )
33+ target_link_libraries(your_target PRIVATE cib )
3434```
3535
3636With 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.
4040Since * cib* is a library for efficiently building firmware through composition
4141a simple example takes a few more lines than a typical "Hello, world!"
4242
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.
4643``` c++
4744#include < cib/cib.hpp>
45+ #include < iostream>
4846
4947struct say_message : public cib ::callback_meta<>{};
5048
49+ // the 'core' component exposes the 'say_message' service for others to extend
5150struct core {
52- constexpr static auto config =
53- cib::config(cib::exports<say_message>);
51+ constexpr static auto config = cib::exports<say_message>;
5452};
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>
6253
63- struct hello_world {
54+ // the 'say_hello_world' component extends 'say_message' with its own functionality
55+ struct say_hello_world {
6456 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+ });
7060};
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>
8061
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 {
10064 constexpr static auto config =
101- cib::components<core, hello_world, lazy_dog >;
65+ cib::components<core, say_hello_world >;
10266};
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"
10967
110- cib::nexus<my_project> nexus{};
68+ // the nexus instantiates the project
69+ cib::nexus<hello_world> nexus{};
11170
11271int main() {
113- // services can be accessed directly from the nexus...
72+ // the fully extended and built services are ready to be used
11473 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;
11975}
12076```
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).
13180
13281### Building
13382
13483*cib* is built with CMake. The single header is built with the
13584`release_header` target:
13685
13786```shell
87+ git clone https://github.com/intel/compile-time-init-build.git
13888cmake -B build
13989cmake --build build -t release_header
14090ls build/include/cib/ | grep cib.hpp
@@ -143,6 +93,10 @@ ls build/include/cib/ | grep cib.hpp
14393This combines all the * cib* header files in the ` include ` tree by recursively
14494including the ` #include ` directives and ignoring all other macros.
14595
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+
146100Unit tests are registered with CTest:
147101
148102``` shell
0 commit comments