-
Notifications
You must be signed in to change notification settings - Fork 351
Description
EDIT: The proposal might depend on later CMAKE version?! Have to verify how 2.8 could still work in case we need to support it for some reason.
In order to support cmake on windows (and to improve the plugin in general) I am proposing the following changes to the cmake plugin:
-
Allow
build_system
andchild_build_system
to beNone
(new default)- In this case, instead of hard-coded logic, use
cmake
without specific generator andcmake --build build_path --target {ALL}
whereALL
isall
in unix andALL_BUILD
on windows.- The
all
andALL_BUILD
distinction is unfortunate, but can be verified by listing all targets
- The
- This allows cmake to choose the best default for any platform (Visual Studio on Windows) and build without having to deal with Visual Studio and MSBuild discovery manually - which is really painful on windows. See the note below.
- In this case, instead of hard-coded logic, use
-
Deprecate the hardcoded generators
- We should support all generators that the underlying platform & cmake version supports
- For backwards compatibility I will keep the current dictionary, but I will alternate it with a dynamic list coming from
cmake --help
that will always match a cmake-executable. - The only gotcha is that we don't have the context at class scope, so technically a different cmake version might run in context then what the arguments would show. I can deal with it by using the cmake bin path as key for the cached generators, but in this 10% case the bound arguments would not match the underlying generators. I will need to lift the validation in the command line parameter and let cmake deal with it. However platform and cmake version should be the only necessary inputs. Generators are compiled into cmake and can not be changed/extended otherwise.
- If we really wanted to have accurate arguments we'd need to be creating a context for this part, but since the current method is not accurate either (hard-coded and may be wrong), I guess we could live with it. Also if you have an explicit cmake version it will match perfectly.
This would allow building on Windows (or other platforms?) with the default settings but still keep backwards compatibility.
I am already working towards a PR on this. Feedback appreciated.
Other necessary changes for better path handling will be in a separate issue.
Related note for the curious
Windows is very special.
In order to support other generators on windows I am looking at options for manual discovery of the visual studio installation and platform SDK - which is needlessly painful. This is not necessarily cmake related so I think its best to keep outside of core-rez/the plugin. It can be implemented as a package instead. My personal generic approach with least maintenance overhead is to rely on vswhere
[1] to find vcvarsall.bat
. Yes since they made Visual Studio only discoverable via COM in the latest releases you need a compiled executable to find the compiler to compile an executable ... 👏 Then I parse the difference of the resulting environment in terms of set, append and prepend env and reconstruct it within commands as @early()
-binding. Since all this happens at build time and generates the right commands in the visual_studio
and platform_sdk
packages that evaluate instantly. Users with non default installation paths just need to rebuild the packages locally.
That's crazy you say? The benefit is you use Microsoft's official logic (thousands lines of horrifying batch files) to setup the environment but dodge the cmd
related limitations [2] of the environment and just evaluate the resulting environment (fast!). This works correctly in any shell.
Other approaches are to reconstruct the partial/complete discovery and setup of the environment as seen in microsoft_crazyness.h
[3] or CMake's Visual Studio generator [4] implementation. But this would mean maintaining it and so far there does not seem to be a pattern in the way both Visual Studio and the platform SDK change structure between releases. It's like they try hard to make you not use their platform for development ¯\_(ツ)_/¯
[1] https://github.com/microsoft/vswhere
[2] https://devblogs.microsoft.com/oldnewthing/20100203-00/?p=15083
[3] https://threader.app/thread/1125902959789740032
[4] https://github.com/Kitware/CMake/tree/master/Source