Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a C++ project that builds using CMake. I usually build on OSX but now I am trying to get a Windows version working too. I would like to use Clang on Windows for compatibility reasons.

I installed the pre-compiled Clang 3.8 binary from LLVM:

C:Program FilesLLVMinclang.exe
C:Program FilesLLVMinclang++.exe

It is also installed on my PATH:

>clang++
clang++.exe: error: no input files

I have two questions:

  1. How do I tell CMake to use clang++ when I call cmake --build?
  2. How can I check before building which compiler CMake is configured with?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
356 views
Welcome To Ask or Share your Answers For Others

1 Answer

You also need - in addition to the Clang compilers itself - an build/link environment for Windows.

The latest CMake 3.6 builds do have several integrated supported Clang build environments on Windows (e.g. Visual Studio, Cygwin; see Release Notes).

I've just run a successful test with

All installed to their standard paths with their bin directories in the global PATH environment.

The part you need to know is setting the right toolset with the CMake -T"LLVM-vs2014" command line option. During the configuration process CMake will let you know which compiler it has found/taken.

CMakeLists.txt

cmake_minimum_required(VERSION 3.6)

project(HelloWorld)

file(
    WRITE main.cpp 
        "#include <iostream>
"
        "int main() { std::cout << "Hello World!" << std::endl; return 0; }"
)
add_executable(${PROJECT_NAME} main.cpp)

Windows Console

...> mkdir VS2015
...> cd VS2015
...VS2015> cmake -G"Visual Studio 14 2015" -T"LLVM-vs2014" ..
-- The C compiler identification is Clang 3.9.0
-- The CXX compiler identification is Clang 3.9.0
-- Check for working C compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/LLVM/msbuild-bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: .../VS2015
...VS2015> cmake --build . 
Microsoft (R)-Buildmodul, Version 14.0.23107.0
[...]
...VS2015> DebugHelloWorld.exe
Hello World!

Installation Hints

Please note that I have added LLVM to my search paths during setup:

LLVM Installation with Add to PATH

And you can crosscheck the available "Platform Toolsets" in any VS project's property page:

VS Project Properties - Platform Toolsets

References


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...