Skip to content

Commit f751f5d

Browse files
committed
Enable clang-cl support using both ARCH_COMPILER_MSVC and ARCH_COMPILER_CLANG.
1 parent 833d130 commit f751f5d

File tree

12 files changed

+27
-17
lines changed

12 files changed

+27
-17
lines changed

cmake/defaults/clangdefaults.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
# https://openusd.org/license.
66
#
77

8-
include(gccclangshareddefaults)
9-
10-
set(_PXR_CXX_FLAGS "${_PXR_GCC_CLANG_SHARED_CXX_FLAGS}")
8+
if (MSVC)
9+
include(msvcdefaults)
10+
else()
11+
include(gccclangshareddefaults)
12+
set(_PXR_CXX_FLAGS "${_PXR_GCC_CLANG_SHARED_CXX_FLAGS}")
13+
endif()
1114

1215
# Prevent floating point result discrepancies on Apple platforms
1316
# due to multiplication+additions being converted to FMA

pxr/base/arch/attributes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ PXR_NAMESPACE_OPEN_SCOPE
144144
/// [[no_unique_address]] tag.
145145
# define ARCH_EMPTY_BASES
146146

147-
#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
147+
#elif defined(ARCH_COMPILER_GCC) || (defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
148148

149149
# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) \
150150
__attribute__((format(printf, _fmt, _firstArg)))
@@ -241,7 +241,7 @@ struct Arch_ConstructorEntry {
241241
}; \
242242
static void _name()
243243

244-
#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
244+
#elif defined(ARCH_COMPILER_GCC) || (defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
245245

246246
// The used attribute is required to prevent these apparently unused functions
247247
// from being removed by the linker.

pxr/base/arch/debugger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void ArchAbort(bool logging = true);
8383
/// possible, code to prevent optimization so the caller appears in the
8484
/// debugger's stack trace. The calling functions should also use the
8585
/// \c ARCH_NOINLINE function attribute.
86-
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
86+
#if defined(ARCH_COMPILER_GCC) || (defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
8787
#define ARCH_DEBUGGER_TRAP do { ArchDebuggerTrap(); asm(""); } while (0)
8888
#else
8989
#define ARCH_DEBUGGER_TRAP do { ArchDebuggerTrap(); } while (0)

pxr/base/arch/defines.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
#define ARCH_COMPILER_CLANG_MAJOR __clang_major__
6464
#define ARCH_COMPILER_CLANG_MINOR __clang_minor__
6565
#define ARCH_COMPILER_CLANG_PATCHLEVEL __clang_patchlevel__
66+
#if defined(_MSC_VER)
67+
#define ARCH_COMPILER_MSVC
68+
#define ARCH_COMPILER_MSVC_VERSION _MSC_VER
69+
#endif
6670
#elif defined(__GNUC__)
6771
#define ARCH_COMPILER_GCC
6872
#define ARCH_COMPILER_GCC_MAJOR __GNUC__
@@ -95,7 +99,7 @@
9599
// custom versions of macros.
96100
// See here for more detail about MSVC's preprocessors:
97101
// https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview
98-
#if defined(ARCH_COMPILER_MSVC)
102+
#if defined(ARCH_COMPILER_MSVC) && !defined(ARCH_COMPILER_CLANG)
99103
#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
100104
#define ARCH_PREPROCESSOR_MSVC_TRADITIONAL
101105
#endif

pxr/base/arch/demangle.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
using std::string;
1818

1919
#if (ARCH_COMPILER_GCC_MAJOR == 3 && ARCH_COMPILER_GCC_MINOR >= 1) || \
20-
ARCH_COMPILER_GCC_MAJOR > 3 || defined(ARCH_COMPILER_CLANG)
20+
ARCH_COMPILER_GCC_MAJOR > 3 || (defined(ARCH_COMPILER_CLANG) && \
21+
!defined(ARCH_COMPILER_MSVC))
2122
#define _AT_LEAST_GCC_THREE_ONE_OR_CLANG
2223
#endif
2324

pxr/base/arch/export.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@
140140
#include "pxr/base/arch/defines.h"
141141

142142
#if defined(ARCH_OS_WINDOWS)
143-
# if defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR >= 4 || defined(ARCH_COMPILER_CLANG)
143+
# if defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR >= 4 || \
144+
(defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
144145
# define ARCH_EXPORT __attribute__((dllexport))
145146
# define ARCH_IMPORT __attribute__((dllimport))
146147
# define ARCH_HIDDEN

pxr/base/arch/functionLite.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
#define __ARCH_FUNCTION__ __func__
2222

2323
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_ICC) || \
24-
defined(ARCH_COMPILER_CLANG)
24+
(defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
2525
# define __ARCH_PRETTY_FUNCTION__ __PRETTY_FUNCTION__
2626
#elif defined(ARCH_COMPILER_MSVC)
2727
# define __ARCH_PRETTY_FUNCTION__ __FUNCSIG__
2828
#else
2929
# define __ARCH_PRETTY_FUNCTION__ __ARCH_FUNCTION__
3030
#endif /* defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_ICC) ||
31-
defined(ARCH_COMPILER_CLANG)*/
31+
(defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC)) */
3232

3333
#if defined(BUILD_COMPONENT_SRC_PREFIX)
3434
# define __ARCH_FILE__ BUILD_COMPONENT_SRC_PREFIX __FILE__

pxr/base/arch/hints.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/// outcome of bool-expr to a very high degree of certainty. For example,
2020
/// fatal-error cases, invariants, first-time initializations, etc.
2121

22-
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
22+
#if defined(ARCH_COMPILER_GCC) || (defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
2323

2424
#define ARCH_LIKELY(x) (__builtin_expect((bool)(x), true))
2525
#define ARCH_UNLIKELY(x) (__builtin_expect((bool)(x), false))

pxr/base/arch/mallocHook.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ bool
217217
ArchIsStlAllocatorOff()
218218
{
219219
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_ICC) || \
220-
defined(ARCH_COMPILER_CLANG)
220+
(defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC))
221221
// I'm assuming that ICC compiles will use the gcc STL library.
222222

223223
/*

pxr/base/arch/math.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ inline void ArchSinCos(double v, double *s, double *c) {
119119
inline int
120120
ArchCountTrailingZeros(uint64_t x)
121121
{
122-
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG) && \
122+
#if defined(ARCH_COMPILER_GCC) || \
123+
(defined(ARCH_COMPILER_CLANG) && !defined(ARCH_COMPILER_MSVC)) && \
123124
!defined(ARCH_OS_WASM_VM)
124125
return __builtin_ctzl(x);
125126
#elif defined(ARCH_COMPILER_MSVC)

0 commit comments

Comments
 (0)