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

MSVC: Use bundled CMake if present and no other is in path #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

knopp
Copy link

@knopp knopp commented Feb 27, 2022

MSVC already comes with CMake installed (by default if desktop development with c++ was specified), but CMake-rs doesn't know about it.

This PR will use the bundled installation, but only if there is no other CMake installation in path.

@alexcrichton
Copy link
Member

Is there documentation to link to of how this is found? Otherwise all I can really do is rubber-stamp this as I don't really have any idea if this is correct and there's not really a great way to test this on CI

@knopp
Copy link
Author

knopp commented Feb 28, 2022

I don't think there's any official documentation mentioning CMake installation location. It just happen to be for last few MSVC versions. For example flutter tool which invokes during build locates it same way.

@knopp
Copy link
Author

knopp commented Mar 1, 2022

This may need some work. If there are multiple VS versions installed side by side (i.e. 2019 and 2022) this finds CMake from 2019, but will fail because it tries to use it with 2022 generator.

@alexcrichton
Copy link
Member

Ok, sorry but I've decided that I will no longer maintain this crate and it needs a new maintainer.

@shuffle2
Copy link

shuffle2 commented Apr 14, 2022

Another issue with the proposed implementation (and which I had in my first try) is that you cannot rely on devenv.exe being present (e.g. if only Build Tools are installed). It seems the correct way is to use the related COM interface to get the base directory and then append Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe.

Note you can also use ISetupInstance2.GetPackages to check if the cmake package (Microsoft.VisualStudio.VC.CMake) is installed and query some info about it if desired (of course, it doesn't give you any path information about the installed cmake though, that would be too helpful :))

In any case, the cc crate should probably just expose ability to get the root installation directory corresponding to the resolved cl.exe such that users of that crate can tack on any paths they want without having to reimplement all the COM stuff or relying on cc to implement detection of every possible binary distributed with msvc.

@the-Arioch
Copy link

Can the CMAKE_COMMAND env-var be used ? it seems to be a standard (albeit hard to find) way?

https://cmake.org/cmake/help/latest/variable/CMAKE_COMMAND.html

I would maybe also look into https://cmake.org/cmake/help/latest/variable/CMAKE_VS_DEVENV_COMMAND.html

I have a similar, perhaps, case whgen a newb run into a wall: DDoSolitary/yasfw#49

However i do not have giant VS IDE amd instead try to wrap my mind around VC++ Build Tools and VSCode
In my case it is MS Visual Studio Build Tools 2019 version 16.11.12

I also just had installed VCPKG.

Now i seem to have two CMAKE instances:

c:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
d:\CppProjects\VCPKG\downloads\tools\cmake-3.22.2-windows\cmake-3.22.2-windows-i386\bin\cmake.exe 

Looks kind of redundant and weird, but that is how Microsoft is making it yet.
The latter can be optimistically found using another env-var VCPKG_ROOT=d:\CppProjects\VCPKG\, but this does not seem a good solution.
Perhaps there can be some newb-oriented document how to install or find CMAKE tool, and the library refer to it when spewing "not found" error, instead of letting novice users out in the dark.


A faux path would be to rely on the standard Windows sequence of finding an application by document file extension. To me HKEY_CLASSES_ROOT\.cmake registry branch finally led me to VSCode editor, to to cmake processor.

@shuffle2
Copy link

fwiw here's how i've solved it (works for VS or BuildTools-only installs) https://github.com/unicorn-engine/unicorn/blob/2912cd1e299456e71f9fc52b046d84cf1aff2144/bindings/rust/build.rs#L21

@the-Arioch
Copy link

the-Arioch commented Apr 16, 2022

This seems to be related to #142

Just cross-linking two discussion pages, making it easier to find

@thomcc
Copy link
Member

thomcc commented Oct 28, 2022

Mind rebasing to fix conflicts? This path seems right to me (matches the path on my windows machine, and the path that other projects seem to have used for some time without problems).

@ChrisDenton
Copy link
Member

I do think cc-rs should have a proper way to get the base directory but an interim solution does make sense.

@tgross35 tgross35 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants