[libc-commits] [libc] [libc] Add libc_set_definition and libc_add_definition to properly pass definitions to MSVC. (PR #189664)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Tue Mar 31 14:50:01 PDT 2026


================
@@ -10,6 +10,31 @@ if(NOT DEFINED LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
   endif()
 endif()
 
+function(libc_add_definition output_var def)
+  if(MSVC)
+    list(APPEND ${output_var} "/D${def}")
+  else()
+    list(APPEND ${output_var} "-D${def}")
+  endif()
+
+  set(${output_var} ${${output_var}} PARENT_SCOPE)
+endfunction()
----------------
petrhosek wrote:

Is there a reason for writing this logic ourselves rather than relying on CMake builtin functions like [`target_compile_definitions`](https://cmake.org/cmake/help/latest/command/target_compile_definitions.html)?

https://github.com/llvm/llvm-project/pull/189664


More information about the libc-commits mailing list