Skip to content

Commit 25722bb

Browse files
authored
Merge pull request #7632 from hughbe/msvc-specific
2 parents f116f5f + 9f9da4b commit 25722bb

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,33 @@ function(_add_variant_c_compile_flags)
205205
endif()
206206

207207
if("${CFLAGS_SDK}" STREQUAL "WINDOWS")
208-
list(APPEND result -Xclang;--dependent-lib=oldnames)
209-
# TODO(compnerd) handle /MT, /MTd, /MD, /MDd
210-
if("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
211-
list(APPEND result "-D_MD")
212-
list(APPEND result -Xclang;--dependent-lib=msvcrt)
213-
else()
214-
list(APPEND result "-D_MDd")
215-
list(APPEND result -Xclang;--dependent-lib=msvcrtd)
208+
# MSVC doesn't support -Xclang. We don't need to manually specify
209+
# -D_MD or D_MDd either, as CMake does this automatically.
210+
if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
211+
list(APPEND result -Xclang;--dependent-lib=oldnames)
212+
# TODO(compnerd) handle /MT, /MTd, /MD, /MDd
213+
if("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
214+
list(APPEND result "-D_MD")
215+
list(APPEND result -Xclang;--dependent-lib=msvcrt)
216+
else()
217+
list(APPEND result "-D_MDd")
218+
list(APPEND result -Xclang;--dependent-lib=msvcrtd)
219+
endif()
220+
endif()
221+
222+
# MSVC/clang-cl don't support -fno-pic or -fms-compatability-version.
223+
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
224+
list(APPEND result -fno-pic)
225+
list(APPEND result "-fms-compatibility-version=1900")
216226
endif()
217-
list(APPEND result -fno-pic)
218-
endif()
219227

220-
if("${CFLAGS_SDK}" STREQUAL "WINDOWS")
221228
list(APPEND result "-DLLVM_ON_WIN32")
222229
list(APPEND result "-D_CRT_SECURE_NO_WARNINGS")
223230
list(APPEND result "-D_CRT_NONSTDC_NO_WARNINGS")
224231
# TODO(compnerd) permit building for different families
225232
list(APPEND result "-D_CRT_USE_WINAPI_FAMILY_DESKTOP_APP")
226233
# TODO(compnerd) handle /MT
227234
list(APPEND result "-D_DLL")
228-
list(APPEND result "-fms-compatibility-version=1900")
229235
endif()
230236

231237
if(CFLAGS_ENABLE_ASSERTIONS)

0 commit comments

Comments
 (0)