[llvm] [docs][CMake] Add CMakePreset, improve VS documentation (PR #84760)

Aaron Ballman via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 06:51:19 PDT 2024


================
@@ -119,7 +121,56 @@ These instruction were tested with Visual Studio 2019 and Python 3.9.6:
  Select the last link: ``Source code (zip)`` and unpack the downloaded file using
  Windows Explorer built-in zip support or any other unzip tool.
 
-12. Finally, configure LLVM using CMake:
+12. Open the LLVM folder in Visual Studio or generate a solution via CMake.
+
+  At this point you can select if you want to use the
+  :ref:`native support for CMake<vs_native_cmake>` in Visual Studio or
+  :ref:`generate Visual Studio<gen_vs_cmake>` solution file from CMake.
+  Both integrations are supported in the LLVM project.
+
+.. _vs_native_cmake:
+
+Visual Studio native CMake support
+==================================
+
+Before you can build LLVM with Visual Studio you need to follow the step
+outlined in :ref:`Getting Started<getting_started>`.
+
+Support for native CMake integration was added in Visual Studio 2019, but it has
+been made more robust in 2022. If you are using Visual Studio before 2022, it's
+recommended to generate a Visual Studio solution from CMake instead of using the
+native CMake integration.
+
+If you want to generate a Visual Studio Solution, please refer to the
+chapter below on :ref:generating Visual Studio Solution<gen_vs_cmake>.
+
+To use the native CMake support, launch Visual Studio 2022 and select the option
+Open a Local Folder and open the root llvm-project folder. This will
+automatically launch CMake (have some patience, it can be a bit slow) and
+populate the interface.
+
+LLVM ships with a default CMakePresets.json that is supposed to make it easy to
+get started, but usually you need to modify the settings used. The best way to
+do this is to create a CMakeUserPresets.json in the llvm subfolder and add your
+configuration there. For more information about the Preset system, see
+`Microsoft's documentation <https://learn.microsoft.com/en-us/cpp/build/cmake-presets-json-reference>`_.
----------------
AaronBallman wrote:

> Huh, this is surprising to me. Note that I haven't really used Visual Studio, but use Visual Studio Code, I was just asked by my team to improve this for the VS users since it was a little bit of a chore.

Heh, and I use Visual Studio far more than Visual Studio Code, so it's possible this may just be "different tools work differently" and causing a bit of tension.

> When I read up on the CMakeSettings.json vs CMakePresets.json, it read to me like CMakeSettings.json was the Microsoft only solution that is only respected in Visual Studio and that upstream CMake added CMakePresets.json to do the same thing, presets also work with the command line cmake --preset <name> and they work in Visual Studio Code. So I thought it was a better way forward.

It would sure seem like it would be the right way forward!

> I guess the goal I had here was that I got a lot of questions from devs that when they opened the default settings "clang wasn't enabled" and it was not at all obvious to them how to enable it. That's why I thought a default set of settings to build clang was an upgrade to that.

I believe that can be done from CMakeSettings.json:

![Capture](https://github.com/llvm/llvm-project/assets/4587626/74d2e427-1d8c-4216-8e8e-d3f9a7e65b03)

but I perhaps that's not very intuitive (you have to look at "advanced" options and select a specific compiler rather than rely on finding one on PATH).

I'm starting to suspect that whether we stick with `CMakeSettings.json` or go with `CMakePresets.json`, it might make sense for us to document setup in *both* Visual Studio and VS Code, with screenshots, to help folks out because these tools are both popular and yet manage to do things differently. WDYT?

> All in all, happy to remove that file if it's supposed to work the way that you described above. But I would love for some more input from someone that understand's the idea behind hiding that UI in VS when using presets think? @dmpots do you know or do you know someone that knows? (sorry I snooped and saw that you where working at Microsoft).

+1, I don't feel like I understand enough about how Visual Studio and VS Code CMake support works to feel like I know which way is the best way forward. But I'm more than happy to play test any instructions we want to add to the docs to see how well they work in Visual Studio, help you get screenshots, etc.


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


More information about the llvm-commits mailing list