Development/clang-cl

LibreOffice is currently built on Windows using the MSVC compiler, but it's possible to also build it using the Clang clang-cl wrapper.

Setup
Clang should be already installed together with MS Visual Studio, and so it should be possible to build by adding something like the following to the end of autogen.input: CC=C:/PROGRA~2/MICROS~3/2019/COMMUN~1/VC/Tools/Llvm/bin/clang-cl.exe -m64 CXX=C:/PROGRA~2/MICROS~3/2019/COMMUN~1/VC/Tools/Llvm/bin/clang-cl.exe -m64 CXX_X86_BINARY=C:/PROGRA~2/MICROS~3/2019/COMMUN~1/VC/Tools/Llvm/bin/clang-cl.exe -m32

The path is the location of the clang-cl.exe binary (located e.g. at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe for MSVC 2019) converted using cygpath -m -s . It is also usually necessary to specify -m32/-m64 for 32bit or 64bit compilers, for building on a 64bit platform the way as described, for building on a 32bit platform all should use -m32.

For building with precompiled headers (PCH), at least Clang 13.0 is necessary, otherwise build will later fail. As of December 2021, the Clang shipped with MSVC is too old, so it's necessary to either use --disable-pch, or to download and install LLVM/Clang and use that instead.

Currently neither Clang provided by MS Visual Studio nor Clang provided by LLVM allow building Clang plugins. This and the warning about it can be ignored (possibly explicitly by using --disable-compiler-plugins), otherwise Clang needs to be built from source.

Building Clang from source
Unless also Clang compiler plugins are wanted, this is not necessary. If unsure, use Clang binaries.


 * Install needed tools to build clang:
 * Install MSVC 12.0 or 14.0
 * Install cmake 3.5.0-rc3 from here
 * Install python 3.5.1 from here
 * Install Ninja 1.6 from here
 * Add all of the above to your path
 * Set up clang tree (note the patch instructions below):
 * Start MSVC shell ("VS2015 x64 Native Tools Command Prompt")
 * cd 
 * mkdir clang
 * git clone https://git.llvm.org/git/llvm.git
 * cd llvm
 * cd tools
 * git clone https://git.llvm.org/git/clang.git
 * cd ..\projects
 * git clone https://git.llvm.org/git/compiler-rt.git
 * cd ..\..
 * mkdir llvm-objdir
 * cd llvm-objdir
 * cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 ..\llvm
 * ninja
 * find the fresh built clang-cl executable in

Set up LibreOffice build
This section is(?) obsolete. Current master version of LibreOffice should build using only setting flags as described above. This section may be perhaps useful if building older versions.


 * Recent LibreOffice master repo (known working: &ldquo;Work around -Werror,-Wunused-macros with clang-cl&rdquo;)
 * Patches that were needed in the past:
 * (&ldquo;TODO: work around clang-cl ABI bug PR25641&rdquo; to work around &rdquo;clang-cl: vtordisp thunks not emitted for functions with class template specializations in their signatures&rdquo; until there is a fix for that bug; merged for now as )
 * In autogen.input (using whatever  matches your installed compiler version, see documentation of   at ):
 * Only tested with
 * There is an issue with  at least from Windows SDK 10.0.10240, see, which is known to be solved at least with Windows SDK 10.0.15063.137 available from.
 * Only tested with
 * There is an issue with  at least from Windows SDK 10.0.10240, see, which is known to be solved at least with Windows SDK 10.0.15063.137 available from.
 * Only tested with
 * There is an issue with  at least from Windows SDK 10.0.10240, see, which is known to be solved at least with Windows SDK 10.0.15063.137 available from.

Future Work
Investigate whether clang-cl works on Windows Subsystem for Linux, aka "Windows Bash".