Problem
Building mlir-aie with GCC fails on the CppTests targets (target_model, target_model_rtti, register_database) with errors like:
<command-line>: error: token '=' is not valid in preprocessor expressions
The generated compile command has garbled -D flags where multiple definitions are concatenated into a single quoted string:
-D_GLIBCXX_USE_CXX11_ABI=1
-D_GLIBCXX_USE_CXX11_ABI="1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
GCC rejects these; Clang also rejects them when they reach GCC's libstdc++ headers (which evaluate _GLIBCXX_USE_CXX11_ABI in preprocessor conditionals).
Root Cause
LLVM_DEFINITIONS is a space-separated string:
"-D_GNU_SOURCE -D_GLIBCXX_USE_CXX11_ABI=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
When passed directly to add_definitions(${LLVM_DEFINITIONS}), CMake does not split this into individual flags -- it passes it as one token, which produces garbled quoted output in the generated build rules.
This happens in two places:
CMakeLists.txt:165
test/CMakeLists.txt:97
Both files also include(HandleLLVMOptions), which independently adds the same definitions via add_compile_definitions(), creating a second layer of duplication.
Verified Fix
Replace:
add_definitions(${LLVM_DEFINITIONS})
With:
separate_arguments(LLVM_DEFS_LIST NATIVE_COMMAND "${LLVM_DEFINITIONS}")
add_definitions(${LLVM_DEFS_LIST})
This converts the space-separated string into a proper CMake list before passing it. Tested in both CMakeLists.txt and test/CMakeLists.txt -- all three CppTests build and pass with both GCC 15 and Clang 20.
Environment
- GCC 15 / Clang 20 (Ubuntu 25.10)
- LLVM 23 (built from mlir-aie's pinned commit
979132a)
- CMake 3.31
- Ubuntu 25.10 (kernel 6.19)
Problem
Building mlir-aie with GCC fails on the CppTests targets (
target_model,target_model_rtti,register_database) with errors like:The generated compile command has garbled
-Dflags where multiple definitions are concatenated into a single quoted string:GCC rejects these; Clang also rejects them when they reach GCC's libstdc++ headers (which evaluate
_GLIBCXX_USE_CXX11_ABIin preprocessor conditionals).Root Cause
LLVM_DEFINITIONSis a space-separated string:When passed directly to
add_definitions(${LLVM_DEFINITIONS}), CMake does not split this into individual flags -- it passes it as one token, which produces garbled quoted output in the generated build rules.This happens in two places:
CMakeLists.txt:165test/CMakeLists.txt:97Both files also
include(HandleLLVMOptions), which independently adds the same definitions viaadd_compile_definitions(), creating a second layer of duplication.Verified Fix
Replace:
With:
This converts the space-separated string into a proper CMake list before passing it. Tested in both
CMakeLists.txtandtest/CMakeLists.txt-- all three CppTests build and pass with both GCC 15 and Clang 20.Environment
979132a)