1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-09 14:30:05 +00:00

CMake build option to enable /Qspectre (#293)

This commit is contained in:
Chuck Walbourn 2022-12-06 11:43:45 -08:00
parent 06d5286870
commit 27dcde569c
6 changed files with 275 additions and 8 deletions

View File

@ -24,6 +24,9 @@ option(BUILD_DX12 "Build with DirectX12 Runtime support" ON)
# Enable the use of OpenMP for software BC6H/BC7 compression
option(BC_USE_OPENMP "Build with OpenMP support" ON)
# https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
option(ENABLE_SPECTRE_MITIGATION "Build using /Qspectre for MSVC" OFF)
option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
option(USE_PREBUILT_SHADERS "Use externally built HLSL shaders" OFF)
@ -162,7 +165,7 @@ if(NOT MINGW)
endif()
if(MINGW OR (NOT WIN32) OR VCPKG_TOOLCHAIN)
message("INFO: Using VCPKG for DirectX-Headers and DirectXMath.")
message(STATUS "Using VCPKG for DirectX-Headers and DirectXMath")
find_package(directx-headers CONFIG REQUIRED)
find_package(directxmath CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectX-Headers Microsoft::DirectXMath)
@ -284,12 +287,24 @@ if(MSVC)
endforeach()
if((${CMAKE_SIZEOF_VOID_P} EQUAL 4) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm")))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_link_options(${t} PRIVATE /SAFESEH)
endforeach()
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_link_options(${t} PRIVATE /SAFESEH)
endforeach()
endif()
if((MSVC_VERSION GREATER_EQUAL 1928) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)
if(ENABLE_SPECTRE_MITIGATION
AND (MSVC_VERSION GREATER_EQUAL 1913)
AND (NOT WINDOWS_STORE)
AND (NOT ENABLE_OPENEXR_SUPPORT)
AND (NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
message(STATUS "Using Spectre-mitigated libraries")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE "/Qspectre")
endforeach()
endif()
if((MSVC_VERSION GREATER_EQUAL 1928)
AND (CMAKE_SIZEOF_VOID_P EQUAL 8)
AND NOT ENABLE_OPENEXR_SUPPORT
AND ((NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
@ -381,12 +396,12 @@ if(WIN32)
endif()
if(BUILD_DX12 OR WINDOWS_STORE OR (${DIRECTX_ARCH} MATCHES "^arm64"))
message("INFO: Building with DirectX 12 Runtime support")
message(STATUS "Building with DirectX 12 Runtime support")
set(WINVER 0x0A00)
elseif(${DIRECTX_ARCH} MATCHES "^arm")
set(WINVER 0x0602)
else()
message("INFO: Building with Windows 7 compatibility")
message(STATUS "Building with Windows 7 compatibility")
set(WINVER 0x0601)
target_compile_definitions(${PROJECT_NAME} PRIVATE _WIN7_PLATFORM_UPDATE)
endif()

View File

@ -61,7 +61,11 @@ These components are designed to work without requiring any content from the leg
> DDSTextureLoader12, ScreenGrab12, and WICTextureLoader12 are 'stand-alone' versions of the same modules provided in the [DirectX Tool Kit for DX12](https://github.com/Microsoft/DirectXTK12).
# Documentation
* ``build\``
+ Contains YAML files for the build pipelines along with some miscellaneous build files and scripts.
## Documentation
Documentation is available on the [GitHub wiki](https://github.com/Microsoft/DirectXTex/wiki).

View File

@ -136,3 +136,43 @@ jobs:
inputs:
cwd: ''
cmakeArgs: --build out8 -v --config Debug
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Config x64'
inputs:
cwd: ''
cmakeArgs: '-G "$(VS_GENERATOR)" -A x64 -B out9 -DENABLE_SPECTRE_MITIGATION=ON -DCMAKE_SYSTEM_VERSION=$(WIN10_SDK) -DBUILD_DX12=OFF'
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build x64 Debug'
inputs:
cwd: ''
cmakeArgs: --build out9 -v --config Debug
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build x64 Release'
inputs:
cwd: ''
cmakeArgs: --build out9 -v --config RelWithDebInfo
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Config ARM64'
inputs:
cwd: ''
cmakeArgs: '-G "$(VS_GENERATOR)" -A ARM64 -B out10 -DENABLE_SPECTRE_MITIGATION=ON -DCMAKE_SYSTEM_VERSION=$(WIN10_SDK) -DBUILD_DX12=OFF'
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build ARM64 Debug'
inputs:
cwd: ''
cmakeArgs: --build out10 -v --config Debug
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build ARM64 Release'
inputs:
cwd: ''
cmakeArgs: --build out10 -v --config RelWithDebInfo
- task: CMake@1
displayName: 'CMake (Win10 Spectre): Config'
inputs:
cwd: ''
cmakeArgs: '-G "$(VS_GENERATOR)" -A x64 -B out11 -DENABLE_SPECTRE_MITIGATION=ON -DCMAKE_SYSTEM_VERSION=$(WIN10_SDK) -DBUILD_DX12=ON'
- task: CMake@1
displayName: 'CMake (Win10 Spectre): Build'
inputs:
cwd: ''
cmakeArgs: --build out11 -v --config Debug

View File

@ -136,3 +136,43 @@ jobs:
inputs:
cwd: ''
cmakeArgs: --build out8 -v --config Debug
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Config x64'
inputs:
cwd: ''
cmakeArgs: '-G "$(VS_GENERATOR)" -A x64 -B out9 -DENABLE_SPECTRE_MITIGATION=ON -DCMAKE_SYSTEM_VERSION=$(WIN10_SDK) -DBUILD_DX12=OFF'
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build x64 Debug'
inputs:
cwd: ''
cmakeArgs: --build out9 -v --config Debug
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build x64 Release'
inputs:
cwd: ''
cmakeArgs: --build out9 -v --config RelWithDebInfo
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Config ARM64'
inputs:
cwd: ''
cmakeArgs: '-G "$(VS_GENERATOR)" -A ARM64 -B out10 -DENABLE_SPECTRE_MITIGATION=ON -DCMAKE_SYSTEM_VERSION=$(WIN10_SDK) -DBUILD_DX12=OFF'
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build ARM64 Debug'
inputs:
cwd: ''
cmakeArgs: --build out10 -v --config Debug
- task: CMake@1
displayName: 'CMake (MSVC Spectre): Build ARM64 Release'
inputs:
cwd: ''
cmakeArgs: --build out10 -v --config RelWithDebInfo
- task: CMake@1
displayName: 'CMake (Win10 Spectre): Config'
inputs:
cwd: ''
cmakeArgs: '-G "$(VS_GENERATOR)" -A x64 -B out11 -DENABLE_SPECTRE_MITIGATION=ON -DCMAKE_SYSTEM_VERSION=$(WIN10_SDK) -DBUILD_DX12=ON'
- task: CMake@1
displayName: 'CMake (Win10 Spectre): Build'
inputs:
cwd: ''
cmakeArgs: --build out11 -v --config Debug

View File

@ -115,6 +115,95 @@ jobs:
configuration: Release
msbuildArchitecture: x64
- job: DESKTOP_BUILD_SPECTRE
displayName: 'Win32 Desktop (Spectre-mitigated)'
timeoutInMinutes: 120
cancelTimeoutInMinutes: 1
steps:
- checkout: self
clean: true
fetchTags: false
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022.sln 32dbg
inputs:
solution: DirectXTex_Desktop_2022.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Debug
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022.sln 32rel
inputs:
solution: DirectXTex_Desktop_2022.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Release
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022.sln 64dbg
inputs:
solution: DirectXTex_Desktop_2022.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Debug
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022.sln 64rel
inputs:
solution: DirectXTex_Desktop_2022.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Release
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022_Win10.sln 32dbg
inputs:
solution: DirectXTex_Desktop_2022_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Debug
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022_Win10.sln 32rel
inputs:
solution: DirectXTex_Desktop_2022_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Release
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022_Win10.sln 64dbg
inputs:
solution: DirectXTex_Desktop_2022_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Debug
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022_Win10.sln 64rel
inputs:
solution: DirectXTex_Desktop_2022_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Release
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022_Win10.sln arm64dbg
inputs:
solution: DirectXTex_Desktop_2022_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: ARM64
configuration: Debug
msbuildArchitecture: x64
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2022_Win10.sln arm64rel
inputs:
solution: DirectXTex_Desktop_2022_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: ARM64
configuration: Release
msbuildArchitecture: x64
- job: UWP_BUILD
displayName: 'Universal Windows Platform (UWP)'
timeoutInMinutes: 120

View File

@ -105,6 +105,85 @@ jobs:
platform: ARM64
configuration: Release
- job: DESKTOP_BUILD_SPECTRE
displayName: 'Win32 Desktop (Spectre-mitigated)'
timeoutInMinutes: 120
cancelTimeoutInMinutes: 1
steps:
- checkout: self
clean: true
fetchTags: false
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019.sln 32dbg
inputs:
solution: DirectXTex_Desktop_2019.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Debug
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019.sln 32rel
inputs:
solution: DirectXTex_Desktop_2019.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Release
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019.sln 64dbg
inputs:
solution: DirectXTex_Desktop_2019.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Debug
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019.sln 64rel
inputs:
solution: DirectXTex_Desktop_2019.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Release
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019_Win10.sln 32dbg
inputs:
solution: DirectXTex_Desktop_2019_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Debug
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019_Win10.sln 32rel
inputs:
solution: DirectXTex_Desktop_2019_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x86
configuration: Release
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019_Win10.sln 64dbg
inputs:
solution: DirectXTex_Desktop_2019_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Debug
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019_Win10.sln 64rel
inputs:
solution: DirectXTex_Desktop_2019_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: x64
configuration: Release
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019_Win10.sln arm64dbg
inputs:
solution: DirectXTex_Desktop_2019_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: ARM64
configuration: Debug
- task: VSBuild@1
displayName: Build solution DirectXTex_Desktop_2019_Win10.sln arm64rel
inputs:
solution: DirectXTex_Desktop_2019_Win10.sln
msbuildArgs: /p:PreferredToolArchitecture=x64 /p:SpectreMitigation=Spectre
platform: ARM64
configuration: Release
- job: UWP_BUILD
displayName: 'Universal Windows Platform (UWP)'
timeoutInMinutes: 120