Update CMake to work with Intel compilers (#143)

This commit is contained in:
Chuck Walbourn 2024-02-09 11:52:24 -08:00 committed by GitHub
parent e2ac0915bf
commit 9250181c34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 120 additions and 73 deletions

View File

@ -188,25 +188,29 @@ include(CheckIncludeFileCXX)
if(DEFINED XBOX_CONSOLE_TARGET)
message(STATUS "Building for Xbox Console Target: ${XBOX_CONSOLE_TARGET}")
set(CMAKE_REQUIRED_QUIET ON)
CHECK_INCLUDE_FILE_CXX(gxdk.h GXDK_HEADER)
if(NOT GXDK_HEADER)
message(FATAL_ERROR "Microsoft GDK with Xbox Extensions required to build for Xbox. See https://aka.ms/gdkx")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC WINAPI_FAMILY=WINAPI_FAMILY_GAMES)
if(XBOX_CONSOLE_TARGET STREQUAL "scarlett")
CHECK_INCLUDE_FILE_CXX(d3d12_xs.h D3D12XS_HEADER)
if(NOT D3D12XS_HEADER)
message(FATAL_ERROR "Microsoft GDK with Xbox Extensions environment needs to be set for Xbox Series X|S.")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC _GAMING_XBOX _GAMING_XBOX_SCARLETT)
elseif(XBOX_CONSOLE_TARGET STREQUAL "xboxone")
CHECK_INCLUDE_FILE_CXX(d3d12_x.h D3D12X_HEADER)
if(NOT D3D12X_HEADER)
message(FATAL_ERROR "Microsoft GDK with Xbox Extensions environment needs to be set for Xbox One.")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC _GAMING_XBOX _GAMING_XBOX_XBOXONE)
if(XBOX_CONSOLE_TARGET STREQUAL "durango")
message(FATAL_ERROR "This library no longer supports legacy Xbox One XDK.")
else()
message(FATAL_ERROR "Unknown XBOX_CONSOLE_TARGET")
CHECK_INCLUDE_FILE_CXX(gxdk.h GXDK_HEADER)
if(NOT GXDK_HEADER)
message(FATAL_ERROR "Microsoft GDK with Xbox Extensions required to build for Xbox. See https://aka.ms/gdkx")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC WINAPI_FAMILY=WINAPI_FAMILY_GAMES)
if(XBOX_CONSOLE_TARGET STREQUAL "scarlett")
CHECK_INCLUDE_FILE_CXX(d3d12_xs.h D3D12XS_HEADER)
if(NOT D3D12XS_HEADER)
message(FATAL_ERROR "Microsoft GDK with Xbox Extensions environment needs to be set for Xbox Series X|S.")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC _GAMING_XBOX _GAMING_XBOX_SCARLETT)
elseif(XBOX_CONSOLE_TARGET STREQUAL "xboxone")
CHECK_INCLUDE_FILE_CXX(d3d12_x.h D3D12X_HEADER)
if(NOT D3D12X_HEADER)
message(FATAL_ERROR "Microsoft GDK with Xbox Extensions environment needs to be set for Xbox One.")
endif()
target_compile_definitions(${PROJECT_NAME} PUBLIC _GAMING_XBOX _GAMING_XBOX_XBOXONE)
else()
message(FATAL_ERROR "Unknown XBOX_CONSOLE_TARGET")
endif()
endif()
elseif(WINDOWS_STORE)
target_compile_definitions(${PROJECT_NAME} PUBLIC WINAPI_FAMILY=WINAPI_FAMILY_APP)
@ -291,6 +295,7 @@ if(BUILD_TOOLS AND WIN32)
UVAtlasTool/Mesh.h
UVAtlasTool/MeshOBJ.cpp
UVAtlasTool/SDKMesh.h)
target_compile_features(uvatlastool PRIVATE cxx_std_17)
target_link_libraries(uvatlastool PRIVATE
${PROJECT_NAME}
ole32.lib version.lib
@ -301,14 +306,14 @@ if(BUILD_TOOLS AND WIN32)
endif()
if(directxmath_FOUND)
foreach(t IN LISTS TOOL_EXES)
target_link_libraries(${t} PRIVATE Microsoft::DirectXMath)
endforeach()
foreach(t IN LISTS TOOL_EXES)
target_link_libraries(${t} PRIVATE Microsoft::DirectXMath)
endforeach()
endif()
if(MSVC)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /Wall /GR- "$<$<NOT:$<CONFIG:DEBUG>>:/guard:cf>")
target_compile_options(${t} PRIVATE /Wall /EHsc /GR- "$<$<NOT:$<CONFIG:DEBUG>>:/guard:cf>")
target_link_options(${t} PRIVATE /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO)
endforeach()
@ -318,30 +323,13 @@ if(MSVC)
endforeach()
endif()
if(ENABLE_SPECTRE_MITIGATION
AND (MSVC_VERSION GREATER_EQUAL 1913)
AND (NOT WINDOWS_STORE)
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 (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()
else()
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
@ -355,9 +343,9 @@ elseif(XBOX_CONSOLE_TARGET STREQUAL "xboxone")
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})
@ -371,7 +359,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(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
list(APPEND WarningsLib "-Wno-unsafe-buffer-usage")
@ -386,6 +380,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)
@ -404,49 +403,63 @@ 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 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()
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()
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 "/wd4365" "/wd4514" "/wd4625" "/wd4626" "/wd4627" "/wd4668" "/wd4710" "/wd4711" "/wd4751" "/wd4820" "/wd5026" "/wd5027" "/wd5039" "/wd5045" "/wd4061" "/wd4062" "/wd5219")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.34)
list(APPEND WarningsEXE "/wd5262" "/wd5264")
target_compile_options(${PROJECT_NAME} PRIVATE "/wd5262")
list(APPEND WarningsEXE "/wd5262" "/wd5264")
target_compile_options(${PROJECT_NAME} PRIVATE "/wd5262")
endif()
foreach(t IN LISTS TOOL_EXES)
target_compile_options(${t} PRIVATE ${WarningsEXE})
endforeach()

View File

@ -152,6 +152,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": "x64-Debug" , "description": "MSVC for x64 (Debug) Library only", "inherits": [ "base", "x64", "Debug", "MSVC" ] },
{ "name": "x64-Release" , "description": "MSVC for x64 (Release) Library only", "inherits": [ "base", "x64", "Release", "MSVC" ] },
@ -206,6 +229,12 @@
{ "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "MinGW32" ] },
{ "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC", "VCPKG", "MinGW32" ] },
{ "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) Library only", "inherits": [ "base", "x64", "Debug", "Intel" ] },
{ "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) Library only", "inherits": [ "base", "x64", "Release", "Intel" ] },
{ "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug) Library only", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] },
{ "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release) Library only", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] },
{ "name": "x64-Debug-Linux", "description": "WSL Linux x64 (Debug)", "inherits": [ "base", "x64", "Debug", "VCPKG" ] },
{ "name": "x64-Release-Linux", "description": "WSL Linux x64 (Release)", "inherits": [ "base", "x64", "Release", "VCPKG" ] },
{ "name": "arm64-Debug-Linux", "description": "WSL Linux ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "VCPKG" ] },
@ -229,7 +258,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

@ -424,7 +424,7 @@ namespace
// Binary searching to find a vertex on the border. The vertex's coordinate in TangentAxis
// is largest in all vertices whose coordinates in TangentAxis are smaller than target.
inline size_t static FindVertexRangeStartOnBorder(
static inline size_t FindVertexRangeStartOnBorder(
VERTEX_ARRAY& aBorder,
float target,
Axis TangentAxis)
@ -478,7 +478,7 @@ namespace
// Searching along the border, finding a vertex whose coordinate in TangentAxis is the
// smallest in all vertices whose coordinate in TangentAxis is larger than target.
inline size_t static FindVertexRangeEndOnBorder(
static inline size_t FindVertexRangeEndOnBorder(
VERTEX_ARRAY& aBorder,
size_t dwBorderStart,
float target,