microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.48k stars 393 forks source link

Compilation issues with clang #36

Closed walbourn closed 6 years ago

walbourn commented 6 years ago

DirectX Tool Kit won't build with clang, primarily because it relies on the XMVECTOR operator overloads

Note that DirectX Tool Kit assumes you are using C++14, so you should use -std=c++14 with clang along with the newer releases of DirectXMath (3.12 or later)

walbourn commented 6 years ago

Last year I updated DirectXMath to compile with clang. One of the issues I encountered is that clang does not define __m128 as a struct the way Visual C++ and the Intel compiler do. Instead it's defined as an opaque type. Because of C++ rules you're not able to overload just on the type. Therefore I added logic to remove those overloads when building with clang. I explain this in detail in this blog post

walbourn commented 6 years ago

If you want a 'clean' build with clang, you need to turn off a bunch of warnings:

#ifdef __clang__
#pragma clang diagnostic ignored "-Wc++98-compat"
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#pragma clang diagnostic ignored "-Wc++98-compat-local-type-template-args"
#pragma clang diagnostic ignored "-Wcast-align"
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#pragma clang diagnostic ignored "-Wfloat-equal"
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
#pragma clang diagnostic ignored "-Wlanguage-extension-token"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
#pragma clang diagnostic ignored "-Wnested-anon-types"
#pragma clang diagnostic ignored "-Wnonportable-include-path"
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#pragma clang diagnostic ignored "-Wshadow-field-in-constructor"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wswitch-enum"
#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
#pragma clang diagnostic ignored "-Wunused-const-variable"
#endif
walbourn commented 6 years ago

The DirectXMath issues are fixed in this pull request along with clang x86 issues with InitOnceExecuteOnce.