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

Update CMake to work with Intel compilers (#451)

This commit is contained in:
Chuck Walbourn 2024-02-09 11:52:49 -08:00 committed by GitHub
parent 416c2364e0
commit 7fbe35ff34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 146 additions and 63 deletions

View File

@ -257,7 +257,7 @@ if(ENABLE_OPENEXR_SUPPORT)
endif()
if(BUILD_XBOX_EXTS_SCARLETT AND WIN32)
if (EXISTS "${GameDK_DIR}/GXDK/toolKit/include/gxdk.h")
if(EXISTS "${GameDK_DIR}/GXDK/toolKit/include/gxdk.h")
message(STATUS "Building Xbox extensions for Xbox Series X|S")
add_library(Xbox::GDKX SHARED IMPORTED)
@ -275,7 +275,7 @@ if(BUILD_XBOX_EXTS_SCARLETT AND WIN32)
message(FATAL_ERROR "Building Xbox extensions requires GameDKLatest")
endif()
elseif(BUILD_XBOX_EXTS_XBOXONE AND WIN32)
if (EXISTS "${GameDK_DIR}/GXDK/toolKit/include/gxdk.h")
if(EXISTS "${GameDK_DIR}/GXDK/toolKit/include/gxdk.h")
message(STATUS "Building Xbox extensions for XboxOne using the Microsoft GDK")
add_library(Xbox::GDKX SHARED IMPORTED)
@ -290,7 +290,7 @@ elseif(BUILD_XBOX_EXTS_XBOXONE AND WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_XBOX_EXTS)
target_link_libraries(${PROJECT_NAME} PUBLIC Xbox::GDKX)
elseif (EXISTS "${XboxOneXDK_DIR}/PC/include/xdk.h")
elseif(EXISTS "${XboxOneXDK_DIR}/PC/include/xdk.h")
message(STATUS "Building Xbox extensions for XboxOne using the Xbox One XDK")
add_library(Xbox::XDK SHARED IMPORTED)
@ -456,6 +456,7 @@ if(BUILD_TOOLS AND WIN32)
Texassemble/texassemble.rc
Texassemble/settings.manifest
Texassemble/AnimatedGif.cpp)
target_compile_features(texassemble PRIVATE cxx_std_17)
target_link_libraries(texassemble PRIVATE ${PROJECT_NAME} ole32.lib version.lib)
source_group(texassemble REGULAR_EXPRESSION Texassemble/*.*)
list(APPEND TOOL_EXES texassemble)
@ -468,6 +469,7 @@ if(BUILD_TOOLS AND BUILD_DX11 AND WIN32)
Texconv/settings.manifest
Texconv/ExtendedBMP.cpp
Texconv/PortablePixMap.cpp)
target_compile_features(texconv PRIVATE cxx_std_17)
target_link_libraries(texconv PRIVATE ${PROJECT_NAME} ole32.lib shell32.lib version.lib)
source_group(texconv REGULAR_EXPRESSION Texconv/*.*)
list(APPEND TOOL_EXES texconv)
@ -478,6 +480,7 @@ if(BUILD_TOOLS AND WIN32)
Texdiag/texdiag.cpp
Texdiag/texdiag.rc
Texdiag/settings.manifest)
target_compile_features(texdiag PRIVATE cxx_std_17)
target_link_libraries(texdiag PRIVATE ${PROJECT_NAME} ole32.lib version.lib)
source_group(texdiag REGULAR_EXPRESSION Texdiag/*.*)
list(APPEND TOOL_EXES texdiag)
@ -510,7 +513,7 @@ if(BUILD_TOOLS AND WIN32)
target_compile_definitions(texconv PRIVATE USE_XBOX_EXTS)
target_link_libraries(texconv PUBLIC $<TARGET_NAME_IF_EXISTS:Xbox::GDKX> $<TARGET_NAME_IF_EXISTS:Xbox::XDK>)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
add_custom_command(TARGET texconv POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_RUNTIME_DLLS:texconv> $<TARGET_FILE_DIR:texconv>
@ -573,32 +576,14 @@ if(MSVC)
endforeach()
endif()
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 "Building 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 1924)
AND ((NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /ZH:SHA_256)
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})
target_compile_options(${t} PRIVATE "$<$<NOT:$<CONFIG:DEBUG>>:/guard:ehcont>")
target_link_options(${t} PRIVATE "$<$<NOT:$<CONFIG:DEBUG>>:/guard:ehcont>")
endforeach()
AND ((NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")) OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE "$<$<NOT:$<CONFIG:DEBUG>>:/guard:ehcont>")
target_link_options(${t} PRIVATE "$<$<NOT:$<CONFIG:DEBUG>>:/guard:ehcont>")
endforeach()
endif()
if(NO_WCHAR_T)
@ -619,9 +604,9 @@ elseif(XBOX_CONSOLE_TARGET MATCHES "(xboxone|durango)")
target_compile_options(${PROJECT_NAME} PRIVATE $<IF:$<CXX_COMPILER_ID:MSVC>,/favor:AMD64 /arch:AVX,-march=btver2>)
elseif(NOT (${DIRECTX_ARCH} MATCHES "^arm"))
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_SSE2 $<$<CXX_COMPILER_ID:MSVC>:/arch:SSE2> $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse2>)
set(ARCH_SSE2 $<$<CXX_COMPILER_ID:MSVC,Intel>:/arch:SSE2> $<$<NOT:$<CXX_COMPILER_ID:MSVC,Intel>>:-msse2>)
else()
set(ARCH_SSE2 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse2>)
set(ARCH_SSE2 $<$<NOT:$<CXX_COMPILER_ID:MSVC,Intel>>:-msse2>)
endif()
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
@ -635,7 +620,13 @@ if(MINGW)
endforeach()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
if(MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /ZH:SHA_256)
endforeach()
endif()
set(WarningsLib -Wall -Wpedantic -Wextra)
if((BUILD_XBOX_EXTS_XBOXONE OR BUILD_XBOX_EXTS_SCARLETT) AND WIN32)
@ -657,6 +648,11 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE "-Wno-ignored-attributes" "-Walloc-size-larger-than=4GB")
endforeach()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:__cplusplus /Zc:inline /fp:fast /Qdiag-disable:161)
endforeach()
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /sdl /permissive- /JMC- /Zc:__cplusplus /Zc:inline /fp:fast)
@ -675,64 +671,82 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
endforeach()
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.26)
if(ENABLE_SPECTRE_MITIGATION
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.13)
AND (NOT ENABLE_OPENEXR_SUPPORT)
AND (NOT WINDOWS_STORE))
message(STATUS "Building Spectre-mitigated libraries")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:preprocessor /wd5105)
target_compile_options(${t} PRIVATE "/Qspectre")
endforeach()
if(BUILD_XBOX_EXTS_XBOXONE)
target_compile_options(${PROJECT_NAME} PRIVATE /wd5104 /wd5204)
endif()
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.24)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /ZH:SHA_256)
endforeach()
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.26)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:preprocessor /wd5105)
endforeach()
if(BUILD_XBOX_EXTS_XBOXONE)
target_compile_options(${PROJECT_NAME} PRIVATE /wd5104 /wd5204)
endif()
endif()
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.27) AND (NOT (${DIRECTX_ARCH} MATCHES "^arm")))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_link_options(${t} PRIVATE /CETCOMPAT)
endforeach()
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_link_options(${t} PRIVATE /CETCOMPAT)
endforeach()
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.28)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:lambda)
endforeach()
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:lambda)
endforeach()
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.35)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:checkGwOdr)
endforeach()
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:checkGwOdr)
endforeach()
if(NOT (DEFINED XBOX_CONSOLE_TARGET))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE $<$<VERSION_GREATER_EQUAL:${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION},10.0.22000>:/Zc:templateScope>)
endforeach()
endif()
if(NOT (DEFINED XBOX_CONSOLE_TARGET))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE $<$<VERSION_GREATER_EQUAL:${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION},10.0.22000>:/Zc:templateScope>)
endforeach()
endif()
endif()
if(OpenMP_CXX_FOUND)
# OpenMP in MSVC is not compatible with /permissive- unless you disable two-phase lookup
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:twoPhase-)
endforeach()
# OpenMP in MSVC is not compatible with /permissive- unless you disable two-phase lookup
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Zc:twoPhase-)
endforeach()
endif()
set(WarningsEXE "/wd4061" "/wd4062" "/wd4365" "/wd4514" "/wd4625" "/wd4626" "/wd4627" "/wd4668" "/wd4710" "/wd4711" "/wd4751" "/wd4820" "/wd5026" "/wd5027" "/wd5039" "/wd5045" "/wd5219")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.34)
list(APPEND WarningsEXE "/wd5262" "/wd5264")
list(APPEND WarningsEXE "/wd5262" "/wd5264")
endif()
foreach(t IN LISTS TOOL_EXES)
target_compile_options(${t} PRIVATE ${WarningsEXE})
endforeach()
if (BUILD_FUZZING AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.32)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /fsanitize=address /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div)
target_link_libraries(${t} PRIVATE sancov.lib)
endforeach()
if(BUILD_FUZZING
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.32)
AND (NOT WINDOWS_STORE))
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /fsanitize=address /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div)
target_link_libraries(${t} PRIVATE sancov.lib)
endforeach()
endif()
endif()
if(WIN32)
if (XBOX_CONSOLE_TARGET STREQUAL "durango")
if(XBOX_CONSOLE_TARGET STREQUAL "durango")
set(WINVER 0x0602)
elseif(BUILD_DX12 OR (${DIRECTX_ARCH} MATCHES "^arm64"))
message(STATUS "Building with DirectX 12 Runtime support")
@ -757,7 +771,7 @@ if(WIN32)
endif()
if(BUILD_TOOLS AND BUILD_DX11 AND WIN32)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT texconv)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT texconv)
endif()
if(BUILD_TOOLS AND (NOT VCPKG_TOOLCHAIN))
@ -775,5 +789,5 @@ if(WIN32 AND (NOT WINDOWS_STORE) AND (NOT (DEFINED XBOX_CONSOLE_TARGET)))
elseif(BUILD_FUZZING AND (EXISTS "${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders/CMakeLists.txt"))
message(STATUS "Building for fuzzing")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Tests/fuzzloaders)
endif()
endif()
endif()

View File

@ -202,6 +202,29 @@
"VCPKG_HOST_TRIPLET": "x64-mingw-static"
}
},
{
"name": "Intel",
"hidden": true,
"cacheVariables": {
"CMAKE_CXX_COMPILER": "icl.exe",
"BUILD_TOOLS": false
},
"toolset": {
"value": "host=x64",
"strategy": "external"
}
},
{
"name": "IntelLLVM",
"hidden": true,
"cacheVariables": {
"CMAKE_CXX_COMPILER": "icx.exe"
},
"toolset": {
"value": "host=x64",
"strategy": "external"
}
},
{
"name": "Fuzzing",
"cacheVariables": {
@ -301,6 +324,12 @@
{ "name": "arm64-Debug-Linux", "description": "WSL Linux ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "VCPKG", "JPEG_PNG" ] },
{ "name": "arm64-Release-Linux", "description": "WSL Linux ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "VCPKG", "JPEG_PNG" ] },
{ "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "Intel" ] },
{ "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) with DX12", "inherits": [ "base", "x64", "Release", "Intel" ] },
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) with DX12", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) with DX12", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },
{ "name": "x64-Fuzzing" , "description": "MSVC for x64 (Release) with ASan", "inherits": [ "base", "x64", "Release", "MSVC", "Fuzzing" ] }
],
"testPresets": [
@ -321,6 +350,12 @@
{ "name": "x64-Debug-MinGW" , "configurePreset": "x64-Debug-MinGW" },
{ "name": "x64-Release-MinGW" , "configurePreset": "x64-Release-MinGW" },
{ "name": "x86-Debug-MinGW" , "configurePreset": "x86-Debug-MinGW" },
{ "name": "x86-Release-MinGW" , "configurePreset": "x86-Release-MinGW" }
{ "name": "x86-Release-MinGW" , "configurePreset": "x86-Release-MinGW" },
{ "name": "x64-Debug-ICC" , "configurePreset": "x64-Debug-ICC" },
{ "name": "x64-Release-ICC" , "configurePreset": "x64-Release-ICC"},
{ "name": "x64-Debug-ICX" , "configurePreset": "x64-Debug-ICX" },
{ "name": "x64-Release-ICX" , "configurePreset": "x64-Release-ICX"}
]
}

View File

@ -41,6 +41,11 @@ namespace
const GUID& wic;
DXGI_FORMAT format;
bool srgb;
constexpr WICTranslate(const GUID& wg, DXGI_FORMAT fmt, bool isrgb) noexcept :
wic(wg),
format(fmt),
srgb(isrgb) {}
};
constexpr WICTranslate g_WICFormats[] =

View File

@ -25,6 +25,11 @@ namespace
const GUID& source;
const GUID& target;
TEX_ALPHA_MODE alphaMode;
constexpr WICConvert(const GUID& src, const GUID& tgt, TEX_ALPHA_MODE mode) noexcept :
source(src),
target(tgt),
alphaMode(mode) {}
};
constexpr WICConvert g_WICConvert[] =

View File

@ -84,6 +84,10 @@ namespace
{
const GUID& wic;
DXGI_FORMAT format;
constexpr WICTranslate(const GUID& wg, DXGI_FORMAT fmt) noexcept :
wic(wg),
format(fmt) {}
};
constexpr WICTranslate g_WICFormats[] =
@ -118,6 +122,10 @@ namespace
{
const GUID& source;
const GUID& target;
constexpr WICConvert(const GUID& src, const GUID& tgt) noexcept :
source(src),
target(tgt) {}
};
constexpr WICConvert g_WICConvert[] =

View File

@ -75,6 +75,10 @@ namespace
{
const GUID& wic;
DXGI_FORMAT format;
constexpr WICTranslate(const GUID& wg, DXGI_FORMAT fmt) noexcept :
wic(wg),
format(fmt) {}
};
constexpr WICTranslate g_WICFormats[] =
@ -111,6 +115,10 @@ namespace
{
const GUID& source;
const GUID& target;
constexpr WICConvert(const GUID& src, const GUID& tgt) noexcept :
source(src),
target(tgt) {}
};
constexpr WICConvert g_WICConvert[] =

View File

@ -63,6 +63,10 @@ namespace
{
const GUID& wic;
D3DFORMAT format;
constexpr WICTranslate(const GUID& wg, D3DFORMAT fmt) noexcept :
wic(wg),
format(fmt) {}
};
constexpr WICTranslate g_WICFormats[] =
@ -95,6 +99,10 @@ namespace
{
const GUID& source;
const GUID& target;
constexpr WICConvert(const GUID& src, const GUID& tgt) noexcept :
source(src),
target(tgt) {}
};
constexpr WICConvert g_WICConvert[] =