@@ -131,15 +131,42 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
131131 endforeach ()
132132
133133 if (MSVC )
134+ # Configurable path for MSVC LLVM bin directory
135+ set (MSVC_LLVM_BIN_PATH "" CACHE PATH "Path to MSVC LLVM bin directory containing clang_rt.asan_dynamic-x86_64.dll" )
136+
134137 # Get the compiler directory and construct paths dynamically
135138 get_filename_component (COMPILER_DIR "${CMAKE_CXX_COMPILER } " DIRECTORY )
136139
140+ # Build list of search paths for ASAN DLL
141+ # Relative paths navigate from compiler location to LLVM bin directory:
142+ # - ../../bin: For clang-cl in VC/Tools/Llvm/x64/bin relative to MSVC compiler
143+ # - ../../../bin: For alternative LLVM layouts
144+ set (ASAN_SEARCH_PATHS
145+ "${COMPILER_DIR} "
146+ "${COMPILER_DIR} /../../../bin"
147+ "${COMPILER_DIR} /../../bin"
148+ )
149+
150+ # Add user-specified path if provided
151+ if (MSVC_LLVM_BIN_PATH)
152+ list (APPEND ASAN_SEARCH_PATHS "${MSVC_LLVM_BIN_PATH} " )
153+ endif ()
154+
155+ # Add paths based on VSINSTALLDIR environment variable if available
156+ if (DEFINED ENV{VSINSTALLDIR})
157+ list (APPEND ASAN_SEARCH_PATHS "$ENV{VSINSTALLDIR} /VC/Tools/Llvm/x64/bin" )
158+ endif ()
159+
160+ # Add common VS installation paths as fallback (supporting different editions)
161+ list (APPEND ASAN_SEARCH_PATHS
162+ "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/Llvm/x64/bin"
163+ "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/Llvm/x64/bin"
164+ "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin"
165+ )
166+
137167 # Find and install ASAN DLL for Debug builds
138168 find_file (ASAN_DLL "clang_rt.asan_dynamic-x86_64.dll"
139- PATHS "${COMPILER_DIR} "
140- "${COMPILER_DIR} /../../../bin"
141- "${COMPILER_DIR} /../../bin"
142- "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin"
169+ PATHS ${ASAN_SEARCH_PATHS}
143170 NO_DEFAULT_PATH )
144171 if (ASAN_DLL)
145172 install (FILES ${ASAN_DLL} CONFIGURATIONS Debug DESTINATION bin)
0 commit comments