From d0c2770cdecbd5c08a0e9888fe2bc805c75722b3 Mon Sep 17 00:00:00 2001 From: Kent Russell Date: Wed, 5 Apr 2023 13:49:01 -0400 Subject: [PATCH] CMakeLists: Use pkgconfig more effectively with DRM_DIR Instead of hard-coding lib64 and other include locations, just prepend the DRM_DIR to the beginning of the CMake prefix path. Then let pkgconfig find the package, the same way that it would if DRM_DIR wasn't set. DRM_DIR takes precedence, but the default paths will be used if DRM_DIR isn't set, or doesn't point to where libdrm is housed Note that /lib and /lib/$ARCH aren't required for DRM_DIR, just the path to the root folder for the package (e.g. /opt/amdgpu instead of /opt/amdgpu/lib or /opt/amdgpu/lib64 or /opt/amdgpu/lib/x86_64-linux-gnu etc) Change-Id: I56767db28476d14e3fa77be1089c3904e2a32450 --- CMakeLists.txt | 17 +++++------------ tests/kfdtest/CMakeLists.txt | 16 ++++------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b90a045d..e7a9a361be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,20 +166,13 @@ message(STATUS "NUMA:" ${NUMA}) ## If environment variable DRM_DIR is set, the script ## will pick up the corresponding libraries from that path. -if( DEFINED ENV{DRM_DIR} ) -#assume header files and libraries are under the same path - set ( DRM_DIR $ENV{DRM_DIR} ) - set ( DRM_INCLUDE_DIRS ${DRM_DIR}/include ) - link_directories(${DRM_DIR}/lib64) - set ( DRM_LIBRARIES drm ) - set ( DRM_AMDGPU_LIBRARIES drm_amdgpu ) -else() +list (PREPEND CMAKE_PREFIX_PATH "${DRM_DIR}") + # The module name passed to pkg_check_modules() is determined by the # name of file *.pc - pkg_check_modules(DRM REQUIRED libdrm) - pkg_check_modules(DRM_AMDGPU REQUIRED libdrm_amdgpu) - include_directories(${DRM_AMDGPU_INCLUDE_DIRS}) -endif() +pkg_check_modules(DRM REQUIRED libdrm) +pkg_check_modules(DRM_AMDGPU REQUIRED libdrm_amdgpu) +include_directories(${DRM_AMDGPU_INCLUDE_DIRS}) include_directories(${DRM_INCLUDE_DIRS}) target_link_libraries ( ${HSAKMT_TARGET} diff --git a/tests/kfdtest/CMakeLists.txt b/tests/kfdtest/CMakeLists.txt index ba1d99be51..61c9b84f60 100644 --- a/tests/kfdtest/CMakeLists.txt +++ b/tests/kfdtest/CMakeLists.txt @@ -92,20 +92,12 @@ set (CPACK_RPM_PACKAGE_REQUIRES "rocm-core") find_package(PkgConfig) -if( DEFINED ENV{DRM_DIR} ) -#assume header files and libraries are under the same path - set ( DRM_DIR $ENV{DRM_DIR} ) - set ( DRM_INCLUDE_DIRS ${DRM_DIR}/include ) - link_directories(${DRM_DIR}/lib64) - set ( DRM_LIBRARIES drm ) - set ( DRM_AMDGPU_LIBRARIES drm_amdgpu ) -else() +list (PREPEND CMAKE_PREFIX_PATH "${DRM_DIR}") # The module name passed to pkg_check_modules() is determined by the # name of file *.pc - pkg_check_modules(DRM REQUIRED libdrm) - pkg_check_modules(DRM_AMDGPU REQUIRED libdrm_amdgpu) - include_directories(${DRM_AMDGPU_INCLUDE_DIRS}) -endif() +pkg_check_modules(DRM REQUIRED libdrm) +pkg_check_modules(DRM_AMDGPU REQUIRED libdrm_amdgpu) +include_directories(${DRM_AMDGPU_INCLUDE_DIRS}) if( DEFINED ENV{LIBHSAKMT_PATH} ) set ( LIBHSAKMT_PATH $ENV{LIBHSAKMT_PATH} )