[compiler-rt] [llvm] [cmake] Refactor DIA SDK detection into FindDIASDK module (PR #160354)

Ruoyu Zhong via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 09:26:15 PDT 2025


================
@@ -0,0 +1,74 @@
+# Finds the Microsoft DIA SDK and sets DIASDK_FOUND and related variables.
+#
+# This module is intended to be used both internally by LLVM's build system and
+# by consuming projects when loading LLVMConfig.cmake.
+#
+# LLVM_WINSYSROOT may be set for locating the DIA SDK.
+#
+# If successful, the following variables will be defined:
+#   DIASDK_FOUND
+#   DIASDK_INCLUDE_DIR
+#   DIASDK_LIBRARIES
+#
+# Additionally, the following import target will be defined:
+#   DIASDK::Diaguids
+
+if(NOT WIN32)
+  set(DIASDK_FOUND FALSE)
+  return()
+endif()
+
+if(LLVM_WINSYSROOT)
+  set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
+      "Path to the DIA SDK")
+else()
+  set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
----------------
ZhongRuoyu wrote:

If both `LLVM_WINSYSROOT` and `VSINSTALLDIR` are unset, the subsequent package-finding logic should fail and `DIASDK_FOUND` will be unset. A `Could NOT find DIASDK` diagnostic message from `find_package_handle_standard_args` will be shown.

I intentionally didn't let it emit any warning message because DIA SDK is allowed to be not found (see usage in `compiler-rt/cmake/config-ix.cmake`, for example).

In the `llvm/cmake/config-ix.cmake` usage, this find module is used with as `find(DIASDK REQUIRED)` so failure to find DIA SDK will also fail the CMake configuration.

Where the LLVM distribution tarball is used (see the original linked issues that this PR aims to fix), the following error will be emitted if neither `LLVM_WINSYSROOT` nor `VSINSTALLDIR` are set:

```
CMake Error at C:/llvm/lib/cmake/llvm/LLVMExports.cmake:522 (set_target_properties):
  The link interface of target "LLVMDebugInfoPDB" contains:

    DIASDK::Diaguids

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  C:/llvm/lib/cmake/llvm/LLVMConfig.cmake:367 (include)
  CMakeLists.txt:8 (find_package)
```

I'm still happy to add special handling for unset `VSINSTALLDIR` if you feel the need to do so. Was just trying to add some clarity here!


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


More information about the llvm-commits mailing list