[libc-commits] [libc] [libc][cmake] Fix and enhance LibcParseArguments and add unified libc_log helper (PR #232089)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Thu Oct 15 02:24:06 PDT 2026
================
@@ -1,17 +1,127 @@
+# This file provides a unified argument parsing facility for LLVM-libc CMake
+# rules (such as add_libc_test, create_libc_test, add_entrypoint_object, etc.).
+#
+# Every argument declared in `LLVM_LIBC_OPTIONAL_ARGS`,
+# `LLVM_LIBC_SINGLE_VALUE_ARGS`, or `LLVM_LIBC_MULTI_VALUE_ARGS` automatically
+# receives two mode-specific variants:
+# OVERLAY_<arg>
+# FULL_BUILD_<arg>
+#
+# When `llvm_libc_parse_arguments` is called:
+# 1. It parses all base, overlay, and full-build argument variants using
+# cmake_parse_arguments.
+# 2. It determines the active build mode (either explicitly specified via
+# `BUILD_MODE` or defaulted from `LLVM_LIBC_FULL_BUILD`).
+# 3. It automatically merges the active mode's argument values
+# (e.g., `FULL_BUILD_<arg>` or `OVERLAY_<arg>`) into the canonical
+# `<prefix>_<arg>` variable.
+#
+# Examples:
+#
+# 1. Mode-specific dependencies or compile options:
+#
+# add_libc_test(
+# sin_test
+# SUITE libc_math_tests
+# SRCS sin_test.cpp
+# DEPENDS libc.src.math.sin
+# OVERLAY_DEPENDS libc.test.UnitTest.OverlaySupport
+# FULL_BUILD_DEPENDS libc.test.UnitTest.HermeticSupport
+# FULL_BUILD_COMPILE_OPTIONS -ffreestanding
+# )
+#
+# - In overlay mode (LLVM_LIBC_FULL_BUILD=OFF):
+# TEST_DEPENDS will contain:
+# libc.src.math.sin;libc.test.UnitTest.OverlaySupport
+#
+# - In full-build mode (LLVM_LIBC_FULL_BUILD=ON):
+# TEST_DEPENDS will contain:
+# libc.src.math.sin;libc.test.UnitTest.HermeticSupport
+# TEST_COMPILE_OPTIONS will contain:
+# -ffreestanding
+#
+# 2. Mode-restricted targets:
+#
+# add_libc_test(
+# loader_test
+# FULL_BUILD_ONLY
+# SUITE libc_loader_tests
+# SRCS loader_test.cpp
+# DEPENDS ...
+# )
+#
+# - When parsed in overlay mode:
+# TEST_FULL_BUILD_ONLY evaluates to TRUE, allowing the caller to
+# skip defining the target. Similarly, `OVERLAY_ONLY` skips the
+# target in full-build mode.
+#
+# 3. Explicit BUILD_MODE override:
+#
+# add_libc_test(
+# gpu_perf
+# IS_GPU_BENCHMARK
+# BUILD_MODE FULL_BUILD
+# SRCS perf.cpp
+# DEPENDS ...
+# )
+#
+# - Even if LLVM_LIBC_FULL_BUILD is OFF, `BUILD_MODE FULL_BUILD` ensures
+# that full-build rules and FULL_BUILD_* options are selected.
+#
+# 4. Forwarding merged arguments:
+#
+# `forward_arguments(name_prefix output_var)` re-emits only the canonical
+# (merged) arguments, dropping the mode-specific prefixes. This allows
+# outer wrapper functions to pass fully-resolved arguments down to inner
+# rules without repeating mode resolution:
+#
+# function(add_libc_test test_name)
+# llvm_libc_parse_arguments(LIBC_TEST ${ARGN})
+# ...
+# forward_arguments(LIBC_TEST forwarded_args)
+# _add_libc_test(${test_name} ${forwarded_args} ${LIBC_TEST_UNPARSED_ARGUMENTS})
+# endfunction()
+
+# Common options that control mode / target inclusion. These do NOT receive
+# OVERLAY_ or FULL_BUILD_ prefixes.
+set(LLVM_LIBC_COMMON_OPTIONAL_ARGS
+ FULL_BUILD_ONLY
+ OVERLAY_ONLY
+)
+
+set(LLVM_LIBC_COMMON_SINGLE_VALUE_ARGS
+ BUILD_MODE
----------------
labath wrote:
What's the use case for this? I mean, as far as this code is concerned, this is fine, but I'm worried about the big picture. Trying to mix targets built with different modes in the same build sounds like a bad idea to me.
https://github.com/llvm/llvm-project/pull/232089
More information about the libc-commits
mailing list