Skip to content

[CMake] Fix MSVC runtime library selection - #8804

Draft
Alex Sepkowski (alsepkow) wants to merge 1 commit into
microsoft:mainfrom
alsepkow:user/alsepkow/fix-msvc-runtime-selection
Draft

[CMake] Fix MSVC runtime library selection#8804
Alex Sepkowski (alsepkow) wants to merge 1 commit into
microsoft:mainfrom
alsepkow:user/alsepkow/fix-msvc-runtime-selection

Conversation

@alsepkow

Copy link
Copy Markdown
Contributor

Make the existing LLVM_USE_CRT_<CONFIG> settings control the MSBuild runtime-library property generated by modern CMake.

CMake's CMP0091 runtime-library abstraction emits <RuntimeLibrary> in Visual Studio projects. The current ChooseMSVCCRT.cmake implementation instead edits CMAKE_<LANG>_FLAGS_<CONFIG>, which can leave an explicit /MT competing with CMake's generated /MD selection. Translate the existing MD, MDd, MT, and MTd values to CMAKE_MSVC_RUNTIME_LIBRARY so the requested runtime is authoritative. Configurations without an explicit override retain CMake's normal DLL-runtime defaults.

Testing:

  • Configured an x64 build with Visual Studio 18 2026 and LLVM_USE_CRT_RELEASE=MT.
  • Verified the generated Release llvm-tblgen.vcxproj contains <RuntimeLibrary>MultiThreaded</RuntimeLibrary> while Debug remains MultiThreadedDebugDLL.
  • Built the Release llvm-tblgen target successfully.
  • Verified dumpbin /dependents reports only KERNEL32.dll, with no VCRUNTIME or MSVCP imports.

No release note is needed because this fixes build-system behavior rather than compiler-visible behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0f4d0e10-e926-4bce-b36b-0abebc08f6dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

1 participant