Use Pigweed modules in your project#
Once you have set up Pigweed, you can start using Pigweed modules in your project.
Link against Pigweed modules#
Pigweed modules are exposed as CMake targets. To use a module, simply link against
it using target_link_libraries.
For example, to use pw::Vector from pw_containers:
Include the header in your code:
#include "pw_containers/vector.h"
Link against the module in your
CMakeLists.txt:add_library(my_library my_library.cc) target_link_libraries(my_library PUBLIC pw_containers.vector)
Use pw_add_library#
Pigweed provides a helper function pw_add_library which simplifies library
creation and automatically handles some Pigweed-specific configuration. It is
recommended to use this for your own libraries that depend on Pigweed.
include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
pw_add_library(my_library
SOURCES
my_library.cc
PUBLIC_DEPS
pw_containers.vector
)
See CMake for more details on pw_add_library.
Protobuf Generation#
Pigweed provides CMake support for generating C++ and Python code from Protobuf files.
include($ENV{PW_ROOT}/pw_protobuf_compiler/proto.cmake)
pw_proto_library(my_protos
SOURCES
my_proto.proto
)
pw_add_library(my_lib
SOURCES
my_lib.cc
PUBLIC_DEPS
my_protos.pwpb
)
See pw_protobuf_compiler for more details.