pw_hdlc_lite: Build HDLC RPC example with CMake
- Add CMakeLists.txt for pw_hdlc_lite's RPC example.
- Update the pw_rpc CMake to split out individual libraries.
- Small docs update for using third party code in the CMake build.
Change-Id: I3ee8b85a275c3402dc494b0ea3a8140005241ccf
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24280
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_build/docs.rst b/pw_build/docs.rst
index b2b5b5c..2da654b 100644
--- a/pw_build/docs.rst
+++ b/pw_build/docs.rst
@@ -375,7 +375,10 @@
.. code-block:: sh
- cmake -B out/cmake_host -S /path/to/pigweed -G Ninja -DCMAKE_TOOLCHAIN_FILE=pw_toolchain/host_clang/toolchain.cmake
+ cmake -B out/cmake_host -S "$PW_ROOT" -G Ninja -DCMAKE_TOOLCHAIN_FILE=$PW_ROOT/pw_toolchain/host_clang/toolchain.cmake
+
+The ``PW_ROOT`` environment variable must point to the root of the Pigweed
+directory. This variable is set by Pigweed's environment setup.
Tests can be executed with the ``pw_run_tests.GROUP`` targets. To run Pigweed
module tests, execute ``pw_run_tests.modules``:
@@ -446,6 +449,17 @@
"")``), the dependency is not available. Otherwise, it is available and
libraries declared by it can be referenced.
+The third_party variable may be set with the CMake ``set`` function in the
+toolchain file or a ``CMakeLists.txt`` prior to adding any directories. This
+statement sets the third-party variable for Nanopb to ``PRESENT``:
+
+.. code-block:: cmake
+
+ set(dir_pw_third_party_nanopb PRESENT CACHE STRING "" FORCE)
+
+Alternately, the variable may be set temporarily with ``ccmake`` or
+``cmake-gui``.
+
Use Pigweed from an existing CMake project
------------------------------------------
To use Pigweed libraries form a CMake-based project, simply include the Pigweed
diff --git a/pw_hdlc_lite/CMakeLists.txt b/pw_hdlc_lite/CMakeLists.txt
index e61c309..44c0ba8 100644
--- a/pw_hdlc_lite/CMakeLists.txt
+++ b/pw_hdlc_lite/CMakeLists.txt
@@ -26,3 +26,5 @@
pw_checksum
pw_log
)
+
+add_subdirectory(rpc_example)
diff --git a/pw_hdlc_lite/rpc_example/CMakeLists.txt b/pw_hdlc_lite/rpc_example/CMakeLists.txt
new file mode 100644
index 0000000..9c2d32c
--- /dev/null
+++ b/pw_hdlc_lite/rpc_example/CMakeLists.txt
@@ -0,0 +1,24 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+add_executable(pw_hdlc_lite.rpc_example hdlc_rpc_server.cc main.cc)
+
+target_link_libraries(pw_hdlc_lite.rpc_example
+ PRIVATE
+ pw_hdlc_lite
+ pw_log
+ pw_rpc.nanopb.echo_service
+ pw_rpc.server
+)
diff --git a/pw_protobuf_compiler/proto.cmake b/pw_protobuf_compiler/proto.cmake
index 50e05e8..1966fc7 100644
--- a/pw_protobuf_compiler/proto.cmake
+++ b/pw_protobuf_compiler/proto.cmake
@@ -217,8 +217,8 @@
target_link_libraries("${NAME}.nanopb_rpc"
INTERFACE
"${NAME}.nanopb"
+ pw_rpc.nanopb.method_union
pw_rpc.server
- pw_rpc.nanopb
${DEPS}
)
add_dependencies("${NAME}.nanopb_rpc" "${NAME}.generate.nanopb_rpc")
diff --git a/pw_rpc/nanopb/CMakeLists.txt b/pw_rpc/nanopb/CMakeLists.txt
index 9e1365b..896fefd 100644
--- a/pw_rpc/nanopb/CMakeLists.txt
+++ b/pw_rpc/nanopb/CMakeLists.txt
@@ -14,15 +14,53 @@
include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
-pw_auto_add_simple_module(pw_rpc.nanopb
+pw_add_module_library(pw_rpc.nanopb.method
+ SOURCES
+ nanopb_method.cc
PUBLIC_DEPS
- pw_rpc.client
- pw_rpc.common
+ pw_rpc.nanopb.common
+ pw_rpc.server
+ PRIVATE_DEPS
+ pw_log
+)
+
+pw_add_module_library(pw_rpc.nanopb.method_union
+ PUBLIC_DEPS
+ pw_rpc.nanopb.method
pw_rpc.raw
pw_rpc.server
PRIVATE_DEPS
+ pw_log
+)
+
+pw_add_module_library(pw_rpc.nanopb.client
+ SOURCES
+ nanopb_client_call.cc
+ PUBLIC_DEPS
+ pw_rpc.nanopb.common
+ pw_rpc.common
+)
+
+pw_add_module_library(pw_rpc.nanopb.common
+ SOURCES
+ nanopb_common.cc
+ PUBLIC_DEPS
+ pw_bytes
+ pw_rpc.common
pw_third_party.nanopb
- TEST_DEPS
+)
+
+pw_add_module_library(pw_rpc.nanopb.echo_service
+ PUBLIC_DEPS
+ pw_rpc.echo_proto.nanopb_rpc
+)
+
+pw_auto_add_module_tests(pw_rpc.nanopb
+ PRIVATE_DEPS
+ pw_rpc.client
+ pw_rpc.raw
+ pw_rpc.server
+ pw_rpc.nanopb.common
pw_rpc.echo_proto.nanopb_rpc
pw_rpc.test_protos.nanopb_rpc
pw_rpc.test_utils