Compilation with CLANG under Windows

• Aug 24, 2018 - 14:04

With the recent addition of compilation under MSVC, it has also become possible to use CLANG for the compilation under Windows.
Steps
1- Follow the instructions at https://musescore.org/en/handbook/developers-handbook/compilation/compi… up to the point (included) in which dependencies are unpacked in the "dependencies" folder.
2- Install LLVM for Windows 64bit releases.llvm.org/download.html
3- Make sure that LLVM build folder is in the PATH (usually C:\Program Files\LLVM\bin)
4- Install the LLVM Compiler Toolchain Visual Studio extension https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm… (can be done from within Visual Studio)
5- Remove the flag "/permissive-" from CMakeLists.txt (for example here: https://github.com/musescore/MuseScore/blob/e5d59a7c6a2002f5cbef8fde44e… )
[Remember not to commit this change to master for now, if you try this]

Now you can proceed with Visual Studio or by command line.
With Visual Studio:
6- Proceed with the build points left after point 1- up to "Go to msvc.build_x64 and open newly created mscore.sln file" (included)
7- Select all the project inside mscore.sln solution in the Solution Explorer
8- Project -> Properties and set the Platform Toolset to "llvm" (see attached image)
9- Build project "mscore" and then "INSTALL"
10- MuseScore is compiler by clang and installed in "msvc.install_x64/bin" folder

With command line:
6- Launch a Windows command line and make sure that the PATH contains msvc Qt bin folder, LLVM bin folder, CMake bin folder (and git bin folder). Launch
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
as to set the variables for a MSVC compilation.
In alternative, launch "x64 Native Tools Command Prompt for VS 2017" (make sure that the PATH contains the above mentioned folders)
7- Modify "msvc_build.bat" so that when launching cmake the toolset llvm is used. In particular, add flag -T "llvm"
here (before the "..") https://github.com/musescore/MuseScore/blob/e5d59a7c6a2002f5cbef8fde44e…
8- cd to MuseScore directory (and optionally run call msvc_build.bat revision)
9- Execute the follwing command to compile (for e.g. a release build; see the instructions at the beginning of msvc_build.bat for other kind of builds)
call msvc_build.bat release
10- To install:
cd ..
call msvc_build.bat install

[Remember not to commit the modification to msvc_build.bat nor the optional modification to revision.h]
11- MuseScore, compiled by clang, is installed in "msvc.install_x64/bin" folder

The compilation in these cases is done with clang-cl, which accepts (most of) the compilation flags of MSVC cl compiler. One of the differences is for example the ability to use variable-length arrays, which at the moment are special cased inside MuseScore code for MSVC.

Ciao,
ABL

Attachment Size
MSVC_target.png 59.21 KB

Comments

Awesome! Do I understand correctly that clang builds MuseScore.exe with all Windows specific dll dependencies?
If it is true, I would propose using clang as a priority generator for MuseScore on Windows. The reason is unifying build results between Mac and Windows code.
For now, there is still popping noise in 64-bit build of MuseScore. Does it exist on Mac with the score from https://musescore.org/en/node/275544?

In reply to by Anatoly-os

Yes, the dlls are the same as those used with MSVC (QwebEngine included).
Clang-cl creates code which can interoperate with MSVC code, so different parts of the project could even be compiled with different compilers (MSVC and clang) and still be able to be linked together. At the moment this patched build chain is still using MSVC linker (link.exe) to link the executables, and Microsoft C++ libraries from the SDK (the those against which MSVC is linking too).
I think compilation with clang should be still tested, but it could be a promising way.
It outputs a lot more warnings than MSVC is doing at the moment (but most of them are on the same line of MSVC ones).

Do you still have an unanswered question? Please log in first to post your question.