1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

HIP: Add language to CMake

This commit is contained in:
Robert Maynard
2020-08-28 15:03:39 -04:00
committed by Zack Galbreath
parent ff0d2858e1
commit b50bfc8913
68 changed files with 1183 additions and 36 deletions

View File

@@ -166,6 +166,62 @@ function(cmake_determine_compile_features lang)
message(CHECK_PASS "done")
elseif(lang STREQUAL HIP AND COMMAND cmake_record_hip_compile_features)
message(CHECK_START "Detecting ${lang} compile features")
set(CMAKE_HIP98_COMPILE_FEATURES)
set(CMAKE_HIP11_COMPILE_FEATURES)
set(CMAKE_HIP14_COMPILE_FEATURES)
set(CMAKE_HIP17_COMPILE_FEATURES)
set(CMAKE_HIP20_COMPILE_FEATURES)
set(CMAKE_HIP23_COMPILE_FEATURES)
include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
cmake_record_hip_compile_features()
if(NOT _result EQUAL 0)
message(CHECK_FAIL "failed")
return()
endif()
if (CMAKE_HIP20_COMPILE_FEATURES AND CMAKE_HIP23_COMPILE_FEATURES)
list(REMOVE_ITEM CMAKE_HIP23_COMPILE_FEATURES ${CMAKE_HIP20_COMPILE_FEATURES})
endif()
if (CMAKE_HIP17_COMPILE_FEATURES AND CMAKE_HIP20_COMPILE_FEATURES)
list(REMOVE_ITEM CMAKE_HIP20_COMPILE_FEATURES ${CMAKE_HIP17_COMPILE_FEATURES})
endif()
if (CMAKE_HIP14_COMPILE_FEATURES AND CMAKE_HIP17_COMPILE_FEATURES)
list(REMOVE_ITEM CMAKE_HIP17_COMPILE_FEATURES ${CMAKE_HIP14_COMPILE_FEATURES})
endif()
if (CMAKE_HIP11_COMPILE_FEATURES AND CMAKE_HIP14_COMPILE_FEATURES)
list(REMOVE_ITEM CMAKE_HIP14_COMPILE_FEATURES ${CMAKE_HIP11_COMPILE_FEATURES})
endif()
if (CMAKE_HIP98_COMPILE_FEATURES AND CMAKE_HIP11_COMPILE_FEATURES)
list(REMOVE_ITEM CMAKE_HIP11_COMPILE_FEATURES ${CMAKE_HIP98_COMPILE_FEATURES})
endif()
if(NOT CMAKE_HIP_COMPILE_FEATURES)
set(CMAKE_HIP_COMPILE_FEATURES
${CMAKE_HIP98_COMPILE_FEATURES}
${CMAKE_HIP11_COMPILE_FEATURES}
${CMAKE_HIP14_COMPILE_FEATURES}
${CMAKE_HIP17_COMPILE_FEATURES}
${CMAKE_HIP20_COMPILE_FEATURES}
${CMAKE_HIP23_COMPILE_FEATURES}
)
endif()
set(CMAKE_HIP_COMPILE_FEATURES ${CMAKE_HIP_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_HIP98_COMPILE_FEATURES ${CMAKE_HIP98_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_HIP11_COMPILE_FEATURES ${CMAKE_HIP11_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_HIP14_COMPILE_FEATURES ${CMAKE_HIP14_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_HIP17_COMPILE_FEATURES ${CMAKE_HIP17_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_HIP20_COMPILE_FEATURES ${CMAKE_HIP20_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_HIP23_COMPILE_FEATURES ${CMAKE_HIP23_COMPILE_FEATURES} PARENT_SCOPE)
message(CHECK_PASS "done")
endif()
endfunction()

View File

@@ -0,0 +1,96 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR
("${CMAKE_GENERATOR}" MATCHES "Ninja") ) )
message(FATAL_ERROR "HIP language not currently supported by \"${CMAKE_GENERATOR}\" generator")
endif()
if(NOT CMAKE_HIP_COMPILER)
set(CMAKE_HIP_COMPILER_INIT NOTFOUND)
# prefer the environment variable HIPCXX
if(NOT $ENV{HIPCXX} STREQUAL "")
get_filename_component(CMAKE_HIP_COMPILER_INIT $ENV{HIPCXX} PROGRAM PROGRAM_ARGS CMAKE_HIP_FLAGS_ENV_INIT)
if(CMAKE_HIP_FLAGS_ENV_INIT)
set(CMAKE_HIP_COMPILER_ARG1 "${CMAKE_HIP_FLAGS_ENV_INIT}" CACHE STRING "Arguments to CXX compiler")
endif()
if(NOT EXISTS ${CMAKE_HIP_COMPILER_INIT})
message(FATAL_ERROR "Could not find compiler set in environment variable HIPCXX:\n$ENV{HIPCXX}.\n${CMAKE_HIP_COMPILER_INIT}")
endif()
endif()
# finally list compilers to try
if(NOT CMAKE_HIP_COMPILER_INIT)
set(CMAKE_HIP_COMPILER_LIST hipcc clang++)
endif()
_cmake_find_compiler(HIP)
else()
_cmake_find_compiler_path(HIP)
endif()
mark_as_advanced(CMAKE_HIP_COMPILER)
# Build a small source file to identify the compiler.
if(NOT CMAKE_HIP_COMPILER_ID_RUN)
set(CMAKE_HIP_COMPILER_ID_RUN 1)
# Try to identify the compiler.
set(CMAKE_HIP_COMPILER_ID)
set(CMAKE_HIP_PLATFORM_ID)
file(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in
CMAKE_HIP_COMPILER_ID_PLATFORM_CONTENT)
list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-v")
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
CMAKE_DETERMINE_COMPILER_ID(HIP HIPFLAGS CMakeHIPCompilerId.hip)
_cmake_find_compiler_sysroot(HIP)
endif()
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_HIP_COMPILER}" PATH)
endif ()
set(_CMAKE_PROCESSING_LANGUAGE "HIP")
include(CMakeFindBinUtils)
include(Compiler/${CMAKE_HIP_COMPILER_ID}-FindBinUtils OPTIONAL)
unset(_CMAKE_PROCESSING_LANGUAGE)
if(CMAKE_HIP_COMPILER_SYSROOT)
string(CONCAT _SET_CMAKE_HIP_COMPILER_SYSROOT
"set(CMAKE_HIP_COMPILER_SYSROOT \"${CMAKE_HIP_COMPILER_SYSROOT}\")\n"
"set(CMAKE_COMPILER_SYSROOT \"${CMAKE_HIP_COMPILER_SYSROOT}\")")
else()
set(_SET_CMAKE_HIP_COMPILER_SYSROOT "")
endif()
if(CMAKE_HIP_COMPILER_ARCHITECTURE_ID)
set(_SET_CMAKE_HIP_COMPILER_ARCHITECTURE_ID
"set(CMAKE_HIP_COMPILER_ARCHITECTURE_ID ${CMAKE_HIP_COMPILER_ARCHITECTURE_ID})")
else()
set(_SET_CMAKE_HIP_COMPILER_ARCHITECTURE_ID "")
endif()
if(MSVC_HIP_ARCHITECTURE_ID)
set(SET_MSVC_HIP_ARCHITECTURE_ID
"set(MSVC_HIP_ARCHITECTURE_ID ${MSVC_HIP_ARCHITECTURE_ID})")
endif()
if(NOT DEFINED CMAKE_HIP_ARCHITECTURES)
set(CMAKE_HIP_ARCHITECTURES "OFF" CACHE STRING "HIP architectures")
endif()
# configure variables set in this file for fast reload later on
configure_file(${CMAKE_ROOT}/Modules/CMakeHIPCompiler.cmake.in
${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPCompiler.cmake
@ONLY
)
set(CMAKE_HIP_COMPILER_ENV_VAR "HIPCXX")

View File

@@ -0,0 +1,59 @@
set(CMAKE_HIP_COMPILER "@CMAKE_HIP_COMPILER@")
set(CMAKE_HIP_COMPILER_ID "@CMAKE_HIP_COMPILER_ID@")
set(CMAKE_HIP_COMPILER_VERSION "@CMAKE_HIP_COMPILER_VERSION@")
set(CMAKE_HIP_STANDARD_COMPUTED_DEFAULT "@CMAKE_HIP_STANDARD_COMPUTED_DEFAULT@")
set(CMAKE_HIP_COMPILE_FEATURES "@CMAKE_HIP_COMPILE_FEATURES@")
set(CMAKE_HIP98_COMPILE_FEATURES "@CMAKE_HIP03_COMPILE_FEATURES@")
set(CMAKE_HIP11_COMPILE_FEATURES "@CMAKE_HIP11_COMPILE_FEATURES@")
set(CMAKE_HIP14_COMPILE_FEATURES "@CMAKE_HIP14_COMPILE_FEATURES@")
set(CMAKE_HIP17_COMPILE_FEATURES "@CMAKE_HIP17_COMPILE_FEATURES@")
set(CMAKE_HIP20_COMPILE_FEATURES "@CMAKE_HIP20_COMPILE_FEATURES@")
set(CMAKE_HIP23_COMPILE_FEATURES "@CMAKE_HIP23_COMPILE_FEATURES@")
set(CMAKE_HIP_PLATFORM_ID "@CMAKE_HIP_PLATFORM_ID@")
set(CMAKE_HIP_SIMULATE_ID "@CMAKE_HIP_SIMULATE_ID@")
set(CMAKE_HIP_COMPILER_FRONTEND_VARIANT "@CMAKE_HIP_COMPILER_FRONTEND_VARIANT@")
set(CMAKE_HIP_SIMULATE_VERSION "@CMAKE_HIP_SIMULATE_VERSION@")
@SET_MSVC_HIP_ARCHITECTURE_ID@
@_SET_CMAKE_HIP_COMPILER_SYSROOT@
set(CMAKE_HIP_COMPILER_ENV_VAR "HIPCXX")
set(CMAKE_HIP_COMPILER_LOADED 1)
set(CMAKE_HIP_COMPILER_ID_RUN 1)
set(CMAKE_HIP_SOURCE_FILE_EXTENSIONS hip)
set(CMAKE_HIP_LINKER_PREFERENCE 15)
set(CMAKE_HIP_LINKER_PREFERENCE_PROPAGATES 1)
set(CMAKE_HIP_SIZEOF_DATA_PTR "@CMAKE_HIP_SIZEOF_DATA_PTR@")
set(CMAKE_HIP_COMPILER_ABI "@CMAKE_HIP_COMPILER_ABI@")
set(CMAKE_HIP_LIBRARY_ARCHITECTURE "@CMAKE_HIP_LIBRARY_ARCHITECTURE@")
if(CMAKE_HIP_SIZEOF_DATA_PTR)
set(CMAKE_SIZEOF_VOID_P "${CMAKE_HIP_SIZEOF_DATA_PTR}")
endif()
if(CMAKE_HIP_COMPILER_ABI)
set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_HIP_COMPILER_ABI}")
endif()
if(CMAKE_HIP_LIBRARY_ARCHITECTURE)
set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_HIP_LIBRARY_ARCHITECTURE@")
endif()
set(CMAKE_HIP_TOOLKIT_INCLUDE_DIRECTORIES "@CMAKE_HIP_TOOLKIT_INCLUDE_DIRECTORIES@")
set(CMAKE_HIP_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_HIP_IMPLICIT_INCLUDE_DIRECTORIES@")
set(CMAKE_HIP_IMPLICIT_LINK_LIBRARIES "@CMAKE_HIP_IMPLICIT_LINK_LIBRARIES@")
set(CMAKE_HIP_IMPLICIT_LINK_DIRECTORIES "@CMAKE_HIP_IMPLICIT_LINK_DIRECTORIES@")
set(CMAKE_HIP_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_HIP_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
set(CMAKE_HIP_COMPILER_DEVICE_LIBRARY_ROOT_DIR "@CMAKE_HIP_COMPILER_DEVICE_LIBRARY_ROOT_DIR@")
@_SET_CMAKE_HIP_DEVICE_LIBRARY_INCLUSION@
set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_HIP_COMPILER_AR "@CMAKE_HIP_COMPILER_AR@")
set(CMAKE_RANLIB "@CMAKE_RANLIB@")
set(CMAKE_HIP_COMPILER_RANLIB "@CMAKE_HIP_COMPILER_RANLIB@")
set(CMAKE_LINKER "@CMAKE_LINKER@")
set(CMAKE_MT "@CMAKE_MT@")

View File

@@ -0,0 +1,16 @@
#ifndef __HIP__
# error "A C or C++ compiler has been selected for HIP"
#endif
#include "CMakeCompilerABI.h"
int main(int argc, char* argv[])
{
int require = 0;
require += info_sizeof_dptr[argc];
#if defined(ABI_ID)
require += info_abi[argc];
#endif
(void)argv;
return require;
}

View File

@@ -0,0 +1,54 @@
#ifndef __HIP__
# error "A C or C++ compiler has been selected for HIP"
#endif
@CMAKE_HIP_COMPILER_ID_CONTENT@
/* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
#ifdef SIMULATE_ID
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
#endif
@CMAKE_HIP_COMPILER_ID_PLATFORM_CONTENT@
@CMAKE_HIP_COMPILER_ID_ERROR_FOR_TEST@
const char* info_language_dialect_default = "INFO" ":" "dialect_default["
#if __cplusplus > 202002L
"23"
#elif __cplusplus > 201703L
"20"
#elif __cplusplus >= 201703L
"17"
#elif __cplusplus >= 201402L
"14"
#elif __cplusplus >= 201103L
"11"
#else
"98"
#endif
"]";
/*--------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
int require = 0;
require += info_compiler[argc];
require += info_platform[argc];
#ifdef COMPILER_VERSION_MAJOR
require += info_version[argc];
#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
#ifdef SIMULATE_VERSION_MAJOR
require += info_simulate_version[argc];
#endif
require += info_language_dialect_default[argc];
(void)argv;
return require;
}

View File

@@ -0,0 +1,132 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
if(UNIX)
set(CMAKE_HIP_OUTPUT_EXTENSION .o)
else()
set(CMAKE_HIP_OUTPUT_EXTENSION .obj)
endif()
set(CMAKE_INCLUDE_FLAG_HIP "-I")
# Load compiler-specific information.
if(CMAKE_HIP_COMPILER_ID)
include(Compiler/${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL)
endif()
# load the system- and compiler specific files
if(CMAKE_HIP_COMPILER_ID)
# load a hardware specific file, mostly useful for embedded compilers
if(CMAKE_SYSTEM_PROCESSOR)
include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_HIP_COMPILER_ID}-HIP-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
endif()
include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_HIP_COMPILER_ID}-HIP OPTIONAL)
endif()
if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG)
set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
endif()
if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP)
set(CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
endif()
if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG)
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
endif()
if(NOT DEFINED CMAKE_EXE_EXPORTS_HIP_FLAG)
set(CMAKE_EXE_EXPORTS_HIP_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
endif()
if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG)
set(CMAKE_SHARED_LIBRARY_SONAME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
endif()
if(NOT CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG)
set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG})
endif()
if(NOT CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP)
set(CMAKE_EXECUTABLE_RUNTIME_HIP_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_HIP_FLAG_SEP})
endif()
if(NOT CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG)
set(CMAKE_EXECUTABLE_RPATH_LINK_HIP_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_HIP_FLAG})
endif()
if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_HIP_WITH_RUNTIME_PATH)
set(CMAKE_SHARED_LIBRARY_LINK_HIP_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
endif()
# for most systems a module is the same as a shared library
# so unless the variable CMAKE_MODULE_EXISTS is set just
# copy the values from the LIBRARY variables
if(NOT CMAKE_MODULE_EXISTS)
set(CMAKE_SHARED_MODULE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_HIP_FLAGS})
set(CMAKE_SHARED_MODULE_CREATE_HIP_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS})
endif()
# add the flags to the cache based
# on the initial values computed in the platform/*.cmake files
# use _INIT variables so that this only happens the first time
# and you can set these flags in the cmake cache
set(CMAKE_HIP_FLAGS_INIT "$ENV{HIPFLAGS} ${CMAKE_HIP_FLAGS_INIT}")
cmake_initialize_per_config_variable(CMAKE_HIP_FLAGS "Flags used by the HIP compiler")
if(CMAKE_HIP_STANDARD_LIBRARIES_INIT)
set(CMAKE_HIP_STANDARD_LIBRARIES "${CMAKE_HIP_STANDARD_LIBRARIES_INIT}"
CACHE STRING "Libraries linked by default with all HIP applications.")
mark_as_advanced(CMAKE_HIP_STANDARD_LIBRARIES)
endif()
if(NOT CMAKE_HIP_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_HIP_COMPILER_LAUNCHER})
set(CMAKE_HIP_COMPILER_LAUNCHER "$ENV{CMAKE_HIP_COMPILER_LAUNCHER}"
CACHE STRING "Compiler launcher for HIP.")
endif()
include(CMakeCommonLanguageInclude)
# now define the following rules:
# CMAKE_HIP_CREATE_SHARED_LIBRARY
# CMAKE_HIP_CREATE_SHARED_MODULE
# CMAKE_HIP_COMPILE_OBJECT
# CMAKE_HIP_LINK_EXECUTABLE
# create a shared library
if(NOT CMAKE_HIP_CREATE_SHARED_LIBRARY)
set(CMAKE_HIP_CREATE_SHARED_LIBRARY
"<CMAKE_HIP_COMPILER> <CMAKE_SHARED_LIBRARY_HIP_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()
# create a shared module copy the shared library rule by default
if(NOT CMAKE_HIP_CREATE_SHARED_MODULE)
set(CMAKE_HIP_CREATE_SHARED_MODULE ${CMAKE_HIP_CREATE_SHARED_LIBRARY})
endif()
# Create a static archive incrementally for large object file counts.
if(NOT DEFINED CMAKE_HIP_ARCHIVE_CREATE)
set(CMAKE_HIP_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if(NOT DEFINED CMAKE_HIP_ARCHIVE_APPEND)
set(CMAKE_HIP_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if(NOT DEFINED CMAKE_HIP_ARCHIVE_FINISH)
set(CMAKE_HIP_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
endif()
# compile a HIP file into an object file
if(NOT CMAKE_HIP_COMPILE_OBJECT)
set(CMAKE_HIP_COMPILE_OBJECT
"<CMAKE_HIP_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> ${_CMAKE_COMPILE_AS_HIP_FLAG} -c <SOURCE>")
endif()
# compile a cu file into an executable
if(NOT CMAKE_HIP_LINK_EXECUTABLE)
set(CMAKE_HIP_LINK_EXECUTABLE
"<CMAKE_HIP_COMPILER> <FLAGS> <CMAKE_HIP_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif()
set(CMAKE_HIP_INFORMATION_LOADED 1)

View File

@@ -0,0 +1,98 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
if(CMAKE_HIP_COMPILER_FORCED)
# The compiler configuration was forced by the user.
# Assume the user has configured all compiler information.
set(CMAKE_HIP_COMPILER_WORKS TRUE)
return()
endif()
set(__CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS}")
string(APPEND CMAKE_HIP_FLAGS "--cuda-host-only")
include(CMakeTestCompilerCommon)
# work around enforced code signing and / or missing executable target type
set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
endif()
# Remove any cached result from an older CMake version.
# We now store this in CMakeHIPCompiler.cmake.
unset(CMAKE_HIP_COMPILER_WORKS CACHE)
# Try to identify the ABI and configure it into CMakeHIPCompiler.cmake
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
CMAKE_DETERMINE_COMPILER_ABI(HIP ${CMAKE_ROOT}/Modules/CMakeHIPCompilerABI.hip)
if(CMAKE_HIP_ABI_COMPILED)
# The compiler worked so skip dedicated test below.
set(CMAKE_HIP_COMPILER_WORKS TRUE)
message(STATUS "Check for working HIP compiler: ${CMAKE_HIP_COMPILER} - skipped")
endif()
# This file is used by EnableLanguage in cmGlobalGenerator to
# determine that the selected C++ compiler can actually compile
# and link the most basic of programs. If not, a fatal error
# is set and cmake stops processing commands and will not generate
# any makefiles or projects.
if(NOT CMAKE_HIP_COMPILER_WORKS)
PrintTestCompilerStatus("HIP")
__TestCompiler_setTryCompileTargetType()
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testHIPCompiler.hip
"#ifndef __HIP__\n"
"# error \"The CMAKE_HIP_COMPILER is set to a C/CXX compiler\"\n"
"#endif\n"
"int main(){return 0;}\n")
try_compile(CMAKE_HIP_COMPILER_WORKS ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testHIPCompiler.hip
OUTPUT_VARIABLE __CMAKE_HIP_COMPILER_OUTPUT)
# Move result from cache to normal variable.
set(CMAKE_HIP_COMPILER_WORKS ${CMAKE_HIP_COMPILER_WORKS})
unset(CMAKE_HIP_COMPILER_WORKS CACHE)
__TestCompiler_restoreTryCompileTargetType()
if(NOT CMAKE_HIP_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the HIP compiler works failed with "
"the following output:\n${__CMAKE_HIP_COMPILER_OUTPUT}\n\n")
string(REPLACE "\n" "\n " _output "${__CMAKE_HIP_COMPILER_OUTPUT}")
message(FATAL_ERROR "The HIP compiler\n \"${CMAKE_HIP_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
"with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
endif()
PrintTestCompilerResult(CHECK_PASS "works")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the HIP compiler works passed with "
"the following output:\n${__CMAKE_HIP_COMPILER_OUTPUT}\n\n")
endif()
set(CMAKE_HIP_FLAGS "${__CMAKE_HIP_FLAGS}")
unset(__CMAKE_HIP_FLAGS)
# Try to identify the compiler features
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
CMAKE_DETERMINE_COMPILE_FEATURES(HIP)
# Re-configure to save learned information.
configure_file(
${CMAKE_ROOT}/Modules/CMakeHIPCompiler.cmake.in
${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPCompiler.cmake
@ONLY
)
include(${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPCompiler.cmake)
if(CMAKE_HIP_SIZEOF_DATA_PTR)
foreach(f ${CMAKE_HIP_ABI_FILES})
include(${f})
endforeach()
unset(CMAKE_HIP_ABI_FILES)
endif()
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
unset(__CMAKE_HIP_COMPILER_OUTPUT)

View File

@@ -170,3 +170,19 @@ macro(cmake_record_cuda_compile_features)
unset(CMAKE_CUDA03_STANDARD__HAS_FULL_SUPPORT)
endif()
endmacro()
macro(cmake_record_hip_compile_features)
set(_result 0)
if(_result EQUAL 0 AND DEFINED CMAKE_HIP23_STANDARD_COMPILE_OPTION)
_has_compiler_features_hip(23)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_HIP20_STANDARD_COMPILE_OPTION)
_has_compiler_features_hip(20)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_HIP17_STANDARD_COMPILE_OPTION)
_has_compiler_features_hip(17)
endif()
_has_compiler_features_hip(14)
_has_compiler_features_hip(11)
_has_compiler_features_hip(98)
endmacro()

View File

@@ -0,0 +1,16 @@
include(Compiler/Clang)
__compiler_clang(HIP)
__compiler_clang_cxx_standards(HIP)
set(_CMAKE_COMPILE_AS_HIP_FLAG "-x hip")
set(_CMAKE_HIP_RDC_FLAG "-fgpu-rdc")
if(NOT "x${CMAKE_HIP_SIMULATE_ID}" STREQUAL "xMSVC")
set(CMAKE_HIP_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
string(APPEND CMAKE_HIP_FLAGS_DEBUG_INIT " -O")
endif()
set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "SHARED")
set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "")
set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "")

View File

@@ -0,0 +1,45 @@
include(Compiler/ROCMClang)
__compiler_rocmclang(HIP)
set(_CMAKE_COMPILE_AS_HIP_FLAG "-x hip")
set(_CMAKE_HIP_RDC_FLAG "-fgpu-rdc")
if(NOT "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC")
set(CMAKE_HIP_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
string(APPEND CMAKE_HIP_FLAGS_DEBUG_INIT " -O")
endif()
if(CMAKE_HIP_SIMULATE_ID STREQUAL "GNU")
set(CMAKE_HIP_LINKER_WRAPPER_FLAG "-Wl,")
set(CMAKE_HIP_LINKER_WRAPPER_FLAG_SEP ",")
elseif(CMAKE_HIP_SIMULATE_ID STREQUAL "Clang")
set(CMAKE_HIP_LINKER_WRAPPER_FLAG "-Xlinker" " ")
set(CMAKE_HIP_LINKER_WRAPPER_FLAG_SEP)
endif()
if(NOT CMAKE_HIP_COMPILER_VERSION VERSION_LESS 1.0)
set(CMAKE_HIP98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_HIP98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
set(CMAKE_HIP98_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_HIP11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_HIP11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
set(CMAKE_HIP11_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_HIP14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_HIP14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
set(CMAKE_HIP14_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_HIP17_STANDARD_COMPILE_OPTION "-std=c++17")
set(CMAKE_HIP17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
set(CMAKE_HIP17_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_HIP20_STANDARD_COMPILE_OPTION "-std=c++20")
set(CMAKE_HIP20_EXTENSION_COMPILE_OPTION "-std=gnu++20")
endif()
set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "SHARED")
set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "")
set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "")
__compiler_check_default_language_standard(HIP 3.5 11)

View File

@@ -99,6 +99,16 @@ macro(_record_compiler_features_cuda std)
unset(lang_level_has_features)
endmacro()
macro(_record_compiler_features_hip std)
list(APPEND CMAKE_HIP${std}_COMPILE_FEATURES hip_std_${std})
get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_HIP${std}_KNOWN_FEATURES)
if(lang_level_has_features)
_record_compiler_features(HIP "${CMAKE_HIP${std}_STANDARD_COMPILE_OPTION}" CMAKE_HIP${std}_COMPILE_FEATURES)
endif()
unset(lang_level_has_features)
endmacro()
macro(_has_compiler_features lang level compile_flags feature_list)
# presume all known features are supported
get_property(known_features GLOBAL PROPERTY CMAKE_${lang}${level}_KNOWN_FEATURES)
@@ -117,3 +127,7 @@ macro(_has_compiler_features_cuda std)
list(APPEND CMAKE_CUDA${std}_COMPILE_FEATURES cuda_std_${std})
_has_compiler_features(CUDA ${std} "${CMAKE_CUDA${std}_STANDARD_COMPILE_OPTION}" CMAKE_CUDA${std}_COMPILE_FEATURES)
endmacro()
macro(_has_compiler_features_hip std)
list(APPEND CMAKE_HIP${std}_COMPILE_FEATURES hip_std_${std})
_has_compiler_features(HIP ${std} "${CMAKE_HIP${std}_STANDARD_COMPILE_OPTION}" CMAKE_HIP${std}_COMPILE_FEATURES)
endmacro()