Build libclang on Windows: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(libclang builds configuration)
 
Line 14: Line 14:


=== Intel Compiler ===
=== Intel Compiler ===
Currently llvm requires some tweaks to compile with icl (mostly inline namespaces from windows headers and binary ops with enums). After llvm and windows headers tweaks it compiles but performance is similar to msvc version so there's not much profit in icl builds currently.
Currently llvm requires some tweaks to compile with icl (mostly inline namespaces from windows headers and binary ops with enums). After you apply tweaks for llvm and windows headers it compiles but performance is similar to msvc version so there's not much profit in icl builds currently.


== Build ==
== Build ==
In creator and command like you can just use "jom install" or use default step from Qt Creator
In creator and command line you can just use "jom install" or use default step from Qt Creator


== Profile-guided builds extra configuration ==
== Profile-guided builds extra configuration ==
Line 23: Line 23:
=== MSVC ===
=== MSVC ===
  * First build round:
  * First build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: /GL
<nowiki> </nowiki> CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: /GL
  CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS: /LTCG and /GENPROFILE:PGD=pgd\files\path
<nowiki> </nowiki> CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS: /LTCG and /GENPROFILE:PGD=pgd\files\path
  * Training
  <nowiki>*</nowiki> Training
  Just run parsing/completion
<nowiki> </nowiki> Just run parsing/completion
  * Second build round:
  <nowiki>*</nowiki> Second build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: /GL
<nowiki> </nowiki> CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: /GL
  CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS: /LTCG and /USEPROFILE:PGD=same\pgd\files\path
<nowiki> </nowiki> CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS: /LTCG and /USEPROFILE:PGD=same\pgd\files\path


=== MinGW ===
=== MinGW ===
  * First build round:
  * First build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: -fprofile-generate=path\to\profile\files
<nowiki> </nowiki> CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: -fprofile-generate=path\to\profile\files
  * Training
  <nowiki>*</nowiki> Training
  Just run parsing/completion
<nowiki> </nowiki> Just run parsing/completion
  * Second build round:
  <nowiki>*</nowiki> Second build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: -fprofile-use=path\to\profile\files
<nowiki> </nowiki> CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: -fprofile-use=path\to\profile\files


=== Clang ===
=== Clang ===
Line 45: Line 45:


  * First build round:
  * First build round:
  cmake -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-generate=path\llvm-%p.profraw" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-generate=path\llvm-%p.profraw" -DMSVC=1 -DCMAKE_CL_64=<1|0> -DCMAKE_EXE_LINKER_FLAGS="<path\to\llvm\install>\lib\clang\5.0.0\lib\windows\clang_rt.profile-x86_64.lib /FORCE:MULTIPLE" path\to\llvm
<nowiki> </nowiki> cmake -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-generate=path\llvm-%p.profraw" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-generate=path\llvm-%p.profraw" -DMSVC=1 -DCMAKE_CL_64=<1|0> -DCMAKE_EXE_LINKER_FLAGS="<path\to\llvm\install>\lib\clang\5.0.0\lib\windows\clang_rt.profile-x86_64.lib /FORCE:MULTIPLE" path\to\llvm
  * Training
  <nowiki>*</nowiki> Training
  * Merging train data
  <nowiki>*</nowiki> Merging train data
  llvm-profdata merge -output= llvm.profdata llvm-*.profraw
<nowiki> </nowiki> llvm-profdata merge -output= llvm.profdata llvm-*.profraw
  * Second build round:
  <nowiki>*</nowiki> Second build round:
  cmake -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-use=path\llvm.prodata" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-use=path\llvm.prodata" -DMSVC=1 -DCMAKE_CL_64=<1|0> path\to\llvm
<nowiki> </nowiki> cmake -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-use=path\llvm.prodata" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-use=path\llvm.prodata" -DMSVC=1 -DCMAKE_CL_64=<1|0> path\to\llvm

Revision as of 14:44, 28 September 2017

Configuring builds

MSVC (2015 and 2017) and MinGW

Can be configured with Qt Creator. It's enough to manually set CMAKE_INSTALL_PREFIX, CMAKE_BUILD_TYPE and LLVM_ENABLE_RTTI

For MinGW there are extra flags though to link libraries into libclang.dll statically (CMAKE_C_FLAGS and CMAKE_CXX_FLAGS): -static-libgcc -static-libstdc++ -static

Clang

Configurable with cmake: You need msvc command line and append PATH with bin directory of clang (set PATH=%PATH%;path\to\clang\bin)

cmake -G <Generator ("NMake Makefiles JOM" or "NMake Makefiles")> -DCMAKE_BUILD_TYPE=<Release|Debug> -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0" -DMSVC=1 -DCMAKE_CL_64=<1|0> path\to\llvm

Intel Compiler

Currently llvm requires some tweaks to compile with icl (mostly inline namespaces from windows headers and binary ops with enums). After you apply tweaks for llvm and windows headers it compiles but performance is similar to msvc version so there's not much profit in icl builds currently.

Build

In creator and command line you can just use "jom install" or use default step from Qt Creator

Profile-guided builds extra configuration

MSVC

* First build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: /GL
  CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS: /LTCG and /GENPROFILE:PGD=pgd\files\path
* Training
  Just run parsing/completion
* Second build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: /GL
  CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS: /LTCG and /USEPROFILE:PGD=same\pgd\files\path

MinGW

* First build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: -fprofile-generate=path\to\profile\files
* Training
  Just run parsing/completion
* Second build round:
  CMAKE_C_FLAGS and CMAKE_CXX_FLAGS: -fprofile-use=path\to\profile\files

Clang

Clang requires compiler-rt to build llvm with -fprofile-instr-generate flag Follow the https://compiler-rt.llvm.org/ to build it. You need additional configuration though: -DCMAKE_INSTALL_PREFIX=<path\to\llvm\install>\lib\clang\5.0.0 and a proper -DCMAKE_BUILD_TYPE

* First build round:
  cmake -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-generate=path\llvm-%p.profraw" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-generate=path\llvm-%p.profraw" -DMSVC=1 -DCMAKE_CL_64=<1|0> -DCMAKE_EXE_LINKER_FLAGS="<path\to\llvm\install>\lib\clang\5.0.0\lib\windows\clang_rt.profile-x86_64.lib /FORCE:MULTIPLE" path\to\llvm
* Training
* Merging train data
  llvm-profdata merge -output= llvm.profdata llvm-*.profraw
* Second build round:
  cmake -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=path\to\install -DCMAKE_C_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-use=path\llvm.prodata" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.0 -fprofile-instr-use=path\llvm.prodata" -DMSVC=1 -DCMAKE_CL_64=<1|0> path\to\llvm