I try to parallel compile a c++ project with Visual Studio 2022. However It cost 4 minute in Visual Studio2022 or using command instead of 1minute in VSCode, VisualStudio2022 and using command will cost more time and less CPU,which is likely unable parallel compile.
Below is the environment and cmake configure:
CMakeList.txt:
You can’t set the generator this way. The project cannot choose the generator. The user selects it with the -G option when running the cmake executable, or as part of a CMake preset. An example of setting it via the command line:
cmake -G "MinGW Makefiles" ...
This also can’t be set by the project. CMAKE_BUILD_PARALLEL_LEVEL needs to be set as an environment variable when running the build step using cmake --build. You can also set this in a CMake preset, but projects shouldn’t do that because they can’t know the capabilities of the developer’s machine.
These should generally only be set after the first project() call (this is also missing from your example).
These should not be set by the project. They should be set in a toolchain file instead. They can be set on the command line or in a CMake preset, but I’d recommend using a toolchain file instead.
This also shouldn’t be set by the project. It should be set by the user on the cmake command line.