build llvm fails under win7 x64/VS2017

my build environment:

Win7 x64
VStudio 2017 Community Edition 15.8.4 (latest)
CMake 3.12.1 (x86)
git 2.19.0 (latest, x64)
Python 2.7.2 (x86)

my build steps:

open VS2017 x64 developer command prompt
cd D:\projects\fun\jit_tests
mkdir llvm
cd llvm
git clone https://github.com/llvm-mirror/llvm
mkdir llvm-build
cd llvm-build
cmake -G "Visual Studio 15 2017 Win64" -DBUILD_SHARED_LIBS=ON -DLLVM_TARGETS_TO_BUILD=host -DLLVM_ENABLE_WARNINGS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF ../llvm
cmake --build .

produces these errors and warnings while building

CMake Warning at CMakeLists.txt:29 (message):
 Visual Studio generators use the x86 host compiler by default, even for
 64-bit targets. This can result in linker instability and out of memory
 errors. To use the 64-bit host compiler, pass -Thost=x64 on the CMake
 command line.
...
CMake Warning (dev) at utils/benchmark/CMakeLists.txt:3 (project):
 Policy CMP0048 is not set: project() command manages VERSION variables.
 Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy
 command to set the policy and suppress this warning.
-----> seems related to https://bugs.llvm.org/show_bug.cgi?id=38874
...
CMake Warning at utils/benchmark/CMakeLists.txt:234 (message):
 Using std::regex with exceptions disabled is not fully supported

and later some linker errors

LINK : fatal error LNK1104: cannot open file '..\..\Debug\lib\LLVMDemangle.lib' [D:\projects\fun\jit_tests\llvm40\llvm40-build\lib\Support\LLVMSupport.vcxproj]
...
LINK : fatal error LNK1104: cannot open file '..\..\..\lib\Debug\benchmark.lib' [D:\projects\fun\jit_tests\llvm40\llvm40-build\utils\benchmark\src\benchmark_main.vcxproj]
...
LINK : fatal error LNK1104: cannot open file '..\..\Debug\lib\LLVMDemangle.lib' [D:\projects\fun\jit_tests\llvm40\llvm40-build\lib\Support\LLVMSupport.vcxproj]
...
LINK : fatal error LNK1104: cannot open file '..\..\..\lib\Debug\benchmark.lib' [D:\projects\fun\jit_tests\llvm40\llvm40-build\utils\benchmark\src\benchmark_main.vcxproj]

i also tried to build LLVM 4 and 6 on a clean cloned version
git checkout -b release_40
git checkout -b release_60

producing the very same warnings/errors and the build breaks

in the end i've got 1 lib and 2 dlls - not what i've expected :slight_smile:

any ideas?

i've read the following on https://llvm.org/docs/CMake.html
....
BUILD_SHARED_LIBS is only recommended for use by LLVM developers.
If you want to build LLVM as a shared library, you should use the LLVM_BUILD_LLVM_DYLIB option.
....

replacing BUILD_SHARED_LIBS with LLVM_LINK_LLVM_DYLIB fixed my build problems

my new build-config:

cmake -Thost=x64 -G "Visual Studio 15 2017 Win64" -DLLVM_TARGETS_TO_BUILD=host -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_TOOLS=OFF -DLLVM_BUILD_LLVM_DYLIB=ON ../llvm

using BUILD_SHARED_LIBS with this config fails very early - is that intended behavior or a config bug?

the next thing i try is to use Ninja on my Win7x64/VS2017 - hope that reduces the build-times (currently 1.5h for an full static build - but im using an old pc)

BUILD_SHARED_LIBS is definitely not supported with MSVC. I’m not even confident that LLVM_BUILD_LLVM_DYLIB will work well, despite various people’s attempts to make it work. I would recommend static linking first, and then move on to the much harder problem of building a DLL that exports what you want.

BUILD_SHARED_LIBS is definitely not supported with MSVC. I'm not even
confident that LLVM_BUILD_LLVM_DYLIB

both does not work for me

BUILD_SHARED_LIBS breaks the build very early, few seconds after build start

LLVM_BUILD_LLVM_DYLIB comes up with "Not Supported" after waiting a long long time for the build to finish

i will stay with the static build

thx