如何告诉CMake在Windows上使用Clang? [英] How do I tell CMake to use Clang on Windows?

查看:1547
本文介绍了如何告诉CMake在Windows上使用Clang?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++项目,使用CMake构建。我通常建立在OSX,但现在我试图得到一个Windows版本工作。出于兼容性原因,我想在Windows上使用Clang。



我安装了来自LLVM的预编译的Clang 3.8二进制文件:

  C:\Program Files\LLVM\bin\clang.exe 
C:\Program Files\LLVM\bin\clang ++。exe



它也安装在我的路径:

  > clang ++ 
clang ++。exe:错误:无输入文件


  1. 当我调用<$ c $时,如何告诉CMake使用 clang ++ c> cmake --build ?

  2. 如何在构建哪个编译器CMake之前检查?


解决方案

除了Clang编译器本身,你还需要一个用于Windows的构建/链接环境。



最新的CMake 3.6版本在Windows上有几个集成的支持Clang构建环境(例如Visual Studio,Cygwin;参见版本说明)。



我刚刚使用

运行成功的测试


  • LLVM-3.9.0-r273898-win32.exe from http://llvm.org/builds/

  • cmake-3.6.0-rc4-win64-x64.msi https://cmake.org/download/

  • Microsoft VS2015 Community Edition版本14.0.23107.0



    • 全部安装到全局 PATH bin $ c>环境。



      您需要知道的部分是使用CMake -TLLVM-vs2014 命令行选项。在配置过程中,CMake会让你知道它找到/采取了哪个编译器。



      CMakeLists.txt

        cmake_minimum_required(VERSION 3.6)

      项目(HelloWorld)

      文件(
      WRITE main。 cpp
      #include< iostream> \\\

      int main(){std :: cout<< \Hello World!\< std :: endl; return 0;}

      add_executable($ {PROJECT_NAME} main.cpp)

      Windows控制台

        ...& mkdir VS2015 
      ...> cd VS2015
      ... \VS2015> cmake -GVisual Studio 14 2015-TLLVM-vs2014..
      - C编译器标识是Clang 3.9.0
      - CXX编译器标识是Clang 3.9.0
      - 检查工作C编译器:C:/ Program Files(x86)/LLVM/msbuild-bin/cl.exe
      - 检查工作C编译器:C:/ Program Files(x86)/ LLVM /msbuild-bin/cl.exe - works
      - 检测C编译器ABI信息
      - 检测C编译器ABI信息 - 完成
      - 检查是否工作CXX编译器:C:程序文件(x86)/LLVM/msbuild-bin/cl.exe
      - 检查是否工作CXX编译器:C:/ Program Files(x86)/LLVM/msbuild-bin/cl.exe - works
      - 检测CXX编译器ABI info
      - 检测CXX编译器ABI信息 - done
      - 检测CXX编译特性
      - 检测CXX编译特性 - 完成
      - 配置done
      - 生成done
      - 生成文件已写入:... / VS2015
      ... \VS2015> cmake --build。
      Microsoft(R)-Buildmodul,版本14.0.23107.0
      [...]
      ... \VS2015> Debug \HelloWorld.exe
      Hello World!

      参考




      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 Files\LLVM\bin\clang.exe
      C:\Program Files\LLVM\bin\clang++.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?

      解决方案

      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>\n"
              "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> Debug\HelloWorld.exe
      Hello World!
      

      References

      这篇关于如何告诉CMake在Windows上使用Clang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆