Просмотр исходного кода

ROCMClang: Add the ROCm toolkit derived clang compiler to CMake

Robert Maynard 5 лет назад
Родитель
Сommit
bd844387df

+ 1 - 0
Help/variable/CMAKE_LANG_COMPILER_ID.rst

@@ -34,6 +34,7 @@ include:
   OpenWatcom = Open Watcom (openwatcom.org)
   PGI = The Portland Group (pgroup.com)
   PathScale = PathScale (pathscale.com)
+  ROCMClang = ROCm Toolkit Clang-based Compiler (rocmdocs.amd.com)
   SDCC = Small Device C Compiler (sdcc.sourceforge.net)
   SunPro = Oracle Solaris Studio (oracle.com)
   TI = Texas Instruments (ti.com)

+ 5 - 0
Modules/CMakeCompilerIdDetection.cmake

@@ -81,6 +81,11 @@ function(compiler_id_detection outvar lang)
       ARMCC
       AppleClang
       ARMClang
+    )
+    if(NOT __skip_rocmclang)
+      list(APPEND ordered_compilers ROCMClang)
+    endif()
+    list(APPEND ordered_compilers
       Clang
       GNU
       MSVC

+ 0 - 1
Modules/CMakeDetermineCompilerId.cmake

@@ -150,7 +150,6 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
     endif()
   endif()
 
-
   if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU")
     execute_process(
       COMMAND "${CMAKE_${lang}_COMPILER}"

+ 2 - 0
Modules/Compiler/ROCMClang-ASM.cmake

@@ -0,0 +1,2 @@
+include(Compiler/ROCMClang)
+__compiler_rocmclang(ASM)

+ 7 - 0
Modules/Compiler/ROCMClang-C.cmake

@@ -0,0 +1,7 @@
+include(Compiler/ROCMClang)
+__compiler_rocmclang(C)
+
+set(_rocm_clang_ver "${CMAKE_C_COMPILER_VERSION_INTERNAL}")
+set(CMAKE_C_COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION_INTERNAL}")
+include(Compiler/Clang-C)
+set(CMAKE_C_COMPILER_VERSION "${_rocm_clang_ver}")

+ 7 - 0
Modules/Compiler/ROCMClang-CXX.cmake

@@ -0,0 +1,7 @@
+include(Compiler/ROCMClang)
+__compiler_rocmclang(CXX)
+
+set(_rocm_clang_ver "${CMAKE_CXX_COMPILER_VERSION_INTERNAL}")
+set(CMAKE_CXX_COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION_INTERNAL}")
+include(Compiler/Clang-CXX)
+set(CMAKE_CXX_COMPILER_VERSION "${_rocm_clang_ver}")

+ 19 - 0
Modules/Compiler/ROCMClang-DetermineCompiler.cmake

@@ -0,0 +1,19 @@
+
+set(_compiler_id_pp_test "defined(__clang__) && __has_include(<hip/hip_version.h>)")
+
+set(_compiler_id_version_compute "
+# if defined(__clang__) && __has_include(<hip/hip_version.h>)
+#  include <hip/hip_version.h>
+#  define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(HIP_VERSION_MAJOR)
+#  define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(HIP_VERSION_MINOR)
+#  define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(HIP_VERSION_PATCH)
+# endif")
+
+set(_compiler_id_simulate "
+# if defined(_MSC_VER)
+#  define @PREFIX@SIMULATE_ID \"MSVC\"
+# elif defined(__clang__)
+#  define @PREFIX@SIMULATE_ID \"Clang\"
+# elif defined(__GNUC__)
+#  define @PREFIX@SIMULATE_ID \"GNU\"
+# endif")

+ 1 - 0
Modules/Compiler/ROCMClang-FindBinUtils.cmake

@@ -0,0 +1 @@
+include(Compiler/Clang-FindBinUtils)

+ 7 - 0
Modules/Compiler/ROCMClang-OBJC.cmake

@@ -0,0 +1,7 @@
+include(Compiler/ROCMClang)
+__compiler_rocmclang(OBJC)
+
+set(_rocm_clang_ver "${CMAKE_OBJC_COMPILER_VERSION_INTERNAL}")
+set(CMAKE_OBJC_COMPILER_VERSION "${CMAKE_OBJC_COMPILER_VERSION_INTERNAL}")
+include(Compiler/Clang-OBJC)
+set(CMAKE_OBJC_COMPILER_VERSION "${_rocm_clang_ver}")

+ 7 - 0
Modules/Compiler/ROCMClang-OBJCXX.cmake

@@ -0,0 +1,7 @@
+include(Compiler/ROCMClang)
+__compiler_rocmclang(OBJCXX)
+
+set(_rocm_clang_ver "${CMAKE_OBJCXX_COMPILER_VERSION_INTERNAL}")
+set(CMAKE_OBJCXX_COMPILER_VERSION "${CMAKE_OBJCXX_COMPILER_VERSION_INTERNAL}")
+include(Compiler/Clang-OBJCXX)
+set(CMAKE_OBJCXX_COMPILER_VERSION "${_rocm_clang_ver}")

+ 35 - 0
Modules/Compiler/ROCMClang.cmake

@@ -0,0 +1,35 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+
+# This module is shared by multiple languages; use include blocker.
+include_guard()
+
+include(Compiler/CMakeCommonCompilerMacros)
+
+macro(__compiler_rocmclang lang)
+
+  set(CMAKE_${lang}_VERBOSE_FLAG "-v")
+
+  if(NOT "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC")
+    # Feature flags.
+    set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+    set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+    set(CMAKE_HIP_COMPILE_OPTIONS_VISIBILITY -fvisibility=)
+
+    string(APPEND CMAKE_HIP_FLAGS_INIT " ")
+    string(APPEND CMAKE_HIP_FLAGS_DEBUG_INIT " -g")
+    string(APPEND CMAKE_HIP_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
+    string(APPEND CMAKE_HIP_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
+    string(APPEND CMAKE_HIP_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
+  endif()
+
+  set(CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS -shared)
+  set(CMAKE_INCLUDE_SYSTEM_FLAG_HIP "-isystem ")
+
+  set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+  set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
+  set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
+  set(CMAKE_${lang}_RESPONSE_FILE_FLAG "@")
+  set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@")
+endmacro()

+ 1 - 0
Modules/WriteCompilerDetectionHeader.cmake

@@ -384,6 +384,7 @@ elseif(_WCDH_policy STREQUAL "")
     )
 endif()
 
+set(__skip_rocmclang TRUE)
 include(${CMAKE_CURRENT_LIST_DIR}/CMakeCompilerIdDetection.cmake)
 
 function(_load_compiler_variables CompilerId lang)