在cmake的,我怎么能测试,如果编译器是锵? [英] In cmake, how can I test if the compiler is Clang?

查看:202
本文介绍了在cmake的,我怎么能测试,如果编译器是锵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一套跨平台CMake的构建脚本,我们支持与 MSVC 并的GCC

We have a set of cross platform CMake build scripts, and we support building with MSVC and GCC.

我们正在尝试,但我无法弄清楚如何测试编译器是否锵我们CMake的脚本。

We're trying out Clang, but I can't figure out how to test whether or not the compiler is Clang with our CMake script.

我应该测试,看看是否编译器锵与否?目前,我们正在使用 MSVC 和<一个href=\"http://www.cmake.org/cmake/help/v2.8.8/cmake.html#variable%3aCMAKE_COMPILER_IS_GNULANG\"><$c$c>CMAKE_COMPILER_IS_GNU<LANG>测试分别MSVC和GCC。

What should I test to see if the compiler is Clang or not? We're currently using MSVC and CMAKE_COMPILER_IS_GNU<LANG> to test for MSVC and GCC, respectively.

推荐答案

一个可靠的检查方法是使用 CMAKE_&LT;&LANG GT; _COMPILER_ID 变量。例如,检查C ++编译器:

A reliable check is to use the CMAKE_<LANG>_COMPILER_ID variables. E.g., to check the C++ compiler:

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  # using Clang
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  # using GCC
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
  # using Intel C++
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  # using Visual Studio C++
endif()

如果使用编译器的包装如的ccache 这些也正常工作。

These also work correctly if a compiler wrapper like ccache is used.

随着CMake的3.0.0的 CMAKE_&LT; LANG&GT;对于苹果提供锵_COMPILER_ID 值现在是 AppleClang 。为了测试Apple提供锵和普通锵都使用以下if条件:

As of CMake 3.0.0 the CMAKE_<LANG>_COMPILER_ID value for Apple-provided Clang is now AppleClang. To test for both the Apple-provided Clang and the regular Clang use the following if condition:

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  # using regular Clang or AppleClang
endif()

另请参阅 AppleClang政策说明

这篇关于在cmake的,我怎么能测试,如果编译器是锵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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