pw_tokenizer: Apply linker script in CMake
Automatically add the linker script in the CMake build, as the GN build
does.
Change-Id: Ibbad27fbb94c091c065983b80c91a85527844226
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24440
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_build/docs.rst b/pw_build/docs.rst
index 2da654b..d78818b 100644
--- a/pw_build/docs.rst
+++ b/pw_build/docs.rst
@@ -433,6 +433,15 @@
* To force to a backend to a particular value globally, call ``pw_set_backend``
in the top-level ``CMakeLists.txt`` before any other CMake code is executed.
+Toolchain setup
+---------------
+In CMake, the toolchain is configured by setting CMake variables, as described
+in the `CMake documentation <https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html>`_.
+These variables are typically set in a toolchain CMake file passed to ``cmake``
+with the ``-D`` option (``-DCMAKE_TOOLCHAIN_FILE=path/to/file.cmake``).
+For Pigweed embedded builds, set ``CMAKE_SYSTEM_NAME`` to the empty string
+(``""``).
+
Third party libraries
---------------------
The CMake build includes third-party libraries similarly to the GN build. A
@@ -481,7 +490,6 @@
Bazel
=====
-
Bazel is currently very experimental, and only builds for host.
The common configuration for Bazel for all modules is in the ``pigweed.bzl``
diff --git a/pw_tokenizer/CMakeLists.txt b/pw_tokenizer/CMakeLists.txt
index b96104a..a467ada 100644
--- a/pw_tokenizer/CMakeLists.txt
+++ b/pw_tokenizer/CMakeLists.txt
@@ -27,6 +27,19 @@
pw_varint
)
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "")
+ target_link_options(pw_tokenizer
+ PUBLIC
+ "-T${CMAKE_CURRENT_SOURCE_DIR}/pw_tokenizer_linker_sections.ld"
+ )
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+ target_link_options(pw_tokenizer
+ PUBLIC
+ "-T${CMAKE_CURRENT_SOURCE_DIR}/add_tokenizer_sections_to_default_script.ld"
+ "-L${CMAKE_CURRENT_SOURCE_DIR}"
+ )
+endif()
+
pw_add_module_library(pw_tokenizer.base64
SOURCES
base64.cc