Skip to content

Commit

Permalink
Add initial support for MinGW-w64
Browse files Browse the repository at this point in the history
  • Loading branch information
raedrizqie committed Jun 22, 2024
1 parent 1f8f796 commit ec6dbda
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 49 deletions.
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,22 @@ option(DXC_DISABLE_ALLOCATOR_OVERRIDES "Disable usage of allocator overrides" OF
mark_as_advanced(DXC_DISABLE_ALLOCATOR_OVERRIDES)

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

# enable control flow guard
if(WIN32)
add_compile_options(/guard:cf)
add_link_options(/guard:cf)
if(MSVC)
add_compile_options(/guard:cf)
add_link_options(/guard:cf)
else()
add_compile_options(-fcf-protection)
endif()
endif(WIN32)

# Enable CET Shadow Stack
if(WIN32 AND NOT (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*"))
if(MSVC AND NOT (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*"))
add_link_options(/CETCOMPAT)
endif()

Expand Down Expand Up @@ -646,9 +650,9 @@ endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# enable warnings as errors for debug build
if (WIN32)
if (MSVC)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX")
endif (WIN32)
endif (MSVC)

include(AddLLVM)
include(TableGen)
Expand Down Expand Up @@ -761,7 +765,9 @@ if (LLVM_INCLUDE_DOCS)
add_subdirectory(docs)
endif()

add_hlsl_hctgen(DxilDocs OUTPUT docs/DXIL.rst CODE_TAG) # HLSL Change
if (LLVM_BUILD_DOCS)
add_hlsl_hctgen(DxilDocs OUTPUT docs/DXIL.rst CODE_TAG) # HLSL Change
endif()

add_subdirectory(cmake/modules)

Expand Down
8 changes: 5 additions & 3 deletions cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ endfunction()
#
function(add_windows_version_resource_file OUT_VAR)
set(sources ${ARGN})
if (MSVC)
if (WIN32)
set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc)
if(EXISTS ${resource_file})
set(sources ${sources} ${resource_file})
source_group("Resource Files" ${resource_file})
set(windows_resource_file ${resource_file} PARENT_SCOPE)
endif()
endif(MSVC)
endif(WIN32)

set(${OUT_VAR} ${sources} PARENT_SCOPE)
endfunction(add_windows_version_resource_file)
Expand Down Expand Up @@ -296,8 +296,10 @@ function(set_windows_version_resource_properties name resource_file)
set(ARG_PRODUCT_NAME "LLVM")
endif()

if (MSVC)
set_property(SOURCE ${resource_file}
PROPERTY COMPILE_FLAGS /nologo)
endif()
set_property(SOURCE ${resource_file}
PROPERTY COMPILE_DEFINITIONS
"RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}"
Expand All @@ -318,7 +320,7 @@ function(set_windows_version_resource_properties name resource_file)
"INCLUDE_HLSL_VERSION_FILE=1")
set_property(SOURCE ${resource_file}
PROPERTY COMPILE_OPTIONS
"/I" "${HLSL_VERSION_LOCATION}")
"-I" "${HLSL_VERSION_LOCATION}")
endif (DEFINED resource_file)
endif(${HLSL_EMBED_VERSION})
# HLSL change ends
Expand Down
29 changes: 24 additions & 5 deletions cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ if( LLVM_ENABLE_PIC )
# Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
# know how to disable this, so just force ENABLE_PIC off for now.
message(WARNING "-fPIC not supported with Xcode.")
elseif( WIN32 OR CYGWIN)
# On Windows all code is PIC. MinGW warns if -fPIC is used.
else()
add_flag_or_print_warning("-fPIC" FPIC)
if( NOT WIN32 AND NOT CYGWIN )
# On Windows all code is PIC. MinGW warns if -fPIC is used.
add_flag_or_print_warning("-fPIC" FPIC)
endif()

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

if (MINGW)
append("-Wno-implicit-fallthrough" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-Wno-missing-exception-spec" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-Wno-reorder-ctor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-Wno-sign-compare" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-Wno-unused-const-variable" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-Wno-unused-function" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif()

add_flag_if_supported("-Wno-unused-but-set-variable" UNUSED_BUT_SET_VARIABLE)
add_flag_if_supported("-Wno-deprecated-copy" DEPRECATED_COPY)

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

if (MINGW)
if (LLVM_ENABLE_EH)
append("-fexceptions" CMAKE_CXX_FLAGS)
endif()
if (LLVM_ENABLE_RTTI)
append("-frtti" CMAKE_CXX_FLAGS)
endif()
endif()

# HLSL Change Begin
option(LLVM_ENABLE_LTO "Enable building with LTO" ${HLSL_OFFICIAL_BUILD})
if (LLVM_ENABLE_LTO)
Expand All @@ -624,7 +643,7 @@ if (LLVM_ENABLE_LTO)
append("/GL" CMAKE_C_FLAGS${_SUFFIX} CMAKE_CXX_FLAGS${_SUFFIX})
append("/LTCG" CMAKE_MODULE_LINKER_FLAGS${_SUFFIX} CMAKE_MODULE_LINKER_FLAGS${_SUFFIX} CMAKE_EXE_LINKER_FLAGS${_SUFFIX})
else()
add_flag_if_supported("-flto" SUPPORST_FLTO)
add_flag_if_supported("-flto" SUPPORTS_FLTO)
endif()
endif()
# HLSL Change End
Expand Down
14 changes: 7 additions & 7 deletions lib/DxilDia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (C) Microsoft Corporation. All rights reserved.
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.

if (WIN32)
if (MSVC)
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
endif (WIN32)
endif (MSVC)

if (WIN32)
if (MSVC)
add_llvm_library(LLVMDxilDia
DxcPixCompilationInfo.cpp
DxcPixDxilDebugInfo.cpp
Expand Down Expand Up @@ -33,7 +33,7 @@ if (WIN32)
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
)
else(WIN32)
else(MSVC)
# DxcPixLiveVariables_FragmentIterator is not dependent on dia.
# It is used by PixTest.
set(HLSL_IGNORE_SOURCES
Expand Down Expand Up @@ -65,11 +65,11 @@ else(WIN32)
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
)
endif(WIN32)
endif(MSVC)

if (WIN32)
if (MSVC)
target_link_libraries(LLVMDxilDia PRIVATE ${LIBRARIES} ${DIASDK_LIBRARIES})
include_directories(AFTER ${LLVM_INCLUDE_DIR}/dxc/Tracing ${DIASDK_INCLUDE_DIRS})
endif (WIN32)
endif (MSVC)

add_dependencies(LLVMDxilDia LLVMDxilPIXPasses intrinsics_gen)
4 changes: 2 additions & 2 deletions lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ add_llvm_library(LLVMSupport
)

set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
if(WIN32)
if(MSVC)
set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS /EHsc )
endif(WIN32)
endif(MSVC)

target_link_libraries(LLVMSupport PUBLIC LLVMMSSupport) # HLSL Change
4 changes: 2 additions & 2 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ add_llvm_tool_subdirectory(llvm-dis) # HLSL Change
# add_llvm_tool_subdirectory(llvm-mc) # HLSL Change

# HLSL Change Begins
if (WIN32)
if (MSVC)
# This target can currently only be built on Windows.
add_llvm_tool_subdirectory(dxexp)
endif (WIN32)
endif (MSVC)
# HLSL Change ends

# add_llvm_tool_subdirectory(llc) # HLSL Change
Expand Down
2 changes: 1 addition & 1 deletion tools/clang/lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set(get_svn_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/GetSVN.cmake")
if (HLSL_ENABLE_FIXED_VER)
# Actual version string is no longer specified here, but instead derived from
# the defines in the generated or copied dxcversion.inc
add_definitions(/DHLSL_FIXED_VER)
add_definitions(-DHLSL_FIXED_VER)
endif (HLSL_ENABLE_FIXED_VER)
# HLSL Change Ends

Expand Down
6 changes: 5 additions & 1 deletion tools/clang/lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ add_clang_library(clangSema
# Sema got too big for debug builds on arm64ec, which means it will hit
# other targets too eventually.
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
endif()
endif(WIN32)
# HLSL Change End
4 changes: 2 additions & 2 deletions tools/clang/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ add_subdirectory(dxr)
add_subdirectory(dxv)

# These targets can currently only be built on Windows.
if (WIN32)
if (MSVC)
add_subdirectory(d3dcomp)
add_subdirectory(dxrfallbackcompiler)
add_subdirectory(dxlib-sample)
# UI powered by .NET.
add_subdirectory(dotnetc)
endif (WIN32)
endif (MSVC)
# HLSL Change Ends
8 changes: 4 additions & 4 deletions tools/clang/tools/dxa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
# Builds dxa.exe

if (WIN32)
if (MSVC)
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
endif (WIN32)
endif (MSVC)

set( LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Expand All @@ -27,9 +27,9 @@ target_link_libraries(dxa

set_target_properties(dxa PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})

if (WIN32)
if (MSVC)
include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
endif (WIN32)
endif (MSVC)

add_dependencies(dxa dxcompiler)

Expand Down
8 changes: 4 additions & 4 deletions tools/clang/tools/dxc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
# Builds dxc.exe

if (WIN32)
if (MSVC)
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
endif (WIN32)
endif (MSVC)

set( LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Expand Down Expand Up @@ -33,9 +33,9 @@ endif()

set_target_properties(dxc PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})

if (WIN32)
if (MSVC)
include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
endif (WIN32)
endif (MSVC)

include_directories(${LLVM_SOURCE_DIR}/tools/clang/tools)

Expand Down
13 changes: 9 additions & 4 deletions tools/clang/tools/dxclib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
# Builds dxclib

if (WIN32)
if (MSVC)
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
endif (WIN32)
endif (MSVC)

set( LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Expand All @@ -20,14 +20,19 @@ add_clang_library(dxclib
dxc.cpp
)

if (MINGW)
target_link_options(dxclib PUBLIC -mconsole -municode)
target_link_libraries(dxclib PRIVATE version)
endif()

if(ENABLE_SPIRV_CODEGEN)
target_link_libraries(dxclib PRIVATE SPIRV-Tools)
target_link_libraries(dxclib PRIVATE clangSPIRV)
endif()

if (WIN32)
if (MSVC)
include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
endif (WIN32)
endif (MSVC)

target_compile_definitions(dxclib
PRIVATE VERSION_STRING_SUFFIX=" for ${CMAKE_SYSTEM_NAME}")
Expand Down
6 changes: 3 additions & 3 deletions tools/clang/tools/dxcompiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ set(GENERATED_HEADERS
ClangStmtNodes
)

if (WIN32)
if (MSVC)
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
endif (WIN32)
endif (MSVC)

add_clang_library(dxcompiler SHARED ${SOURCES})
add_dependencies(dxcompiler TablegenHLSLOptions)
if (WIN32)
if (MSVC)
# No DxcEtw on non-Windows platforms.
add_dependencies(dxcompiler DxcEtw)
endif()
Expand Down
8 changes: 4 additions & 4 deletions tools/clang/tools/dxl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
# Builds dxl.exe

if (WIN32)
if (MSVC)
find_package(DiaSDK REQUIRED) # Used for constants and declarations.
endif (WIN32)
endif (MSVC)

set( LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Expand All @@ -26,9 +26,9 @@ target_link_libraries(dxl

set_target_properties(dxl PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})

if (WIN32)
if (MSVC)
include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
endif (WIN32)
endif (MSVC)

include_directories(${LLVM_SOURCE_DIR}/tools/clang/tools)

Expand Down
4 changes: 4 additions & 0 deletions tools/clang/tools/dxopt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ target_link_libraries(dxopt
dxcompiler
)

if (MINGW)
target_link_options(dxopt PRIVATE -mconsole -municode)
endif()

set_target_properties(dxopt PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})

add_dependencies(dxopt dxcompiler)
Expand Down

0 comments on commit ec6dbda

Please sign in to comment.