Skip to content

Commit 1a39ed7

Browse files
committed
Support 64bit MP_DIGIT on Windows under clang-cl
This commit make MP_DIGIT 64 bit when using clang-cl. It also explicitly sets compile flags for clang-cl.
1 parent 839ae9e commit 1a39ed7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,19 @@ endif()
4949

5050
# We only differentiate between MSVC and GCC-compatible compilers
5151
if(MSVC)
52-
set(LTM_C_FLAGS -W3)
52+
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
53+
# We are clang-cl
54+
# Some flags for linux similarity and warnings
55+
set(LTM_C_FLAGS -fstrict-aliasing /W3 /D_CRT_SECURE_NO_WARNINGS)
56+
# Optimization flags
57+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zc:inline /Gw /Gy /clang:-funroll-loops")
58+
# Pass optimization option to override the debug flags, and allow dead code elimination
59+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /clang:-O1" )
60+
# We need to link the runtime for 128 bit int support, which clang-cl has
61+
link_libraries(clang_rt.builtins-x86_64.lib)
62+
else()
63+
set(LTM_C_FLAGS /W3 /D_CRT_SECURE_NO_WARNINGS)
64+
endif()
5365
elseif(WATCOM)
5466
set(LTM_C_FLAGS -fo=.obj -oaxt -3r -w3)
5567
else()
@@ -63,7 +75,7 @@ else()
6375
endif()
6476

6577
# What compiler do we have and what are their...uhm... peculiarities
66-
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
78+
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang" AND NOT MSVC)
6779
list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header)
6880
# Clang requires at least '-O1' for dead code elimination
6981
set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}")
@@ -97,7 +109,7 @@ add_library(${PROJECT_NAME}
97109

98110
target_include_directories(${PROJECT_NAME} PUBLIC
99111
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
100-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
112+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
101113
)
102114

103115
target_compile_options(${PROJECT_NAME} BEFORE PRIVATE

tommath.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" {
1717
#endif
1818

1919
/* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */
20-
#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT)
20+
#if ((defined(_MSC_VER) && !defined(__clang__)) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT)
2121
# define MP_32BIT
2222
#endif
2323

@@ -29,7 +29,7 @@ extern "C" {
2929
defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
3030
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
3131
# if !(defined(MP_64BIT) || defined(MP_32BIT) || defined(MP_16BIT))
32-
# if defined(__GNUC__) && defined(__SIZEOF_INT128__) && !defined(__hppa)
32+
# if defined(__GNUC__) && defined(__SIZEOF_INT128__) && !defined(__hppa) || (defined(_MSC_VER) && defined(__SIZEOF_INT128__))
3333
/* we support 128bit integers only via: __attribute__((mode(TI))) */
3434
# define MP_64BIT
3535
# else

0 commit comments

Comments
 (0)