[Mlir-commits] [mlir] [MLIR][CMake] Fix LLVM_DEFINITIONS handling in standalone example (PR #234653)
Christopher Bate
llvmlistbot at llvm.org
Thu Oct 22 08:00:58 PDT 2026
https://github.com/christopherbate created https://github.com/llvm/llvm-project/pull/234653
Split LLVM_DEFINITIONS into a CMake list before passing it to add_definitions(), and apply it before HandleLLVMOptions overwrites the variable.
Add comments explaining the compile and linker flag setup and how to scope HandleLLVMOptions around third-party dependencies.
>From d180d309b36d7387b3c34353964c2038a8c587ca Mon Sep 17 00:00:00 2001
From: Christopher Bate <cbate at nvidia.com>
Date: Wed, 21 Oct 2026 14:48:40 -0600
Subject: [PATCH] [MLIR][CMake] Fix LLVM_DEFINITIONS handling in standalone
example
Split LLVM_DEFINITIONS into a CMake list before passing it to add_definitions(), and apply it before HandleLLVMOptions overwrites the variable.
Add comments explaining the compile and linker flag setup and how to scope HandleLLVMOptions around third-party dependencies.
---
mlir/examples/standalone/CMakeLists.txt | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/mlir/examples/standalone/CMakeLists.txt b/mlir/examples/standalone/CMakeLists.txt
index 17d712f6a1064a..9b203af7467c06 100644
--- a/mlir/examples/standalone/CMakeLists.txt
+++ b/mlir/examples/standalone/CMakeLists.txt
@@ -22,9 +22,20 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
+ # LLVM_DEFINITIONS is a space-separated string of command-line flags (e.g.
+ # "-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS"), so split it into a CMake list
+ # before passing it to add_definitions(). Do this before including
+ # HandleLLVMOptions, which overwrites LLVM_DEFINITIONS in the current scope.
+ separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
+ add_definitions(${LLVM_DEFINITIONS_LIST})
+
include(TableGen)
include(AddLLVM)
include(AddMLIR)
+ # Configure C/C++ compiler and linker flags matching the LLVM/MLIR build.
+ # Note: If your project builds third-party C++ dependencies from source that
+ # do not depend on LLVM/MLIR, add them before including HandleLLVMOptions so
+ # they are not affected by LLVM-specific warning, assertion, or linker flags.
include(HandleLLVMOptions)
else()
set(EXTERNAL_PROJECT_BUILD TRUE)
@@ -54,7 +65,6 @@ include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${STANDALONE_SOURCE_DIR}/include)
include_directories(${STANDALONE_BINARY_DIR}/include)
link_directories(${LLVM_BUILD_LIBRARY_DIR})
-add_definitions(${LLVM_DEFINITIONS})
add_subdirectory(include)
add_subdirectory(lib)
More information about the Mlir-commits
mailing list