microsoft / vcpkg-docs

MIT License
54 stars 68 forks source link

Totally puzzled by this page - please help me understand #239

Closed KhardanOne closed 1 month ago

KhardanOne commented 9 months ago

Hi there,

Thank you for this page. I am trying to understand how CMake in VS works, and it is a big help.

It also gives me a lot of headache. I managed to follow it in the end, but it took me two whole evenings, which is much more than I am used to. I am still puzzled about some parts of it, and I found some minor mistakes in documentation.

1. Quotation marks issue

The documentation says: set VCPKG_ROOT="C:\path\to\vcpkg" If you do this, then you will get the following warning when running vcpkg new --application:

warning: The vcpkg C:\Bin\Dev\vcpkg\vcpkg.exe is using detected vcpkg root C:\Bin\Dev\vcpkg and ignoring mismatched VCPKG_ROOT environment value "C:\Bin\Dev\vcpkg". To suppress this message, unset the environment variable or use the --vcpkg-root command line switch.

First I did not realize what the problem was, so I tracked down that I had vcpkg also installed as a part of VS. I uninstalled it, even restarted the Windows, just to be sure, still the warning stayed. It was just then that I realized vcpkg expects the path without quotation marks.

2. Puzzled about env vars

This sentence: "Setting VCPKG_ROOT helps Visual Studio locate your vcpkg instance." puzzles me. As far as my knowledge goes, environment variables are local to the command prompt. If I open another developer prompt, there is no VCPKG_ROOT defined. I suppose it is not defined for the Visual Studio itself. I googled it if I am wrong, but didn't find any proof. So I think that this sentence is not true. I am not sure, though. Please let me know if I am wrong.

3. Puzzled about the jsons

In the old times, without vcpkg I would create a CMakeLists.txt file, added a fetch_content for fmt, and I was done, with just a few lines of code. Now we need to run extra tools, and create three extra jsons. One of these jsons cannot even be put in VCS. OK, I can add it to .gitignore, but then on the other computers the other users must recreate it. I could not memorize it. I would need to google it. This sounds bad. You said that explaining the third json is outside of the scope of this document. So my question: why is it worth doing things this way if it is so much more complicated? I am asking this honestly. No malice or passive-aggressive things here. I really would like to understand, as I see the world is going this direction. I'd really appreciate if you answer this question.

4. Advice for documenting hotkeys

The documentation says: Press Ctrl+Shift+B to build the project in Visual Studio. - I would advise you to first always define where can a feature be found on the user interface, and add the hotkeys just after that. I have never used Ctrl+Shift+B before, so I did not know what it is (I used F7 instead). When starting VS this way, the buttons and menus are different on the UI, and even the wording you use is different. Normally these hotkeys build the solution, not the project. So it was not clear for me that you changed the meaning of the words.

I hope these minor notes help improving the documentation, and I am looking forward for your answers.

Cheers, Khardan


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

RochaStratovan commented 9 months ago

@KhardanOne,

Hello, first, I'm another user sharing information. I'm not a vpkg authority.

Quotation Marks

I noticed some issues with the instructions. I'm not sure if what terminal environment you are using: CMD, Powershell or Bash.

I use CMD, and noticed the instructions from CMD aren't quite correct.

This is wrong in CMD

set VCPKG_ROOT="C:\path\to\vcpkg"

This causes VCPKG_ROOT to be set to the specified string, including the quotes, and it leads to the exact problem you observed.

The correct syntax for this is one of the following

set "VCPKG_ROOT=C:\path\to\vcpkg"
set VCPKG_ROOT=C:\path\to\vcpkg

I agree that the first one seems odd that the quotes are cuddling the variable and the path. However, that is a Windows-ism that clearly identifies the beginning and end of the set expression.

For the second one, you don't know if there are any spaces after vpkg that would be included in the assignment. It will work if there are zero spaces after vpkg. The cuddled quotes (") is preferred as it clearly shows no spaces follow the value.

Consider trying the following to see how this works:

:: Set using quotes at wrong spot
set GREETINGS="Hello World"

:: Show the value wrapped in braces
echo {%GREETINGS%}

:: {"Hello World"}

:: Set using quotes at correct spot
set "GREETINGS=Hello World"

:: Show the value wrapped in braces
echo {%GREETINGS%}

:: {Hello World}

:: Set without quotes and no trailing spaces
set GREETINGS=Hello World

:: Show the value wrapped in braces
echo {%GREETINGS%}

:: {Hello World}

:: Set without quotes and three trailing spaces
set GREETINGS=Hello World<space><space><space>

:: Show the value wrapped in braces
echo {%GREETINGS%}

:: {Hello World   }
vicroms commented 8 months ago

1. Quotation marks issue

As @RochaStratovan this is a bug in the instructions, the correct syntax is set "VCPKG_ROOT=path/to/vcpkg". I have opened PRs to fix this issue in our documentation.

2. Puzzled about env vars

You are right about how env vars work and we should clarify this in the article.

3. Puzzled about the jsons

Creating the CMakePresets.json and CMakeUserPresets.json files is optional and we should probably add wording about it. There is a "simpler" way to integrate vcpkg with vcpkg by simply adding "-DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg/scripts/buildsystemes/vcpkg.cmake" in your CMake configure step which we explain in the CMake integration documentation. However, "modern" CMake seems to be moving in the direction of using presets files.

The vcpkg.json file is required to specify your dependencies, so that one is unavoidable.

4. Advice for documenting hotkeys

Thanks for the feedback!

KhardanOne commented 8 months ago

Thank you @RochaStratovan and @vicroms .

dmiller423 commented 4 months ago

If only visual studio didn't overwrite that env var and make it utterly worthless from inside the IDE, causing it to then re{download,build} everything and FAIL.. the CMakePresets is not really optional if you want to use your own paths in that case. Since it will always use default path (what you see in VS Command Line - which must be set in that batch file.)

dmiller423 commented 4 months ago

Rather unfortunately, you still can't even use your own env var in the CMakePresets ENV{VCPKG_ROOT}, it must be hardcoded .. ridiculous

dmiller423 commented 4 months ago

I love this too image