pw_{build_info,persistent_ram,checksum,random}: Add CMake support

Change-Id: I24ca6b7fcd164073e134e3263e333fc3b325f2d7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/80223
Reviewed-by: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9815ca1..b748430 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,7 @@
 add_subdirectory(pw_base64 EXCLUDE_FROM_ALL)
 add_subdirectory(pw_blob_store EXCLUDE_FROM_ALL)
 add_subdirectory(pw_build EXCLUDE_FROM_ALL)
+add_subdirectory(pw_build_info EXCLUDE_FROM_ALL)
 add_subdirectory(pw_bytes EXCLUDE_FROM_ALL)
 add_subdirectory(pw_checksum EXCLUDE_FROM_ALL)
 add_subdirectory(pw_chrono EXCLUDE_FROM_ALL)
@@ -49,6 +50,7 @@
 add_subdirectory(pw_log_null EXCLUDE_FROM_ALL)
 add_subdirectory(pw_log_tokenized EXCLUDE_FROM_ALL)
 add_subdirectory(pw_minimal_cpp_stdlib EXCLUDE_FROM_ALL)
+add_subdirectory(pw_persistent_ram EXCLUDE_FROM_ALL)
 add_subdirectory(pw_polyfill EXCLUDE_FROM_ALL)
 add_subdirectory(pw_protobuf EXCLUDE_FROM_ALL)
 add_subdirectory(pw_protobuf_compiler EXCLUDE_FROM_ALL)
diff --git a/pw_build_info/CMakeLists.txt b/pw_build_info/CMakeLists.txt
new file mode 100644
index 0000000..1fb6699
--- /dev/null
+++ b/pw_build_info/CMakeLists.txt
@@ -0,0 +1,49 @@
+# Copyright 2022 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.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+# GNU build IDs aren't supported by Windows and macOS.
+if((NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") AND
+   (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin"))
+  pw_add_module_library(pw_build_info.build_id
+    HEADERS
+      public/pw_build_info/build_id.h
+    PUBLIC_INCLUDES
+      public
+    PUBLIC_DEPS
+      pw_polyfill.cstddef
+      pw_polyfill.span
+    PUBLIC_LINK_OPTIONS
+      -Wl,--build-id=sha1
+    SOURCES
+      build_id.cc
+    PRIVATE_DEPS
+      pw_preprocessor
+    PRIVATE_COMPILE_OPTIONS
+      -Wno-array-bounds
+      -Wno-stringop-overflow
+  )
+endif()
+
+# Automatically add the gnu build ID linker sections when building for Linux.
+# macOS and Windows executables are not supported, and embedded targets must
+# manually add the snippet to their linker script in a read-only section.
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+  target_link_options(pw_build_info.build_id
+    PUBLIC
+      "-T${CMAKE_CURRENT_SOURCE_DIR}/add_build_id_to_default_script.ld"
+      "-L${CMAKE_CURRENT_SOURCE_DIR}"
+  )
+endif()
diff --git a/pw_checksum/CMakeLists.txt b/pw_checksum/CMakeLists.txt
index 2c437a9..6a79e47 100644
--- a/pw_checksum/CMakeLists.txt
+++ b/pw_checksum/CMakeLists.txt
@@ -14,12 +14,44 @@
 
 include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
 
-pw_auto_add_simple_module(pw_checksum
+pw_add_module_library(pw_checksum
+  HEADERS
+    public/pw_checksum/crc16_ccitt.h
+    public/pw_checksum/crc32.h
+  PUBLIC_INCLUDES
+    public
   PUBLIC_DEPS
-    pw_span
-  PRIVATE_DEPS
+    pw_polyfill.cstddef
+    pw_polyfill.span
     pw_bytes
+  SOURCES
+    crc16_ccitt.cc
+    crc32.cc
 )
 if(Zephyr_FOUND AND CONFIG_PIGWEED_CHECKSUM)
   zephyr_link_libraries(pw_checksum)
 endif()
+
+pw_add_test(pw_checksum.crc16_ccitt_test
+  SOURCES
+    crc16_ccitt_test.cc
+    crc16_ccitt_test_c.c
+  DEPS
+    pw_checksum
+    pw_random
+  GROUPS
+    modules
+    pw_checksum
+)
+
+pw_add_test(pw_checksum.crc32_test
+  SOURCES
+    crc32_test.cc
+    crc32_test_c.c
+  DEPS
+    pw_checksum
+    pw_random
+  GROUPS
+    modules
+    pw_checksum
+)
diff --git a/pw_persistent_ram/CMakeLists.txt b/pw_persistent_ram/CMakeLists.txt
new file mode 100644
index 0000000..f9ba73e
--- /dev/null
+++ b/pw_persistent_ram/CMakeLists.txt
@@ -0,0 +1,55 @@
+# Copyright 2022 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.
+
+include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
+
+pw_add_module_library(pw_persistent_ram
+  HEADERS
+    public/pw_persistent_ram/persistent.h
+    public/pw_persistent_ram/persistent_buffer.h
+  PUBLIC_INCLUDES
+    public
+  PUBLIC_DEPS
+    pw_assert
+    pw_bytes
+    pw_checksum
+    pw_polyfill.cstddef
+    pw_polyfill.span
+    pw_preprocessor
+    pw_stream
+  SOURCES
+    persistent_buffer.cc
+)
+
+pw_add_test(pw_persistent_ram.persistent_test
+  SOURCES
+    persistent_test.cc
+  DEPS
+    pw_persistent_ram
+    pw_random
+  GROUPS
+    modules
+    pw_persistent_ram
+)
+
+pw_add_test(pw_persistent_ram.persistent_buffer_test
+  SOURCES
+    persistent_buffer_test.cc
+  DEPS
+    pw_persistent_ram
+    pw_random
+  GROUPS
+    modules
+    pw_persistent_ram
+)
diff --git a/pw_random/CMakeLists.txt b/pw_random/CMakeLists.txt
index aabdd23..776cccd 100644
--- a/pw_random/CMakeLists.txt
+++ b/pw_random/CMakeLists.txt
@@ -14,9 +14,25 @@
 
 include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
 
-pw_auto_add_simple_module(pw_random
+pw_add_module_library(pw_random
+  HEADERS
+    public/pw_random/random.h
+    public/pw_random/xor_shift.h
+  PUBLIC_INCLUDES
+    public
   PUBLIC_DEPS
     pw_bytes
-    pw_span
+    pw_polyfill.cstddef
+    pw_polyfill.span
     pw_status
 )
+
+pw_add_test(pw_random.xor_shift_star_test
+  SOURCES
+    xor_shift_test.cc
+  DEPS
+    pw_random
+  GROUPS
+    modules
+    pw_random
+)