From f9a373b956fee878494d6e20eafb0ab38f2d6014 Mon Sep 17 00:00:00 2001
From: Mystro256 <alexjnewt@hotmail.com>
Date: Tue, 18 Jan 2022 12:50:05 -0500
Subject: [PATCH] Use FHS compliant install
FHS does not allow installing to "amdgcn", but "LIBDIR/amdgcn" appears
to be acceptable to the FHS and distros. This logic uses GNUInstallDirs
to detect the LIBDIR instead of hardcoding it to "lib".
E.g. Fedora/Redhat use lib64 instead of lib.
---
cmake/OCL.cmake | 3 ++-
cmake/Packages.cmake | 5 +++--
test/constant_folding/CMakeLists.txt | 2 ++
test/constant_folding/RunConstantFoldTest.cmake | 1 +
4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/cmake/OCL.cmake b/cmake/OCL.cmake
index cc533be..b27eb5e 100644
--- a/cmake/OCL.cmake
+++ b/cmake/OCL.cmake
@@ -10,6 +10,7 @@
# configure_file and we are included from multiple places. To get around this
# we `file(WRITE)` a file with an @variable reference and `configure_file` it.
cmake_policy(SET CMP0053 OLD)
+include(GNUInstallDirs)
if (WIN32)
set(EXE_SUFFIX ".exe")
@@ -45,7 +46,7 @@ set (BC_EXT .bc)
set (LIB_SUFFIX ".lib${BC_EXT}")
set (STRIP_SUFFIX ".strip${BC_EXT}")
set (FINAL_SUFFIX "${BC_EXT}")
-set (INSTALL_ROOT_SUFFIX "amdgcn/bitcode")
+set (INSTALL_ROOT_SUFFIX "${CMAKE_INSTALL_LIBDIR}/amdgcn/bitcode")
# Set `inc_options` to contain Clang command-line for include directories for
# current source directory.
diff --git a/cmake/Packages.cmake b/cmake/Packages.cmake
index 715ed95..e948e96 100644
--- a/cmake/Packages.cmake
+++ b/cmake/Packages.cmake
@@ -1,4 +1,5 @@
-set(PACKAGE_PREFIX lib/cmake/AMDDeviceLibs)
+include(GNUInstallDirs)
+set(PACKAGE_PREFIX ${CMAKE_INSTALL_LIBDIR}/cmake/AMDDeviceLibs)
# Generate the build-tree package.
# We know the absolute path to the build tree, so we leave
@@ -16,7 +17,7 @@ configure_file(AMDDeviceLibsConfig.cmake.in
@ONLY)
-set(install_path_suffix "amdgcn/bitcode")
+set(install_path_suffix "${CMAKE_INSTALL_LIBDIR}/amdgcn/bitcode")
# Generate the install-tree package.
# We do not know the absolute path to the intall tree until we are installed,
diff --git a/test/constant_folding/CMakeLists.txt b/test/constant_folding/CMakeLists.txt
index 317bc8d..f8555f6 100644
--- a/test/constant_folding/CMakeLists.txt
+++ b/test/constant_folding/CMakeLists.txt
@@ -4,6 +4,7 @@
## This file is distributed under the University of Illinois Open Source
## License. See LICENSE.TXT for details.
##===--------------------------------------------------------------------------
+include(GNUInstallDirs)
if(TARGET FileCheck)
set(FILECHECK_BIN $<TARGET_FILE:FileCheck>)
@@ -30,6 +31,7 @@ function(add_constant_fold_test name)
-DFILECHECK_BIN=${FILECHECK_BIN}
-DOUTPUT_FILE=output.${name}.ll
-DINPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}.cl
+ -DAMDGCN_BITCODES=${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/amdgcn/bitcode
-DTEST_CPU=gfx900
-P ${CMAKE_CURRENT_SOURCE_DIR}/RunConstantFoldTest.cmake)
endfunction()
diff --git a/test/constant_folding/RunConstantFoldTest.cmake b/test/constant_folding/RunConstantFoldTest.cmake
index 9045bbd..2ce414c 100644
--- a/test/constant_folding/RunConstantFoldTest.cmake
+++ b/test/constant_folding/RunConstantFoldTest.cmake
@@ -16,6 +16,7 @@ execute_process(COMMAND
-target amdgcn-amd-amdhsa -mcpu=${TEST_CPU}
-Xclang -finclude-default-header
--rocm-path=${BINARY_DIR}
+ --rocm-device-lib-path=${AMDGCN_BITCODES}
-mllvm -amdgpu-simplify-libcall=0
-o ${OUTPUT_FILE} ${INPUT_FILE}
RESULT_VARIABLE CLANG_RESULT
--
2.35.3