pw_build: Fix source compilation in CMake facades

Compile source files in the main library instead of the .facade library.

Change-Id: Ie3d75deeb59434fc9e0023b5c82f3b23d9feb247
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/28681
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
diff --git a/pw_build/pigweed.cmake b/pw_build/pigweed.cmake
index 1be5b72..a1046e5 100644
--- a/pw_build/pigweed.cmake
+++ b/pw_build/pigweed.cmake
@@ -124,9 +124,9 @@
 
 # Wrapper around cmake_parse_arguments that fails with an error if any arguments
 # remained unparsed.
-macro(_pw_parse_argv_strict function start_arg prefix options one multi)
+macro(_pw_parse_argv_strict function start_arg options one multi)
   cmake_parse_arguments(PARSE_ARGV
-      "${start_arg}" "${prefix}" "${options}" "${one}" "${multi}"
+      "${start_arg}" arg "${options}" "${one}" "${multi}"
   )
 
   if(NOT "${${prefix}_UNPARSED_ARGUMENTS}" STREQUAL "")
@@ -136,6 +136,9 @@
   endif()
 endmacro()
 
+# Common arguments for libraries.
+set(_common_args SOURCES HEADERS PUBLIC_DEPS PRIVATE_DEPS)
+
 # Creates a library in a module. The library has access to the public/ include
 # directory.
 #
@@ -148,8 +151,8 @@
 #   IMPLEMENTS_FACADES - which facades this library implements
 #
 function(pw_add_module_library NAME)
-  set(list_args SOURCES HEADERS PUBLIC_DEPS PRIVATE_DEPS IMPLEMENTS_FACADES)
-  _pw_parse_argv_strict(pw_add_module_library 1 arg "" "" "${list_args}")
+  set(list_args ${_common_args} IMPLEMENTS_FACADES)
+  _pw_parse_argv_strict(pw_add_module_library 1 "" "" "${list_args}")
 
   # Check that the library's name is prefixed by the module name.
   get_filename_component(module "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
@@ -162,7 +165,7 @@
   endif()
 
   add_library("${NAME}" EXCLUDE_FROM_ALL ${arg_HEADERS} ${arg_SOURCES})
-  target_include_directories("${NAME}" PUBLIC public/)
+  target_include_directories("${NAME}" PUBLIC public)
   target_link_libraries("${NAME}"
     PUBLIC
       pw_build
@@ -193,13 +196,13 @@
 # module that implements the facade depends on a library named
 # MODULE_NAME.facade.
 #
-# pw_add_facade accepts the same arguments as pw_add_module_library, with the
-# following additions:
+# pw_add_facade accepts the same arguments as pw_add_module_library, except for
+# IMPLEMENTS_FACADES. It also accepts the following argument:
 #
 #  DEFAULT_BACKEND - which backend to use by default
 #
 function(pw_add_facade NAME)
-  cmake_parse_arguments(PARSE_ARGV 1 arg "" "DEFAULT_BACKEND" "")
+  _pw_parse_argv_strict(pw_add_facade 1 "" "DEFAULT_BACKEND" "${_common_args}")
 
   # If no backend is set, a script that displays an error message is used
   # instead. If the facade is used in the build, it fails with this error.
@@ -221,13 +224,18 @@
 
   # Define the facade library, which is used by the backend to avoid circular
   # dependencies.
-  pw_add_module_library("${NAME}.facade" ${arg_UNPARSED_ARGUMENTS})
+  add_library("${NAME}.facade" INTERFACE)
+  target_include_directories("${NAME}.facade" INTERFACE public)
+  target_link_libraries("${NAME}.facade" INTERFACE ${arg_PUBLIC_DEPS})
 
   # Define the public-facing library for this facade, which depends on the
   # header files in .facade target and exposes the dependency on the backend.
-  add_library("${NAME}" INTERFACE)
-  target_link_libraries("${NAME}"
-    INTERFACE
+  pw_add_module_library("${NAME}"
+    SOURCES
+      ${arg_SOURCES}
+    HEADERS
+      ${arg_HEADERS}
+    PUBLIC_DEPS
       "${NAME}.facade"
       "${${NAME}_BACKEND}"
   )