How to detect LLVM and its version through #define directives?

后端 未结 8 1275
广开言路
广开言路 2020-12-24 04:33

The question is quite clear I think. I\'m trying to write a compiler detection header to be able to include in the application information on which compiler was used and whi

相关标签:
8条回答
  • 2020-12-24 05:28

    Snippet from InitPreprocessor.cpp:

      // Compiler version introspection macros.
      DefineBuiltinMacro(Buf, "__llvm__=1");   // LLVM Backend
      DefineBuiltinMacro(Buf, "__clang__=1");  // Clang Frontend
    
      // Currently claim to be compatible with GCC 4.2.1-5621.
      DefineBuiltinMacro(Buf, "__GNUC_MINOR__=2");
      DefineBuiltinMacro(Buf, "__GNUC_PATCHLEVEL__=1");
      DefineBuiltinMacro(Buf, "__GNUC__=4");
      DefineBuiltinMacro(Buf, "__GXX_ABI_VERSION=1002");
      DefineBuiltinMacro(Buf, "__VERSION__=\"4.2.1 Compatible Clang Compiler\"");
    

    I didn't find any way to get the version of llvm and clang itself, though..

    0 讨论(0)
  • 2020-12-24 05:29

    I cannot find an answer here, only links to answers, so for completeness, here is the answer:

    __clang__             // set to 1 if compiler is clang
    __clang_major__       // integer: major marketing version number of clang
    __clang_minor__       // integer: minor marketing version number of clang
    __clang_patchlevel__  // integer: marketing patch level of clang
    __clang_version__     // string: full version number
    

    I get currently:

    __clang__=1
    __clang_major__=3
    __clang_minor__=2
    __clang_patchlevel__=0
    __clang_version__="3.2 (tags/RELEASE_32/final)"
    
    0 讨论(0)
提交回复
热议问题