diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 02a2d0ab4..55040b64b 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -231,8 +231,9 @@ if (NOT WIN32) endif() if (NOT WIN32) - if (BUILD_WITH_ROCTX) - target_link_libraries(rocsparse-bench PRIVATE -lroctx64) + if(BUILD_WITH_ROCTX) + find_package(roctx REQUIRED) + target_link_libraries(rocsparse-bench PRIVATE roctx::roctx) target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index d26a10cdf..2fe4abca2 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -415,8 +415,9 @@ if (NOT WIN32) endif() if (NOT WIN32) - if (BUILD_WITH_ROCTX) - target_link_libraries(rocsparse-test PRIVATE -lroctx64) + if(BUILD_WITH_ROCTX) + find_package(roctx REQUIRED) + target_link_libraries(rocsparse-test PRIVATE roctx::roctx) target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) endif() endif() diff --git a/cmake/Findroctx.cmake b/cmake/Findroctx.cmake new file mode 100644 index 000000000..33f692161 --- /dev/null +++ b/cmake/Findroctx.cmake @@ -0,0 +1,72 @@ +# ######################################################################## +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop- +# ies of the Software, and to permit persons to whom the Software is furnished +# to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM- +# PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE- +# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# ######################################################################## + +#[=======================================================================[.rst: +Findroctx +---------- + +Find the roctx library + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the :prop_tgt:`IMPORTED` target if roctx is found: + +``roctx::roctx`` + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``ROCTX_INCLUDE_DIR`` +``ROCTX_LIBRARY`` +``ROCTX_LIBRARIES`` +``ROCTX_FOUND`` + +#]=======================================================================] + +find_path(ROCTX_INCLUDE_DIR + NAMES roctx.h + PATH_SUFFIXES roctracer + ) +find_library(ROCTX_LIBRARY roctx64) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(roctx ROCTX_INCLUDE_DIR ROCTX_LIBRARY) + +if(ROCTX_FOUND) + if(NOT DEFINED ROCTX_LIBRARIES) + set(ROCTX_LIBRARIES ${ROCTX_LIBRARY}) + endif() + + if(NOT TARGET roctx::roctx) + add_library(roctx::roctx UNKNOWN IMPORTED) + + set_target_properties(roctx::roctx PROPERTIES + IMPORTED_LOCATION "${ROCTX_LIBRARY}" + ) + set_target_properties(roctx::roctx PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${ROCTX_INCLUDE_DIR}" + ) + endif() +endif() diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 902ffbe55..43eabf421 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -95,7 +95,8 @@ endif() if (NOT WIN32) if (BUILD_SHARED_LIBS AND BUILD_WITH_ROCTX) - target_link_libraries(rocsparse PRIVATE -lroctx64) + find_package(roctx REQUIRED) + target_link_libraries(rocsparse PRIVATE roctx::roctx) target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) endif() endif()