Skip to content

Commit 83c6b2d

Browse files
authored
Support msvc build CMake (#233)
1 parent 3cc3bae commit 83c6b2d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,19 @@ if(WIN32)
5454
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
5555
endif()
5656

57-
set(CLICE_CXX_FLAGS "-fno-rtti;-fno-exceptions;-Wno-deprecated-declarations;-Wno-undefined-inline;")
57+
if (MSVC)
58+
# Remove any RTTI or exception enabling flags from CMAKE_CXX_FLAGS
59+
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
60+
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
61+
62+
# Fix MSVC Non-standard preprocessor caused error C1189
63+
# While compiling Command.cpp, MSVC won't expand Options macro correctly
64+
# Output: D:\Desktop\code\clice\build\.packages\l\llvm\20.1.5\cc2aa9f1d09a4b71b6fa3bf0011f6387\include\clang/Driver/Options.inc(3590): error C2365: “clang::driver::options::OPT_”: redefinition; previous definition was 'enumerator'
65+
set(CLICE_CXX_FLAGS "/GR-;/EHsc-;/Zc:preprocessor;")
66+
else()
67+
set(CLICE_CXX_FLAGS "-fno-rtti;-fno-exceptions;-Wno-deprecated-declarations;-Wno-undefined-inline;")
68+
endif()
69+
5870
set(CLICE_LINKER_FLAGS "")
5971

6072
if(CLICE_USE_LIBCXX)
@@ -68,9 +80,12 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
6880
list(APPEND CLICE_CXX_FLAGS "-g;-O0;-fsanitize=address")
6981
list(APPEND CLICE_LINKER_FLAGS "-fsanitize=address")
7082
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
71-
message(STATUS "RelWithDebInfo build: Enabling -fsanitize=thread")
72-
list(APPEND CLICE_CXX_FLAGS "-fsanitize=thread")
73-
list(APPEND CLICE_LINKER_FLAGS "-fsanitize=thread")
83+
if(NOT MSVC)
84+
# MSVC only supports ASAN
85+
message(STATUS "RelWithDebInfo build: Enabling -fsanitize=thread")
86+
list(APPEND CLICE_CXX_FLAGS "-fsanitize=thread")
87+
list(APPEND CLICE_LINKER_FLAGS "-fsanitize=thread")
88+
endif()
7489
else()
7590
message(STATUS "Release/Default build: Enabling -O3")
7691
list(APPEND CLICE_CXX_FLAGS "-O3")

cmake/llvm_setup.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function(install_prebuilt_llvm llvm_ver)
123123
# Determine platform-specific package name
124124
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
125125
set(LLVM_BUILD_TYPE "debug")
126-
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
126+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
127127
set(LLVM_BUILD_TYPE "release")
128128
else()
129129
set(LLVM_BUILD_TYPE "release-lto")

0 commit comments

Comments
 (0)