Skip to content

Commit 0eebec6

Browse files
authored
CMake: Add initial support for MinGW-w64 (microsoft#6715)
1 parent b79169b commit 0eebec6

File tree

15 files changed

+89
-49
lines changed

15 files changed

+89
-49
lines changed

CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,22 @@ option(DXC_DISABLE_ALLOCATOR_OVERRIDES "Disable usage of allocator overrides" OF
105105
mark_as_advanced(DXC_DISABLE_ALLOCATOR_OVERRIDES)
106106

107107
# adjust link option to enable debugging from kernel mode; not compatible with incremental linking
108-
if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND WIN32 AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC")
108+
if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND MSVC AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC")
109109
add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO)
110110
endif()
111111

112112
# enable control flow guard
113113
if(WIN32)
114-
add_compile_options(/guard:cf)
115-
add_link_options(/guard:cf)
114+
if(MSVC)
115+
add_compile_options(/guard:cf)
116+
add_link_options(/guard:cf)
117+
else()
118+
add_compile_options(-fcf-protection)
119+
endif()
116120
endif(WIN32)
117121

118122
# Enable CET Shadow Stack
119-
if(WIN32 AND NOT (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*"))
123+
if(MSVC AND NOT (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*"))
120124
add_link_options(/CETCOMPAT)
121125
endif()
122126

@@ -646,9 +650,9 @@ endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
646650
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
647651

648652
# enable warnings as errors for debug build
649-
if (WIN32)
653+
if (MSVC)
650654
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX")
651-
endif (WIN32)
655+
endif (MSVC)
652656

653657
include(AddLLVM)
654658
include(TableGen)
@@ -761,7 +765,9 @@ if (LLVM_INCLUDE_DOCS)
761765
add_subdirectory(docs)
762766
endif()
763767

764-
add_hlsl_hctgen(DxilDocs OUTPUT docs/DXIL.rst CODE_TAG) # HLSL Change
768+
if (LLVM_BUILD_DOCS)
769+
add_hlsl_hctgen(DxilDocs OUTPUT docs/DXIL.rst CODE_TAG) # HLSL Change
770+
endif()
765771

766772
add_subdirectory(cmake/modules)
767773

cmake/modules/AddLLVM.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ endfunction()
245245
#
246246
function(add_windows_version_resource_file OUT_VAR)
247247
set(sources ${ARGN})
248-
if (MSVC)
248+
if (WIN32)
249249
set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc)
250250
if(EXISTS ${resource_file})
251251
set(sources ${sources} ${resource_file})
252252
source_group("Resource Files" ${resource_file})
253253
set(windows_resource_file ${resource_file} PARENT_SCOPE)
254254
endif()
255-
endif(MSVC)
255+
endif(WIN32)
256256

257257
set(${OUT_VAR} ${sources} PARENT_SCOPE)
258258
endfunction(add_windows_version_resource_file)
@@ -296,8 +296,10 @@ function(set_windows_version_resource_properties name resource_file)
296296
set(ARG_PRODUCT_NAME "LLVM")
297297
endif()
298298

299+
if (MSVC)
299300
set_property(SOURCE ${resource_file}
300301
PROPERTY COMPILE_FLAGS /nologo)
302+
endif()
301303
set_property(SOURCE ${resource_file}
302304
PROPERTY COMPILE_DEFINITIONS
303305
"RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}"
@@ -318,7 +320,7 @@ function(set_windows_version_resource_properties name resource_file)
318320
"INCLUDE_HLSL_VERSION_FILE=1")
319321
set_property(SOURCE ${resource_file}
320322
PROPERTY COMPILE_OPTIONS
321-
"/I" "${HLSL_VERSION_LOCATION}")
323+
"-I" "${HLSL_VERSION_LOCATION}")
322324
endif (DEFINED resource_file)
323325
endif(${HLSL_EMBED_VERSION})
324326
# HLSL change ends

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ if( LLVM_ENABLE_PIC )
195195
# Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
196196
# know how to disable this, so just force ENABLE_PIC off for now.
197197
message(WARNING "-fPIC not supported with Xcode.")
198-
elseif( WIN32 OR CYGWIN)
199-
# On Windows all code is PIC. MinGW warns if -fPIC is used.
200198
else()
201-
add_flag_or_print_warning("-fPIC" FPIC)
199+
if( NOT WIN32 AND NOT CYGWIN )
200+
# On Windows all code is PIC. MinGW warns if -fPIC is used.
201+
add_flag_or_print_warning("-fPIC" FPIC)
202+
endif()
202203

203-
if( WIN32 OR CYGWIN)
204+
if( (MINGW AND NOT CLANG) OR CYGWIN )
204205
# MinGW warns if -fvisibility-inlines-hidden is used.
205206
else()
206207
check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
@@ -407,6 +408,15 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
407408
# Disable unknown pragma warnings because the output is just too long with them.
408409
append("-Wno-unknown-pragmas" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
409410

411+
if (MINGW)
412+
append("-Wno-implicit-fallthrough" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
413+
append("-Wno-missing-exception-spec" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
414+
append("-Wno-reorder-ctor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
415+
append("-Wno-sign-compare" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
416+
append("-Wno-unused-const-variable" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
417+
append("-Wno-unused-function" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
418+
endif()
419+
410420
add_flag_if_supported("-Wno-unused-but-set-variable" UNUSED_BUT_SET_VARIABLE)
411421
add_flag_if_supported("-Wno-deprecated-copy" DEPRECATED_COPY)
412422

@@ -614,6 +624,15 @@ if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI)
614624
message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON")
615625
endif()
616626

627+
if (MINGW)
628+
if (LLVM_ENABLE_EH)
629+
append("-fexceptions" CMAKE_CXX_FLAGS)
630+
endif()
631+
if (LLVM_ENABLE_RTTI)
632+
append("-frtti" CMAKE_CXX_FLAGS)
633+
endif()
634+
endif()
635+
617636
# HLSL Change Begin
618637
option(LLVM_ENABLE_LTO "Enable building with LTO" ${HLSL_OFFICIAL_BUILD})
619638
if (LLVM_ENABLE_LTO)
@@ -624,7 +643,7 @@ if (LLVM_ENABLE_LTO)
624643
append("/GL" CMAKE_C_FLAGS${_SUFFIX} CMAKE_CXX_FLAGS${_SUFFIX})
625644
append("/LTCG" CMAKE_MODULE_LINKER_FLAGS${_SUFFIX} CMAKE_MODULE_LINKER_FLAGS${_SUFFIX} CMAKE_EXE_LINKER_FLAGS${_SUFFIX})
626645
else()
627-
add_flag_if_supported("-flto" SUPPORST_FLTO)
646+
add_flag_if_supported("-flto" SUPPORTS_FLTO)
628647
endif()
629648
endif()
630649
# HLSL Change End

lib/DxilDia/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Copyright (C) Microsoft Corporation. All rights reserved.
22
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
33

4-
if (WIN32)
4+
if (MSVC)
55
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
6-
endif (WIN32)
6+
endif (MSVC)
77

8-
if (WIN32)
8+
if (MSVC)
99
add_llvm_library(LLVMDxilDia
1010
DxcPixCompilationInfo.cpp
1111
DxcPixDxilDebugInfo.cpp
@@ -33,7 +33,7 @@ if (WIN32)
3333
ADDITIONAL_HEADER_DIRS
3434
${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
3535
)
36-
else(WIN32)
36+
else(MSVC)
3737
# DxcPixLiveVariables_FragmentIterator is not dependent on dia.
3838
# It is used by PixTest.
3939
set(HLSL_IGNORE_SOURCES
@@ -65,11 +65,11 @@ else(WIN32)
6565
ADDITIONAL_HEADER_DIRS
6666
${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
6767
)
68-
endif(WIN32)
68+
endif(MSVC)
6969

70-
if (WIN32)
70+
if (MSVC)
7171
target_link_libraries(LLVMDxilDia PRIVATE ${LIBRARIES} ${DIASDK_LIBRARIES})
7272
include_directories(AFTER ${LLVM_INCLUDE_DIR}/dxc/Tracing ${DIASDK_INCLUDE_DIRS})
73-
endif (WIN32)
73+
endif (MSVC)
7474

7575
add_dependencies(LLVMDxilDia LLVMDxilPIXPasses intrinsics_gen)

lib/Support/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ add_llvm_library(LLVMSupport
145145
)
146146

147147
set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
148-
if(WIN32)
148+
if(MSVC)
149149
set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS /EHsc )
150-
endif(WIN32)
150+
endif(MSVC)
151151

152152
target_link_libraries(LLVMSupport PUBLIC LLVMMSSupport) # HLSL Change

tools/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ add_llvm_tool_subdirectory(llvm-dis) # HLSL Change
2121
# add_llvm_tool_subdirectory(llvm-mc) # HLSL Change
2222

2323
# HLSL Change Begins
24-
if (WIN32)
24+
if (MSVC)
2525
# This target can currently only be built on Windows.
2626
add_llvm_tool_subdirectory(dxexp)
27-
endif (WIN32)
27+
endif (MSVC)
2828
# HLSL Change ends
2929

3030
# add_llvm_tool_subdirectory(llc) # HLSL Change

tools/clang/lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ set(get_svn_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/GetSVN.cmake")
3535
if (HLSL_ENABLE_FIXED_VER)
3636
# Actual version string is no longer specified here, but instead derived from
3737
# the defines in the generated or copied dxcversion.inc
38-
add_definitions(/DHLSL_FIXED_VER)
38+
add_definitions(-DHLSL_FIXED_VER)
3939
endif (HLSL_ENABLE_FIXED_VER)
4040
# HLSL Change Ends
4141

tools/clang/lib/Sema/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ add_clang_library(clangSema
7272
# Sema got too big for debug builds on arm64ec, which means it will hit
7373
# other targets too eventually.
7474
if(WIN32)
75-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
75+
if(MSVC)
76+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
77+
else()
78+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
79+
endif()
7680
endif(WIN32)
7781
# HLSL Change End

tools/clang/tools/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ add_subdirectory(dxr)
3333
add_subdirectory(dxv)
3434

3535
# These targets can currently only be built on Windows.
36-
if (WIN32)
36+
if (MSVC)
3737
add_subdirectory(d3dcomp)
3838
add_subdirectory(dxrfallbackcompiler)
3939
add_subdirectory(dxlib-sample)
4040
# UI powered by .NET.
4141
add_subdirectory(dotnetc)
42-
endif (WIN32)
42+
endif (MSVC)
4343
# HLSL Change Ends

tools/clang/tools/dxa/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
33
# Builds dxa.exe
44

5-
if (WIN32)
5+
if (MSVC)
66
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
7-
endif (WIN32)
7+
endif (MSVC)
88

99
set( LLVM_LINK_COMPONENTS
1010
${LLVM_TARGETS_TO_BUILD}
@@ -27,9 +27,9 @@ target_link_libraries(dxa
2727

2828
set_target_properties(dxa PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})
2929

30-
if (WIN32)
30+
if (MSVC)
3131
include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
32-
endif (WIN32)
32+
endif (MSVC)
3333

3434
add_dependencies(dxa dxcompiler)
3535

0 commit comments

Comments
 (0)