From bd844387df133897ce6e3f290af771acb0df4df9 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 28 Aug 2020 15:00:57 -0400 Subject: ROCMClang: Add the ROCm toolkit derived clang compiler to CMake --- Help/variable/CMAKE_LANG_COMPILER_ID.rst | 1 + Modules/CMakeCompilerIdDetection.cmake | 5 ++++ Modules/CMakeDetermineCompilerId.cmake | 1 - Modules/Compiler/ROCMClang-ASM.cmake | 2 ++ Modules/Compiler/ROCMClang-C.cmake | 7 +++++ Modules/Compiler/ROCMClang-CXX.cmake | 7 +++++ Modules/Compiler/ROCMClang-DetermineCompiler.cmake | 19 ++++++++++++ Modules/Compiler/ROCMClang-FindBinUtils.cmake | 1 + Modules/Compiler/ROCMClang-OBJC.cmake | 7 +++++ Modules/Compiler/ROCMClang-OBJCXX.cmake | 7 +++++ Modules/Compiler/ROCMClang.cmake | 35 ++++++++++++++++++++++ Modules/WriteCompilerDetectionHeader.cmake | 1 + 12 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Modules/Compiler/ROCMClang-ASM.cmake create mode 100644 Modules/Compiler/ROCMClang-C.cmake create mode 100644 Modules/Compiler/ROCMClang-CXX.cmake create mode 100644 Modules/Compiler/ROCMClang-DetermineCompiler.cmake create mode 100644 Modules/Compiler/ROCMClang-FindBinUtils.cmake create mode 100644 Modules/Compiler/ROCMClang-OBJC.cmake create mode 100644 Modules/Compiler/ROCMClang-OBJCXX.cmake create mode 100644 Modules/Compiler/ROCMClang.cmake diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst index 0abedde..f23b7a2 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst +++ b/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) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 850fc14..2197790 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/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 diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 448f071..d656cd0 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/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}" diff --git a/Modules/Compiler/ROCMClang-ASM.cmake b/Modules/Compiler/ROCMClang-ASM.cmake new file mode 100644 index 0000000..85d1110 --- /dev/null +++ b/Modules/Compiler/ROCMClang-ASM.cmake @@ -0,0 +1,2 @@ +include(Compiler/ROCMClang) +__compiler_rocmclang(ASM) diff --git a/Modules/Compiler/ROCMClang-C.cmake b/Modules/Compiler/ROCMClang-C.cmake new file mode 100644 index 0000000..cdfa95d --- /dev/null +++ b/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}") diff --git a/Modules/Compiler/ROCMClang-CXX.cmake b/Modules/Compiler/ROCMClang-CXX.cmake new file mode 100644 index 0000000..5739c8e --- /dev/null +++ b/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}") diff --git a/Modules/Compiler/ROCMClang-DetermineCompiler.cmake b/Modules/Compiler/ROCMClang-DetermineCompiler.cmake new file mode 100644 index 0000000..c2fc99b --- /dev/null +++ b/Modules/Compiler/ROCMClang-DetermineCompiler.cmake @@ -0,0 +1,19 @@ + +set(_compiler_id_pp_test "defined(__clang__) && __has_include()") + +set(_compiler_id_version_compute " +# if defined(__clang__) && __has_include() +# include +# 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") diff --git a/Modules/Compiler/ROCMClang-FindBinUtils.cmake b/Modules/Compiler/ROCMClang-FindBinUtils.cmake new file mode 100644 index 0000000..e721c87 --- /dev/null +++ b/Modules/Compiler/ROCMClang-FindBinUtils.cmake @@ -0,0 +1 @@ +include(Compiler/Clang-FindBinUtils) diff --git a/Modules/Compiler/ROCMClang-OBJC.cmake b/Modules/Compiler/ROCMClang-OBJC.cmake new file mode 100644 index 0000000..794973d --- /dev/null +++ b/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}") diff --git a/Modules/Compiler/ROCMClang-OBJCXX.cmake b/Modules/Compiler/ROCMClang-OBJCXX.cmake new file mode 100644 index 0000000..82238e1 --- /dev/null +++ b/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}") diff --git a/Modules/Compiler/ROCMClang.cmake b/Modules/Compiler/ROCMClang.cmake new file mode 100644 index 0000000..6b38c2d --- /dev/null +++ b/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() diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake index 0e4e028..54eb40e 100644 --- a/Modules/WriteCompilerDetectionHeader.cmake +++ b/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) -- cgit v0.12