Clion nmake versus MSVC
Hi,
I am trying to use CLION to build a project that I used to build using MSVC.
When using the Visual Studio toolchain inside CLION with the auto-detected path to tools I found the build rather slow compare to the MSVC build.
Inside Clion, the default auto-detected Make executable for the Visual Studio toolchain (Microsoft Visual Studio Community 2019 (version 16.8.3) ) is nmake ( located by default at: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x64\nmake.exe ).
I understand that nmake doesn't accept parallelization ( "-j" option can't be set).
I have read that "Note that msbuild is not supported: CLion runs CMake with the NMAKE generator instead."
So my questions are, is the msbuild used internally by Visual Studio when building, is this why it building much faster (I suppose msbuild is doing parallelization).
I found this blog post CLion 2019.3 EAP: Ninja or Another Generator of Your Choice in CMake | JetBrains Blog
with this statement that correspond to my issue but can't understand what is the solution:
- With the Visual Studio toolchain, CLion was using something very similar to Makefiles – NMake, but the community expected Visual Studio CMake generators (CPP-14730).
I tried adding the ninja generator (-G Ninja) then the build is 10x faster. But I would like to be sure that by using Clion + Ninja generator I end up with "the same" result as the one obtained by using Visual Studio in the first place.
I tried also the Visual Studio generator:
-G "Visual Studio 16 2019" -A x64
it is faster than nmake too, but is the result identical to running from inside Visual Studio?
Why do the Visual studio toolchain Clion default settings doesn't prompt you which generator of Visual Studio you want to use?
One more thing, when using the "Command Prompt" with cmake (without any Generator flag) the parallelization seems to be working by default.
How could I know which make is in use when invoking cmake from command prompt?
Cheers,
DrX
请先登录再写评论。
I found the answer, when calling cmake from windows command prompt the default generator is inherited from your registry and if you have a version of Visual Studio it will be setup by default. Otherwise it will be the nmake default fallback solution.
If you specify via the -G generatorName then the default behaviour will be replaced by the specified generatorName.
You can add a debug line in the beginning of your CMakeLists.txt and check what does it gives you:
message("Current Generator is \"${CMAKE_GENERATOR}\"")Please JetBrains team at least when using the Visual Studio Toolchain could you implement the same parsing of the registry as the cmake does to offer the list of available auto-detected generators, since command prompt is behaving differently that calling cmake from Clion this is confusing.
c - What is the default generator for CMake in Windows? - Stack Overflow
Cheers,
DrX
In CLion you can set up any CMake generator available for your platform (https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).
When there was no possibility to switch generator in CLion, CodeBlocks was the only generator which could be used. And it was made a default generator when this possibility appeared.