[Mlir-commits] [clang] [flang] [lldb] [llvm] [mlir] [cmake] Fix clang-cl PCH mismatches in static builds (PR #191552)
Alexandre Ganea
llvmlistbot at llvm.org
Tue Apr 14 06:30:54 PDT 2026
https://github.com/aganea updated https://github.com/llvm/llvm-project/pull/191552
>From 9881ee16b756ac64507de5e70edbc2ca939813df Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <aganea at havenstudios.com>
Date: Fri, 10 Apr 2026 14:48:38 -0400
Subject: [PATCH 1/2] [cmake] Fix clang-cl PCH mismatches in static builds
With precompiled headers enabled, targets that define macros differently from the
PCH built for LLVMSupport (or that gain macros after PCH setup) trigger
clang-cl warnings and unreliable builds:
warning: definition of macro 'LLVM_BUILD_STATIC' does not match definition in
precompiled header [-Wclang-cl-pch]
Similar mismatches were reported for:
- CLANG_BUILD_STATIC (Clang static builds on Windows)
- _ENABLE_EXTENDED_ALIGNED_STORAGE (LLDB directory-level definitions)
- MLIR_INCLUDE_TESTS, FLANG_INCLUDE_TESTS (including DEF=1 forms)
Object libraries defined LLVM_BUILD_STATIC after llvm_update_pch(), so the PCH
did not see the macro. Executables hit the same issue when LLVM_BUILD_STATIC
was applied after compile flags / PCH resolution.
MLIRNVVMTarget adds target compile definitions such as MLIR_NVVM_EMBED_LIBDEVICE
and __DEFAULT_CUDATOOLKIT_PATH__ that conflict with a reused PCH:
warning: definition of macro 'MLIR_NVVM_EMBED_LIBDEVICE' does not match ...
warning: definition of macro '__DEFAULT_CUDATOOLKIT_PATH__' does not match ...
This is an effort to build the Windows LLVM installer error- and warning-free.
I used llvm/utils/release/build_llvm_release.bat for that purpose.
---
clang/cmake/modules/AddClang.cmake | 9 ++++-
clang/lib/Testing/CMakeLists.txt | 4 ++
flang/cmake/modules/AddFlang.cmake | 8 +++-
llvm/cmake/modules/AddLLVM.cmake | 57 +++++++++++++++++++++++++----
mlir/lib/Target/LLVM/CMakeLists.txt | 1 +
5 files changed, 69 insertions(+), 10 deletions(-)
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index e2112d7c326e2..09c62c44fc94b 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -106,7 +106,14 @@ macro(add_clang_library name)
endif()
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
endif()
- llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+ # CLANG_BUILD_STATIC is added after llvm_add_library, but it changes the
+ # expansion of CLANG_ABI visibility macros, causing a PCH mismatch with
+ # libraries that were built without it. Disable PCH reuse in that case.
+ set(clang_pch_reuse)
+ if((WIN32 AND NOT MINGW) AND NOT CLANG_LINK_CLANG_DYLIB)
+ set(clang_pch_reuse DISABLE_PCH_REUSE)
+ endif()
+ llvm_add_library(${name} ${LIBTYPE} ${clang_pch_reuse} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
if((WIN32 AND NOT MINGW) AND NOT CLANG_LINK_CLANG_DYLIB)
# Make sure all consumers also turn off visibility macros so they're not
diff --git a/clang/lib/Testing/CMakeLists.txt b/clang/lib/Testing/CMakeLists.txt
index f4c99413d6dbf..9aeeb43e0079f 100644
--- a/clang/lib/Testing/CMakeLists.txt
+++ b/clang/lib/Testing/CMakeLists.txt
@@ -4,11 +4,15 @@ set(EXCLUDE_FROM_ALL ON)
# Not add_clang_library: this is not part of clang's public library interface.
# Unit tests should depend on this with target_link_libraries(), rather
# than with clang_target_link_libraries().
+#
+# DISABLE_PCH_REUSE: clang_target_link_libraries below propagates
+# CLANG_BUILD_STATIC from Clang libraries, which conflicts with the PCH.
add_llvm_library(clangTesting
CommandLineArgs.cpp
TestAST.cpp
BUILDTREE_ONLY
+ DISABLE_PCH_REUSE
LINK_COMPONENTS
MC
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index ca233103ccdbe..29ae17afe1144 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -63,7 +63,13 @@ function(add_flang_library name)
# Let llvm_add_library decide, taking BUILD_SHARED_LIBS into account.
set(LIBTYPE)
endif()
- llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+ # Clang libraries propagate CLANG_BUILD_STATIC as a PUBLIC definition on
+ # Windows static builds, which conflicts with the PCH from LLVM libraries.
+ set(_flang_pch_reuse)
+ if(ARG_CLANG_LIBS AND (WIN32 AND NOT MINGW) AND NOT CLANG_LINK_CLANG_DYLIB)
+ set(_flang_pch_reuse DISABLE_PCH_REUSE)
+ endif()
+ llvm_add_library(${name} ${LIBTYPE} ${_flang_pch_reuse} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
clang_target_link_libraries(${name} PRIVATE ${ARG_CLANG_LIBS})
if (ARG_MLIR_LIBS)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 0730ba2f529ed..9efe89725ef20 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -107,6 +107,41 @@ function(llvm_update_pch name)
set(ARG_DISABLE_PCH_REUSE ON)
endif()
+ # Certain compile definitions change macro expansion in ways that conflict
+ # with a reused PCH (e.g. visibility macros, MSVC STL config, test-only
+ # code guards). Collect both target-level and directory-level definitions
+ # and disable PCH reuse when any of these are present but absent from the
+ # PCH source. Definitions may appear as "FOO" or "FOO=value".
+ set(_pch_conflict_defs
+ LLVM_BUILD_STATIC CLANG_BUILD_STATIC
+ _ENABLE_EXTENDED_ALIGNED_STORAGE
+ MLIR_INCLUDE_TESTS FLANG_INCLUDE_TESTS)
+ get_target_property(target_defs ${name} COMPILE_DEFINITIONS)
+ get_directory_property(dir_defs COMPILE_DEFINITIONS)
+ set(all_defs)
+ if(target_defs)
+ list(APPEND all_defs ${target_defs})
+ endif()
+ if(dir_defs)
+ list(APPEND all_defs ${dir_defs})
+ endif()
+ foreach(def ${_pch_conflict_defs})
+ if(def IN_LIST all_defs)
+ set(ARG_DISABLE_PCH_REUSE ON)
+ break()
+ endif()
+ # Also match "DEF=value" forms (e.g. FLANG_INCLUDE_TESTS=1).
+ foreach(actual_def ${all_defs})
+ if(actual_def MATCHES "^${def}=")
+ set(ARG_DISABLE_PCH_REUSE ON)
+ break()
+ endif()
+ endforeach()
+ if(ARG_DISABLE_PCH_REUSE)
+ break()
+ endif()
+ endforeach()
+
# Find PCH with highest priority from dependencies. We reuse the first PCH
# with the highest priority. If the target has its own set of PCH, we give it
# a higher priority so that dependents will prefer the new PCH. We don't do
@@ -637,6 +672,9 @@ function(llvm_add_library name)
${ALL_FILES}
)
llvm_update_compile_flags(${obj_name})
+ if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${obj_name} PRIVATE LLVM_BUILD_STATIC)
+ endif()
llvm_update_pch(${obj_name})
if(CMAKE_GENERATOR STREQUAL "Xcode")
set(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/Dummy.c)
@@ -683,10 +721,6 @@ function(llvm_add_library name)
endif()
endforeach()
endif()
-
- if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
- target_compile_definitions(${obj_name} PRIVATE LLVM_BUILD_STATIC)
- endif()
endif()
if(ARG_SHARED AND ARG_STATIC)
@@ -772,6 +806,9 @@ function(llvm_add_library name)
# $<TARGET_OBJECTS> doesn't require compile flags.
if(NOT obj_name)
llvm_update_compile_flags(${name})
+ if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
+ endif()
llvm_update_pch(${name})
else()
get_target_property(lib_disable_pch ${obj_name} DISABLE_PRECOMPILE_HEADERS)
@@ -1188,6 +1225,14 @@ macro(add_llvm_executable name)
set(ARG_DISABLE_PCH_REUSE ON)
endif()
+ # Executables in static builds get LLVM_BUILD_STATIC defined, but the PCH
+ # from LLVM component libraries does not have it. This macro changes the
+ # expansion of LLVM_ABI and similar visibility macros, causing a PCH
+ # mismatch that clang-cl warns about (-Wclang-cl-pch).
+ if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB OR NOT LLVM_LINK_LLVM_DYLIB)
+ target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
+ endif()
+
# $<TARGET_OBJECTS> doesn't require compile flags.
if(NOT LLVM_ENABLE_OBJLIB)
llvm_update_compile_flags(${name})
@@ -1265,10 +1310,6 @@ macro(add_llvm_executable name)
export_executable_symbols(${name})
endif()
- if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB OR NOT LLVM_LINK_LLVM_DYLIB)
- target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
- endif()
-
if(LLVM_BUILD_LLVM_DYLIB_VIS AND NOT LLVM_DYLIB_EXPORT_INLINES AND
MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
# This has to match how the libraries the executable is linked to are built or there be linker errors.
diff --git a/mlir/lib/Target/LLVM/CMakeLists.txt b/mlir/lib/Target/LLVM/CMakeLists.txt
index 94660e231888b..f98c65bd2acbb 100644
--- a/mlir/lib/Target/LLVM/CMakeLists.txt
+++ b/mlir/lib/Target/LLVM/CMakeLists.txt
@@ -34,6 +34,7 @@ add_mlir_dialect_library(MLIRNVVMTarget
NVVM/Target.cpp
OBJECT
+ DISABLE_PCH_REUSE
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
>From d2a5cdc71220eeb3255f1851253a157e9c339130 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <alex_toresh at yahoo.fr>
Date: Tue, 14 Apr 2026 09:05:16 -0400
Subject: [PATCH 2/2] Narrow macros to improve PCH reusage
---
clang/cmake/modules/AddClang.cmake | 9 +---
clang/lib/Testing/CMakeLists.txt | 4 --
clang/tools/libclang/CMakeLists.txt | 7 +++
flang/CMakeLists.txt | 4 --
flang/cmake/modules/AddFlang.cmake | 8 +--
flang/tools/fir-opt/CMakeLists.txt | 3 ++
lldb/CMakeLists.txt | 1 -
llvm/cmake/modules/AddLLVM.cmake | 59 ++++++++--------------
llvm/cmake/modules/HandleLLVMOptions.cmake | 10 ++++
llvm/tools/llvm-config/CMakeLists.txt | 3 +-
mlir/CMakeLists.txt | 1 -
mlir/tools/mlir-lsp-server/CMakeLists.txt | 3 ++
mlir/tools/mlir-opt/CMakeLists.txt | 4 ++
mlir/tools/mlir-query/CMakeLists.txt | 3 ++
mlir/tools/mlir-reduce/CMakeLists.txt | 3 ++
mlir/tools/mlir-translate/CMakeLists.txt | 3 ++
16 files changed, 60 insertions(+), 65 deletions(-)
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index 09c62c44fc94b..e2112d7c326e2 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -106,14 +106,7 @@ macro(add_clang_library name)
endif()
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
endif()
- # CLANG_BUILD_STATIC is added after llvm_add_library, but it changes the
- # expansion of CLANG_ABI visibility macros, causing a PCH mismatch with
- # libraries that were built without it. Disable PCH reuse in that case.
- set(clang_pch_reuse)
- if((WIN32 AND NOT MINGW) AND NOT CLANG_LINK_CLANG_DYLIB)
- set(clang_pch_reuse DISABLE_PCH_REUSE)
- endif()
- llvm_add_library(${name} ${LIBTYPE} ${clang_pch_reuse} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+ llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
if((WIN32 AND NOT MINGW) AND NOT CLANG_LINK_CLANG_DYLIB)
# Make sure all consumers also turn off visibility macros so they're not
diff --git a/clang/lib/Testing/CMakeLists.txt b/clang/lib/Testing/CMakeLists.txt
index 9aeeb43e0079f..f4c99413d6dbf 100644
--- a/clang/lib/Testing/CMakeLists.txt
+++ b/clang/lib/Testing/CMakeLists.txt
@@ -4,15 +4,11 @@ set(EXCLUDE_FROM_ALL ON)
# Not add_clang_library: this is not part of clang's public library interface.
# Unit tests should depend on this with target_link_libraries(), rather
# than with clang_target_link_libraries().
-#
-# DISABLE_PCH_REUSE: clang_target_link_libraries below propagates
-# CLANG_BUILD_STATIC from Clang libraries, which conflicts with the PCH.
add_llvm_library(clangTesting
CommandLineArgs.cpp
TestAST.cpp
BUILDTREE_ONLY
- DISABLE_PCH_REUSE
LINK_COMPONENTS
MC
diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
index 5fdfc474332f7..dcb9a331d381e 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -133,7 +133,14 @@ if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
remove_definitions("-D_XOPEN_SOURCE=700")
endif()
+set(_libclang_pch_opts)
+if(ENABLE_SHARED)
+ # DEFINE_SYMBOL _CINDEX_LIB_ is set on the shared target after creation,
+ # which conflicts with the PCH that was built without it.
+ set(_libclang_pch_opts DISABLE_PCH_REUSE)
+endif()
add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC} INSTALL_WITH_TOOLCHAIN
+ ${_libclang_pch_opts}
OUTPUT_NAME ${output_name}
${SOURCES}
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index be0b1f3d9b270..97ef8bba8d6ad 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -489,10 +489,6 @@ include(GetClangResourceDir)
get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
-if (FLANG_INCLUDE_TESTS)
- add_compile_definitions(FLANG_INCLUDE_TESTS=1)
-endif()
-
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(cmake/modules)
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index 29ae17afe1144..ca233103ccdbe 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -63,13 +63,7 @@ function(add_flang_library name)
# Let llvm_add_library decide, taking BUILD_SHARED_LIBS into account.
set(LIBTYPE)
endif()
- # Clang libraries propagate CLANG_BUILD_STATIC as a PUBLIC definition on
- # Windows static builds, which conflicts with the PCH from LLVM libraries.
- set(_flang_pch_reuse)
- if(ARG_CLANG_LIBS AND (WIN32 AND NOT MINGW) AND NOT CLANG_LINK_CLANG_DYLIB)
- set(_flang_pch_reuse DISABLE_PCH_REUSE)
- endif()
- llvm_add_library(${name} ${LIBTYPE} ${_flang_pch_reuse} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+ llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
clang_target_link_libraries(${name} PRIVATE ${ARG_CLANG_LIBS})
if (ARG_MLIR_LIBS)
diff --git a/flang/tools/fir-opt/CMakeLists.txt b/flang/tools/fir-opt/CMakeLists.txt
index e735c2c2ff1a3..25e00f68b5cb4 100644
--- a/flang/tools/fir-opt/CMakeLists.txt
+++ b/flang/tools/fir-opt/CMakeLists.txt
@@ -1,5 +1,8 @@
add_flang_tool(fir-opt fir-opt.cpp)
llvm_update_compile_flags(fir-opt)
+if(FLANG_INCLUDE_TESTS)
+ target_compile_definitions(fir-opt PRIVATE FLANG_INCLUDE_TESTS=1)
+endif()
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 0a1ca5cf391ef..da389ad12b68d 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -47,7 +47,6 @@ if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
endif()
if (WIN32)
- add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
if (NOT MSVC)
# _BSD_SOURCE is required for MinGW's getopt.h to define optreset
add_definitions(-D_BSD_SOURCE)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 9efe89725ef20..e7b15d041044d 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -80,6 +80,8 @@ function(llvm_update_compile_flags name)
endfunction()
function(llvm_update_pch name)
+ cmake_parse_arguments(ARG "DISABLE_PCH_REUSE" "" "" ${ARGN})
+
if(LLVM_REQUIRES_RTTI OR LLVM_REQUIRES_EH)
# Non-default RTTI/EH results in incompatible flags, precluding PCH reuse.
set(ARG_DISABLE_PCH_REUSE ON)
@@ -107,41 +109,6 @@ function(llvm_update_pch name)
set(ARG_DISABLE_PCH_REUSE ON)
endif()
- # Certain compile definitions change macro expansion in ways that conflict
- # with a reused PCH (e.g. visibility macros, MSVC STL config, test-only
- # code guards). Collect both target-level and directory-level definitions
- # and disable PCH reuse when any of these are present but absent from the
- # PCH source. Definitions may appear as "FOO" or "FOO=value".
- set(_pch_conflict_defs
- LLVM_BUILD_STATIC CLANG_BUILD_STATIC
- _ENABLE_EXTENDED_ALIGNED_STORAGE
- MLIR_INCLUDE_TESTS FLANG_INCLUDE_TESTS)
- get_target_property(target_defs ${name} COMPILE_DEFINITIONS)
- get_directory_property(dir_defs COMPILE_DEFINITIONS)
- set(all_defs)
- if(target_defs)
- list(APPEND all_defs ${target_defs})
- endif()
- if(dir_defs)
- list(APPEND all_defs ${dir_defs})
- endif()
- foreach(def ${_pch_conflict_defs})
- if(def IN_LIST all_defs)
- set(ARG_DISABLE_PCH_REUSE ON)
- break()
- endif()
- # Also match "DEF=value" forms (e.g. FLANG_INCLUDE_TESTS=1).
- foreach(actual_def ${all_defs})
- if(actual_def MATCHES "^${def}=")
- set(ARG_DISABLE_PCH_REUSE ON)
- break()
- endif()
- endforeach()
- if(ARG_DISABLE_PCH_REUSE)
- break()
- endif()
- endforeach()
-
# Find PCH with highest priority from dependencies. We reuse the first PCH
# with the highest priority. If the target has its own set of PCH, we give it
# a higher priority so that dependents will prefer the new PCH. We don't do
@@ -675,7 +642,11 @@ function(llvm_add_library name)
if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
target_compile_definitions(${obj_name} PRIVATE LLVM_BUILD_STATIC)
endif()
- llvm_update_pch(${obj_name})
+ set(_pch_opts)
+ if(ARG_DISABLE_PCH_REUSE)
+ list(APPEND _pch_opts DISABLE_PCH_REUSE)
+ endif()
+ llvm_update_pch(${obj_name} ${_pch_opts})
if(CMAKE_GENERATOR STREQUAL "Xcode")
set(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/Dummy.c)
file(WRITE ${DUMMY_FILE} "// This file intentionally empty\n")
@@ -809,7 +780,11 @@ function(llvm_add_library name)
if(ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
target_compile_definitions(${name} PRIVATE LLVM_BUILD_STATIC)
endif()
- llvm_update_pch(${name})
+ set(_pch_opts)
+ if(ARG_DISABLE_PCH_REUSE)
+ list(APPEND _pch_opts DISABLE_PCH_REUSE)
+ endif()
+ llvm_update_pch(${name} ${_pch_opts})
else()
get_target_property(lib_disable_pch ${obj_name} DISABLE_PRECOMPILE_HEADERS)
if(NOT ${lib_disable_pch})
@@ -1236,7 +1211,11 @@ macro(add_llvm_executable name)
# $<TARGET_OBJECTS> doesn't require compile flags.
if(NOT LLVM_ENABLE_OBJLIB)
llvm_update_compile_flags(${name})
- llvm_update_pch(${name})
+ if(ARG_DISABLE_PCH_REUSE)
+ llvm_update_pch(${name} DISABLE_PCH_REUSE)
+ else()
+ llvm_update_pch(${name})
+ endif()
elseif(NOT ARG_DISABLE_PCH_REUSE)
get_target_property(lib_disable_pch ${obj_name} DISABLE_PRECOMPILE_HEADERS)
if(NOT ${lib_disable_pch})
@@ -1986,7 +1965,9 @@ function(add_benchmark benchmark_name)
set(EXCLUDE_FROM_ALL ON)
endif()
- add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN})
+ # DISABLE_PCH_REUSE: the benchmark library propagates BENCHMARK_STATIC_DEFINE
+ # as an INTERFACE definition, which conflicts with the PCH.
+ add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH DISABLE_PCH_REUSE ${ARGN})
set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
set_output_directory(${benchmark_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
get_subproject_title(subproject_title)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5f1d68762c038..52f84b0dbb8ee 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -599,6 +599,7 @@ if( MSVC )
_CRT_NONSTDC_NO_WARNINGS
_SCL_SECURE_NO_DEPRECATE
_SCL_SECURE_NO_WARNINGS
+ _ENABLE_EXTENDED_ALIGNED_STORAGE
)
# Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI.
@@ -607,6 +608,15 @@ if( MSVC )
_UNICODE
)
+ # In static builds (no shared LLVM/Clang dylib), visibility macros like
+ # LLVM_ABI / CLANG_ABI must resolve to noops. Define the corresponding
+ # guards globally so every target — including the LLVMSupport PCH — sees
+ # them, avoiding clang-cl PCH mismatch warnings (-Wclang-cl-pch).
+ if(NOT LLVM_LINK_LLVM_DYLIB AND NOT BUILD_SHARED_LIBS)
+ add_compile_definitions(LLVM_BUILD_STATIC)
+ add_compile_definitions(CLANG_BUILD_STATIC)
+ endif()
+
if (LLVM_WINSYSROOT)
if (NOT CLANG_CL)
message(ERROR "LLVM_WINSYSROOT requires clang-cl")
diff --git a/llvm/tools/llvm-config/CMakeLists.txt b/llvm/tools/llvm-config/CMakeLists.txt
index fc285b2ba156a..5819b2ec9ed65 100644
--- a/llvm/tools/llvm-config/CMakeLists.txt
+++ b/llvm/tools/llvm-config/CMakeLists.txt
@@ -15,6 +15,7 @@ add_llvm_tool(llvm-config
# want to build an entire native libLLVM.so in addition to the cross one just
# for the native `llvm-config`!
DISABLE_LLVM_LINK_LLVM_DYLIB
+ DISABLE_PCH_REUSE
)
# Compute the substitution values for various items.
@@ -88,7 +89,7 @@ llvm_expand_pseudo_components(LLVM_DYLIB_COMPONENTS_expanded "${LLVM_DYLIB_COMPO
configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
# Set build-time environment(s).
-add_compile_definitions(CMAKE_CFG_INTDIR="$<CONFIG>")
+target_compile_definitions(llvm-config PRIVATE CMAKE_CFG_INTDIR="$<CONFIG>")
if(LLVM_ENABLE_MODULES)
target_compile_options(llvm-config PUBLIC
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 6d05fa50ecd05..39d9adc6a8f52 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -261,7 +261,6 @@ add_subdirectory(lib)
add_subdirectory(lib/CAPI)
if (MLIR_INCLUDE_TESTS)
- add_definitions(-DMLIR_INCLUDE_TESTS)
add_custom_target(MLIRUnitTests)
set_target_properties(MLIRUnitTests PROPERTIES FOLDER "MLIR/Tests")
if (TARGET llvm_gtest)
diff --git a/mlir/tools/mlir-lsp-server/CMakeLists.txt b/mlir/tools/mlir-lsp-server/CMakeLists.txt
index 0518620699ae0..3d57fa756359e 100644
--- a/mlir/tools/mlir-lsp-server/CMakeLists.txt
+++ b/mlir/tools/mlir-lsp-server/CMakeLists.txt
@@ -45,6 +45,9 @@ add_mlir_tool(mlir-lsp-server
)
mlir_target_link_libraries(mlir-lsp-server PRIVATE ${LIBS})
target_link_libraries(mlir-lsp-server PRIVATE ${test_libs})
+if(MLIR_INCLUDE_TESTS)
+ target_compile_definitions(mlir-lsp-server PRIVATE MLIR_INCLUDE_TESTS)
+endif()
llvm_update_compile_flags(mlir-lsp-server)
mlir_check_all_link_libraries(mlir-lsp-server)
diff --git a/mlir/tools/mlir-opt/CMakeLists.txt b/mlir/tools/mlir-opt/CMakeLists.txt
index c607ccfa80e3c..919dd9b6ceb6f 100644
--- a/mlir/tools/mlir-opt/CMakeLists.txt
+++ b/mlir/tools/mlir-opt/CMakeLists.txt
@@ -93,6 +93,10 @@ add_mlir_tool(mlir-opt
)
mlir_target_link_libraries(mlir-opt PRIVATE ${LIBS})
target_link_libraries(mlir-opt PRIVATE ${test_libs})
+if(MLIR_INCLUDE_TESTS)
+ target_compile_definitions(MLIRMlirOptMain PRIVATE MLIR_INCLUDE_TESTS)
+ target_compile_definitions(mlir-opt PRIVATE MLIR_INCLUDE_TESTS)
+endif()
llvm_update_compile_flags(mlir-opt)
mlir_check_all_link_libraries(mlir-opt)
diff --git a/mlir/tools/mlir-query/CMakeLists.txt b/mlir/tools/mlir-query/CMakeLists.txt
index 1668bbac23d16..51c2d093362a9 100644
--- a/mlir/tools/mlir-query/CMakeLists.txt
+++ b/mlir/tools/mlir-query/CMakeLists.txt
@@ -8,6 +8,9 @@ add_mlir_tool(mlir-query
mlir-query.cpp
)
llvm_update_compile_flags(mlir-query)
+if(MLIR_INCLUDE_TESTS)
+ target_compile_definitions(mlir-query PRIVATE MLIR_INCLUDE_TESTS)
+endif()
mlir_target_link_libraries(mlir-query
PRIVATE
MLIRQueryLib
diff --git a/mlir/tools/mlir-reduce/CMakeLists.txt b/mlir/tools/mlir-reduce/CMakeLists.txt
index 349d75b84df0e..67af5c0421dfd 100644
--- a/mlir/tools/mlir-reduce/CMakeLists.txt
+++ b/mlir/tools/mlir-reduce/CMakeLists.txt
@@ -16,6 +16,9 @@ add_mlir_tool(mlir-reduce
mlir_target_link_libraries(mlir-reduce PRIVATE ${LIBS})
target_link_libraries(mlir-reduce PRIVATE ${test_libs})
+if(MLIR_INCLUDE_TESTS)
+ target_compile_definitions(mlir-reduce PRIVATE MLIR_INCLUDE_TESTS)
+endif()
llvm_update_compile_flags(mlir-reduce)
mlir_check_all_link_libraries(mlir-reduce)
diff --git a/mlir/tools/mlir-translate/CMakeLists.txt b/mlir/tools/mlir-translate/CMakeLists.txt
index b356e04bb1dc4..05ff1ac5ed1b3 100644
--- a/mlir/tools/mlir-translate/CMakeLists.txt
+++ b/mlir/tools/mlir-translate/CMakeLists.txt
@@ -9,6 +9,9 @@ add_mlir_tool(mlir-translate
mlir-translate.cpp
)
llvm_update_compile_flags(mlir-translate)
+if(MLIR_INCLUDE_TESTS)
+ target_compile_definitions(mlir-translate PRIVATE MLIR_INCLUDE_TESTS)
+endif()
mlir_target_link_libraries(mlir-translate
PRIVATE
${dialect_libs}
More information about the Mlir-commits
mailing list