summaryrefslogtreecommitdiff
path: root/Modules/Platform
diff options
context:
space:
mode:
authorGergely Meszaros <maetveis@gmail.com>2022-10-09 20:03:28 +0200
committerGergely Meszaros <maetveis@gmail.com>2022-10-09 20:03:28 +0200
commit5b87ae6e2d5154dc0adae15f9da92a6476de9be5 (patch)
tree06e7635b7666241c27eab877a83ee949e33dbbd9 /Modules/Platform
parent8b15f532db1b424e2218fc26ffd936a32044afa1 (diff)
downloadcmake-5b87ae6e2d5154dc0adae15f9da92a6476de9be5.tar.gz
HIP, Windows: Add Windows-Clang-HIP platform module
Add a platform module for using clang for HIP on windows, based on the CXX module. HIP language on windows works without this, but mixing with MSVC produces catastrofical results. Add the same restriction with HIP as C and C++ had prior: Either none are compiled with MSVC or all are. clang-cl support for HIP does not work yet: it needs more work in both hip-lang-config.cmake and cmake itself.
Diffstat (limited to 'Modules/Platform')
-rw-r--r--Modules/Platform/Windows-Clang-HIP.cmake19
-rw-r--r--Modules/Platform/Windows-Clang.cmake45
2 files changed, 49 insertions, 15 deletions
diff --git a/Modules/Platform/Windows-Clang-HIP.cmake b/Modules/Platform/Windows-Clang-HIP.cmake
new file mode 100644
index 0000000000..20879fabee
--- /dev/null
+++ b/Modules/Platform/Windows-Clang-HIP.cmake
@@ -0,0 +1,19 @@
+include(Platform/Windows-Clang)
+set(_COMPILE_HIP_MSVC " -TP")
+__windows_compiler_clang(HIP)
+
+if("x${CMAKE_HIP_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
+ if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
+ AND CMAKE_GENERATOR MATCHES "Makefiles|WMake"
+ AND CMAKE_DEPFILE_FLAGS_HIP)
+ set(CMAKE_HIP_DEPENDS_USE_COMPILER TRUE)
+ endif()
+elseif("x${CMAKE_HIP_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
+ if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
+ AND CMAKE_GENERATOR MATCHES "Makefiles|WMake"
+ AND CMAKE_DEPFILE_FLAGS_HIP)
+ # dependencies are computed by the compiler itself
+ set(CMAKE_HIP_DEPFILE_FORMAT gcc)
+ set(CMAKE_HIP_DEPENDS_USE_COMPILER TRUE)
+ endif()
+endif()
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
index 5edcb616a5..33d271de8e 100644
--- a/Modules/Platform/Windows-Clang.cmake
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -157,24 +157,36 @@ macro(__enable_llvm_rc_preprocessing clang_option_prefix extra_pp_flags)
endif()
endmacro()
+macro(__verify_same_language_values variable)
+ foreach(lang "C" "CXX" "HIP")
+ if(DEFINED CMAKE_${lang}_${variable})
+ list(APPEND __LANGUAGE_VALUES_${variable} "${CMAKE_${lang}_${variable}}")
+ endif()
+ endforeach()
+ list(REMOVE_DUPLICATES __LANGUAGE_VALUES_${variable})
+ list(LENGTH __LANGUAGE_VALUES_${variable} __NUM_VALUES)
+
+ if(__NUM_VALUES GREATER 1)
+ message(FATAL_ERROR ${ARGN})
+ endif()
+ unset(__NUM_VALUES)
+ unset(__LANGUAGE_VALUES_${variable})
+endmacro()
if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
+ OR "x${CMAKE_HIP_SIMULATE_ID}" STREQUAL "xMSVC")
- if ( DEFINED CMAKE_C_COMPILER_ID AND DEFINED CMAKE_CXX_COMPILER_ID
- AND NOT "x${CMAKE_C_COMPILER_ID}" STREQUAL "x${CMAKE_CXX_COMPILER_ID}")
- message(FATAL_ERROR "The current configuration mixes Clang and MSVC or "
- "some other CL compatible compiler tool. This is not supported. "
- "Use either clang or MSVC as both C and C++ compilers.")
- endif()
+ __verify_same_language_values(COMPILER_ID
+ "The current configuration mixes Clang and MSVC or "
+ "some other CL compatible compiler tool. This is not supported. "
+ "Use either clang or MSVC as both C, C++ and/or HIP compilers.")
- if ( DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT AND DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT
- AND NOT "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
- message(FATAL_ERROR "The current configuration uses the Clang compiler "
- "tool with mixed frontend variants, both the GNU and in MSVC CL "
- "like variants. This is not supported. Use either clang/clang++ "
- "or clang-cl as both C and C++ compilers.")
- endif()
+ __verify_same_language_values(COMPILER_FRONTEND_VARIANT
+ "The current configuration uses the Clang compiler "
+ "tool with mixed frontend variants, both the GNU and in MSVC CL "
+ "like variants. This is not supported. Use either clang/clang++ "
+ "or clang-cl as both C, C++ and/or HIP compilers.")
if(NOT CMAKE_RC_COMPILER_INIT)
# Check if rc is already in the path
@@ -194,7 +206,10 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
unset(__RC_COMPILER_PATH CACHE)
endif()
- if ( "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" )
+ if ( "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"
+ OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"
+ OR "x${CMAKE_HIP_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
+
include(Platform/Windows-MSVC)
# Set the clang option forwarding prefix for clang-cl usage in the llvm-rc processing stage
__enable_llvm_rc_preprocessing("-clang:" "")