我有一个使用CMake构建的C项目.我通常在OSX上构建,但现在我正在尝试使用 Windows版本.出于兼容性原因,我想在Windows上使用Clang. 我从LLVM安装了预编译的Clang 3.8二进制文件: C:\Program Files\
我从LLVM安装了预编译的Clang 3.8二进制文件:
C:\Program Files\LLVM\bin\clang.exe C:\Program Files\LLVM\bin\clang++.exe
它也安装在我的PATH上:
>clang++ clang++.exe: error: no input files
我有两个问题:
>当我打电话给cmake –build时,如何告诉CMake使用clang?
>如何在构建CMake配置的编译器之前检查?
最新的CMake 3.6版本在Windows上有几个集成支持的Clang构建环境(例如Visual Studio,Cygwin;见Release Notes).
我刚刚用一个成功的测试
> LLVM-3.9.0-r273898-win32.exe从http://llvm.org/builds/
> cmake-3.6.0-rc4-win64-x64.msi从https://cmake.org/download/
> Microsoft VS2015 Community Edition版本14.0.23107.0
全部安装到其标准路径,其bin目录位于全局PATH环境中.
您需要知道的部分是使用CMake -T“LLVM-vs2014”命令行选项设置正确的工具集.在配置过程中,CMake会告诉您它找到/采用的编译器.
的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控制台
...> 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!
安装提示
请注意,我在设置过程中已将LLVM添加到搜索路径中:
您可以在任何VS项目的属性页面中交叉检查可用的“平台工具集”:
参考
> What is the -D define to tell Cmake where to find nmake?
> Linker for Clang?
> Switching between GCC and Clang/LLVM using CMake