Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KhardanOne opened this issue Jan 13, 2024 · 3 comments
Open

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

KhardanOne opened this issue Jan 13, 2024 · 3 comments
Assignees

Comments

@KhardanOne
Copy link

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
Copy link

@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
Copy link
Member

vicroms commented Feb 12, 2024

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
Copy link
Author

Thank you @RochaStratovan and @vicroms .

@vicroms vicroms self-assigned this Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants