<legend id='K9m6R'><style id='K9m6R'><dir id='K9m6R'><q id='K9m6R'></q></dir></style></legend>
<i id='K9m6R'><tr id='K9m6R'><dt id='K9m6R'><q id='K9m6R'><span id='K9m6R'><b id='K9m6R'><form id='K9m6R'><ins id='K9m6R'></ins><ul id='K9m6R'></ul><sub id='K9m6R'></sub></form><legend id='K9m6R'></legend><bdo id='K9m6R'><pre id='K9m6R'><center id='K9m6R'></center></pre></bdo></b><th id='K9m6R'></th></span></q></dt></tr></i><div id='K9m6R'><tfoot id='K9m6R'></tfoot><dl id='K9m6R'><fieldset id='K9m6R'></fieldset></dl></div>

      • <bdo id='K9m6R'></bdo><ul id='K9m6R'></ul>
      <tfoot id='K9m6R'></tfoot>

      <small id='K9m6R'></small><noframes id='K9m6R'>

        在 CMake 中,如何测试编译器是否为 Clang?

        时间:2023-08-28
          <tbody id='tl7Lk'></tbody>

      1. <tfoot id='tl7Lk'></tfoot>

        <small id='tl7Lk'></small><noframes id='tl7Lk'>

          <legend id='tl7Lk'><style id='tl7Lk'><dir id='tl7Lk'><q id='tl7Lk'></q></dir></style></legend>
            <bdo id='tl7Lk'></bdo><ul id='tl7Lk'></ul>

              <i id='tl7Lk'><tr id='tl7Lk'><dt id='tl7Lk'><q id='tl7Lk'><span id='tl7Lk'><b id='tl7Lk'><form id='tl7Lk'><ins id='tl7Lk'></ins><ul id='tl7Lk'></ul><sub id='tl7Lk'></sub></form><legend id='tl7Lk'></legend><bdo id='tl7Lk'><pre id='tl7Lk'><center id='tl7Lk'></center></pre></bdo></b><th id='tl7Lk'></th></span></q></dt></tr></i><div id='tl7Lk'><tfoot id='tl7Lk'></tfoot><dl id='tl7Lk'><fieldset id='tl7Lk'></fieldset></dl></div>

                  本文介绍了在 CMake 中,如何测试编译器是否为 Clang?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们有一套跨平台CMake 构建脚本,我们支持使用 Visual C++ 和 GCC.

                  We have a set of cross-platform CMake build scripts, and we support building with Visual C++ and GCC.

                  我们正在尝试 Clang,但我不知道如何测试编译器是带有我们 CMake 脚本的 Clang.

                  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.

                  我应该测试什么来查看编译器是否是 Clang?我们目前正在使用 MSVCCMAKE_COMPILER_IS_GNU 分别测试 Visual C++ 和 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 Visual C++ and GCC, respectively.

                  推荐答案

                  一个可靠的检查是使用 CMAKE__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 开始,Apple 提供的 Clang 的 CMAKE__COMPILER_ID 值现在是 AppleClang.要同时测试 Apple 提供的 Clang 和常规 Clang,请使用以下 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 3.15 增加了对 clang-cl 和常规的 clang 前端.您可以通过检查变量 CMAKE_CXX_COMPILER_FRONTEND_VARIANT 来确定前端变体:

                  CMake 3.15 has added support for both the clang-cl and the regular clang front end. You can determine the front end variant by inspecting the variable CMAKE_CXX_COMPILER_FRONTEND_VARIANT:

                  if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
                    if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
                      # using clang with clang-cl front end
                    elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
                      # using clang with regular front end
                    endif()
                  endif()
                  

                  这篇关于在 CMake 中,如何测试编译器是否为 Clang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:CMake 无法确定目标的链接器语言 下一篇:使用 CMake 生成 Visual Studio C++ 项目文件

                  相关文章

                  <i id='qy4LY'><tr id='qy4LY'><dt id='qy4LY'><q id='qy4LY'><span id='qy4LY'><b id='qy4LY'><form id='qy4LY'><ins id='qy4LY'></ins><ul id='qy4LY'></ul><sub id='qy4LY'></sub></form><legend id='qy4LY'></legend><bdo id='qy4LY'><pre id='qy4LY'><center id='qy4LY'></center></pre></bdo></b><th id='qy4LY'></th></span></q></dt></tr></i><div id='qy4LY'><tfoot id='qy4LY'></tfoot><dl id='qy4LY'><fieldset id='qy4LY'></fieldset></dl></div>
                1. <legend id='qy4LY'><style id='qy4LY'><dir id='qy4LY'><q id='qy4LY'></q></dir></style></legend>

                  • <bdo id='qy4LY'></bdo><ul id='qy4LY'></ul>
                  1. <tfoot id='qy4LY'></tfoot>

                  2. <small id='qy4LY'></small><noframes id='qy4LY'>