diff --git a/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-sdk-config.cmake.in b/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-sdk-config.cmake.in index b4b2d03ca6..1bc2e153b2 100644 --- a/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-sdk-config.cmake.in +++ b/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-sdk-config.cmake.in @@ -25,8 +25,10 @@ set_and_check(@PROJECT_NAME@-sdk_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") get_filename_component(@PROJECT_NAME@-sdk_ROOT_DIR ${@PROJECT_NAME@-sdk_INCLUDE_DIR} PATH) # extra validation -set_and_check(@PROJECT_NAME@_INCLUDE_ROCPROFILER_SDK_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@/@PROJECT_NAME@-sdk") -set_and_check(@PROJECT_NAME@_LIB_ROCPROFILER_SDK_DIR "@PACKAGE_LIB_INSTALL_DIR@/@PROJECT_NAME@-sdk") +set_and_check(@PROJECT_NAME@_INCLUDE_ROCPROFILER_SDK_DIR + "@PACKAGE_INCLUDE_INSTALL_DIR@/@PROJECT_NAME@-sdk") +set_and_check(@PROJECT_NAME@_LIB_ROCPROFILER_SDK_DIR + "@PACKAGE_LIB_INSTALL_DIR@/@PROJECT_NAME@-sdk") set(@PROJECT_NAME@-sdk_LIBRARIES) @@ -34,7 +36,13 @@ set(@PROJECT_NAME@-sdk_LIBRARIES) add_library(@PROJECT_NAME@::@PROJECT_NAME@ INTERFACE IMPORTED) add_library(@PROJECT_NAME@-sdk::@PROJECT_NAME@-sdk ALIAS @PROJECT_NAME@::@PROJECT_NAME@) -if(@PROJECT_NAME@_BUILD_TREE AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-sdk-build-config.cmake") +target_include_directories(@PROJECT_NAME@::@PROJECT_NAME@ + INTERFACE "${@PROJECT_NAME@-sdk_INCLUDE_DIR}") +target_link_directories(@PROJECT_NAME@::@PROJECT_NAME@ INTERFACE + "${@PROJECT_NAME@-sdk_LIB_DIR}") + +if(@PROJECT_NAME@_BUILD_TREE + AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-sdk-build-config.cmake") include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-sdk-build-config.cmake") else() find_package( @@ -87,15 +95,23 @@ else() @hip_DIR@ @rocm_version_DIR@) + include( + "${@PROJECT_NAME@-sdk_CMAKE_DIR}/@PROJECT_NAME@-sdk-config-nolink-target.cmake") + + add_library(@PROJECT_NAME@-sdk::@PROJECT_NAME@-sdk-external-nolink INTERFACE IMPORTED) + include("${@PROJECT_NAME@-sdk_CMAKE_DIR}/@PROJECT_NAME@-sdk-library-targets.cmake") + @PROJECT_NAME@_config_nolink_target(@PROJECT_NAME@-sdk::@PROJECT_NAME@-sdk-external-nolink hip::host) + @PROJECT_NAME@_config_nolink_target(@PROJECT_NAME@-sdk::@PROJECT_NAME@-sdk-external-nolink hsa-runtime64::hsa-runtime64) + @PROJECT_NAME@_config_nolink_target(@PROJECT_NAME@-sdk::@PROJECT_NAME@-sdk-external-nolink amd_comgr) + # Library dependencies foreach(TARG @PROJECT_BUILD_TARGETS@) set(TARG @PROJECT_NAME@::@PROJECT_NAME@-${TARG}) if(NOT @PROJECT_NAME@_FIND_COMPONENTS) list(APPEND @PROJECT_NAME@-sdk_LIBRARIES ${TARG}) - target_link_libraries(@PROJECT_NAME@::@PROJECT_NAME@ - INTERFACE ${TARG}) + target_link_libraries(@PROJECT_NAME@::@PROJECT_NAME@ INTERFACE ${TARG}) endif() endforeach() @@ -111,6 +127,10 @@ else() endif() endforeach() endif() + + target_link_libraries( + @PROJECT_NAME@::@PROJECT_NAME@ + INTERFACE @PROJECT_NAME@-sdk::@PROJECT_NAME@-sdk-external-nolink) endif() include(FindPackageHandleStandardArgs) @@ -118,6 +138,7 @@ find_package_handle_standard_args( @PROJECT_NAME@-sdk FOUND_VAR @PROJECT_NAME@-sdk_FOUND VERSION_VAR @PROJECT_NAME@-sdk_VERSION - REQUIRED_VARS @PROJECT_NAME@-sdk_ROOT_DIR @PROJECT_NAME@-sdk_INCLUDE_DIR @PROJECT_NAME@-sdk_LIB_DIR - @PROJECT_NAME@-sdk_LIBRARIES @PROJECT_NAME@-sdk_VERSION + REQUIRED_VARS + @PROJECT_NAME@-sdk_ROOT_DIR @PROJECT_NAME@-sdk_INCLUDE_DIR + @PROJECT_NAME@-sdk_LIB_DIR @PROJECT_NAME@-sdk_LIBRARIES @PROJECT_NAME@-sdk_VERSION HANDLE_COMPONENTS HANDLE_VERSION_RANGE) diff --git a/projects/rocprofiler-sdk/cmake/rocprofiler_config_install.cmake b/projects/rocprofiler-sdk/cmake/rocprofiler_config_install.cmake index 8b860d709e..fc2c4a32ce 100644 --- a/projects/rocprofiler-sdk/cmake/rocprofiler_config_install.cmake +++ b/projects/rocprofiler-sdk/cmake/rocprofiler_config_install.cmake @@ -42,10 +42,16 @@ write_basic_package_version_file( VERSION ${PROJECT_VERSION} COMPATIBILITY SameMinorVersion) +configure_file( + ${PROJECT_SOURCE_DIR}/cmake/rocprofiler_config_nolink_target.cmake + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}-sdk/${PROJECT_NAME}-sdk-config-nolink-target.cmake + COPYONLY) + install( FILES ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}-sdk/${PROJECT_NAME}-sdk-config.cmake ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}-sdk/${PROJECT_NAME}-sdk-config-version.cmake + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}-sdk/${PROJECT_NAME}-sdk-config-nolink-target.cmake DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}-sdk COMPONENT development) diff --git a/projects/rocprofiler-sdk/cmake/rocprofiler_config_interfaces.cmake b/projects/rocprofiler-sdk/cmake/rocprofiler_config_interfaces.cmake index 3698e19af1..8e8534e485 100644 --- a/projects/rocprofiler-sdk/cmake/rocprofiler_config_interfaces.cmake +++ b/projects/rocprofiler-sdk/cmake/rocprofiler_config_interfaces.cmake @@ -1,11 +1,14 @@ # include guard include_guard(DIRECTORY) +include(rocprofiler_config_nolink_target) + # ######################################################################################## # # External Packages are found here # # ######################################################################################## + target_include_directories( rocprofiler-headers INTERFACE $ @@ -41,6 +44,7 @@ endif() # Threading # # ----------------------------------------------------------------------------------------# + set(CMAKE_THREAD_PREFER_PTHREAD ON) set(THREADS_PREFER_PTHREAD_FLAG OFF) @@ -65,6 +69,7 @@ endif() # dynamic linking (dl) and runtime (rt) libraries # # ----------------------------------------------------------------------------------------# + foreach(_LIB dl rt) find_library(${_LIB}_LIBRARY NAMES ${_LIB}) find_package_handle_standard_args(${_LIB}-library REQUIRED_VARS ${_LIB}_LIBRARY) @@ -93,6 +98,7 @@ endif() # HIP # # ----------------------------------------------------------------------------------------# + find_package(rocm_version) if(rocm_version_FOUND) @@ -103,12 +109,14 @@ endif() find_package(hip REQUIRED CONFIG) target_link_libraries(rocprofiler-hip INTERFACE hip::host) +rocprofiler_config_nolink_target(rocprofiler-hip-nolink hip::host) # ----------------------------------------------------------------------------------------# # # HSA runtime # # ----------------------------------------------------------------------------------------# + find_package( hsa-runtime64 REQUIRED @@ -127,12 +135,15 @@ list(GET HSA_RUNTIME_VERSION 0 HSA_RUNTIME_VERSION_MAJOR) list(GET HSA_RUNTIME_VERSION 1 HSA_RUNTIME_VERSION_MINOR) target_link_libraries(rocprofiler-hsa-runtime INTERFACE hsa-runtime64::hsa-runtime64) +rocprofiler_config_nolink_target(rocprofiler-hsa-runtime-nolink + hsa-runtime64::hsa-runtime64) # ----------------------------------------------------------------------------------------# # # amd comgr # # ----------------------------------------------------------------------------------------# + find_package( amd_comgr REQUIRED @@ -153,6 +164,7 @@ target_link_libraries(rocprofiler-amd-comgr INTERFACE amd_comgr) # PTL (Parallel Tasking Library) # # ----------------------------------------------------------------------------------------# + target_link_libraries(rocprofiler-ptl INTERFACE PTL::ptl-static) # ----------------------------------------------------------------------------------------# @@ -160,6 +172,7 @@ target_link_libraries(rocprofiler-ptl INTERFACE PTL::ptl-static) # amd aql # # ----------------------------------------------------------------------------------------# + find_library( hsa-amd-aqlprofile64_library NAMES hsa-amd-aqlprofile64 hsa-amd-aqlprofile @@ -173,6 +186,7 @@ target_link_libraries(rocprofiler-hsa-aql INTERFACE ${hsa-amd-aqlprofile64_libra # drm # # ----------------------------------------------------------------------------------------# + find_path( drm_INCLUDE_DIR NAMES drm.h @@ -202,3 +216,11 @@ find_library( target_include_directories(rocprofiler-drm SYSTEM INTERFACE ${drm_INCLUDE_DIR} ${xf86drm_INCLUDE_DIR}) target_link_libraries(rocprofiler-drm INTERFACE ${drm_LIBRARY} ${drm_amdgpu_LIBRARY}) + +# ----------------------------------------------------------------------------------------# +# +# interface targets which emulate another interface target but do not link to the library. +# E.g. rocprofiler-hip-nolink has the include directories, compile definitions, and +# compile options of rocprofiler-hip but does not link to the HIP runtime library +# +# ----------------------------------------------------------------------------------------# diff --git a/projects/rocprofiler-sdk/cmake/rocprofiler_config_nolink_target.cmake b/projects/rocprofiler-sdk/cmake/rocprofiler_config_nolink_target.cmake new file mode 100644 index 0000000000..a32ce3d11c --- /dev/null +++ b/projects/rocprofiler-sdk/cmake/rocprofiler_config_nolink_target.cmake @@ -0,0 +1,60 @@ +# +# +# + +include_guard(GLOBAL) + +# function for copying most of a target's properties to another target except for the link +# related properties. Function is potentially recursive -- it should not be used if there +# is a cyclic target dependency. +function(rocprofiler_config_nolink_target _DST _SRC) + set(_LINK_LIBRARIES) + set(_INCLUDE_DIRS) + set(_COMPILE_DEFS) + set(_COMPILE_OPTS) + set(_COMPILE_FEATS) + + set(_PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) + foreach(_PROPERTY INCLUDE_DIRECTORIES LINK_LIBRARIES COMPILE_DEFINITIONS + COMPILE_OPTIONS COMPILE_FEATURES) + list(APPEND _PROPERTIES ${_PROPERTY} INTERFACE_${_PROPERTY}) + endforeach() + + foreach(_PROPERTY ${_PROPERTIES}) + # get the target property + get_target_property(_VAR ${_SRC} ${_PROPERTY}) + + if(NOT _VAR) + continue() + endif() + + if("${_PROPERTY}" MATCHES ".*LINK_LIBRARIES$") + list(APPEND _LINK_LIBRARIES ${_VAR}) + elseif("${_PROPERTY}" MATCHES ".*INCLUDE_DIRECTORIES$") + list(APPEND _INCLUDE_DIRS ${_VAR}) + elseif("${_PROPERTY}" MATCHES ".*COMPILE_DEFINITIONS$") + list(APPEND _COMPILE_DEFS ${_VAR}) + elseif("${_PROPERTY}" MATCHES ".*COMPILE_OPTIONS$") + list(APPEND _COMPILE_OPTS ${_VAR}) + elseif("${_PROPERTY}" MATCHES ".*COMPILE_FEATURES$") + list(APPEND _COMPILE_FEATS ${_VAR}) + else() + message(SEND_ERROR "Unexpected target property: ${_PROPERTY}") + endif() + endforeach() + + list(REMOVE_DUPLICATES _LINK_LIBRARIES) + list(REMOVE_DUPLICATES _INCLUDE_DIRS) + list(REMOVE_DUPLICATES _COMPILE_DEFS) + list(REMOVE_DUPLICATES _COMPILE_OPTS) + list(REMOVE_DUPLICATES _COMPILE_FEATS) + + target_include_directories(${_DST} SYSTEM INTERFACE ${_INCLUDE_DIRS}) + target_compile_definitions(${_DST} INTERFACE ${_COMPILE_DEFS}) + target_compile_options(${_DST} INTERFACE ${_COMPILE_OPTS}) + target_compile_features(${_DST} INTERFACE ${_COMPILE_FEATS}) + + foreach(_LIB ${_LINK_LIBRARIES} ${ARGN}) + rocprofiler_config_nolink_target(${_DST} ${_LIB}) + endforeach() +endfunction() diff --git a/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake b/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake index 24c7b3a221..6f3c382598 100644 --- a/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake +++ b/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake @@ -42,8 +42,8 @@ rocprofiler_add_interface_library(rocprofiler-dl "Build flags for dynamic linking library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-rt "Build flags for runtime library" INTERNAL) -rocprofiler_add_interface_library(rocprofiler-hip "HIP library") -rocprofiler_add_interface_library(rocprofiler-hsa-runtime "HSA runtime library") +rocprofiler_add_interface_library(rocprofiler-hip "HIP library" INTERNAL) +rocprofiler_add_interface_library(rocprofiler-hsa-runtime "HSA runtime library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-amd-comgr "AMD comgr library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-gtest "Google Test library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-glog "Google Log library" INTERNAL) @@ -53,3 +53,9 @@ rocprofiler_add_interface_library(rocprofiler-cxx-filesystem "C++ filesystem lib rocprofiler_add_interface_library(rocprofiler-ptl "Parallel Tasking Library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-hsa-aql "AQL library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-drm "drm (amdgpu) library" INTERNAL) + +rocprofiler_add_interface_library( + rocprofiler-hip-nolink "rocprofiler-hip without linking to HIP library" IMPORTED) +rocprofiler_add_interface_library( + rocprofiler-hsa-runtime-nolink + "rocprofiler-hsa-runtime without linking to HSA library" IMPORTED) diff --git a/projects/rocprofiler-sdk/cmake/rocprofiler_utilities.cmake b/projects/rocprofiler-sdk/cmake/rocprofiler_utilities.cmake index 05d012a3af..bf930a275b 100644 --- a/projects/rocprofiler-sdk/cmake/rocprofiler_utilities.cmake +++ b/projects/rocprofiler-sdk/cmake/rocprofiler_utilities.cmake @@ -352,10 +352,14 @@ endfunction() # macro to add an interface lib # function(ROCPROFILER_ADD_INTERFACE_LIBRARY _TARGET _DESCRIPT) - add_library(${_TARGET} INTERFACE) - add_library(${PROJECT_NAME}::${_TARGET} ALIAS ${_TARGET}) set(_ARGS "${ARGN}") - if(NOT "INTERNAL" IN_LIST _ARGS) + if(IMPORTED IN_LIST _ARGS) + add_library(${_TARGET} INTERFACE IMPORTED) + else() + add_library(${_TARGET} INTERFACE) + endif() + add_library(${PROJECT_NAME}::${_TARGET} ALIAS ${_TARGET}) + if(NOT "INTERNAL" IN_LIST _ARGS AND NOT "IMPORTED" IN_LIST _ARGS) install( TARGETS ${_TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt index 017463d7e7..e7437611b9 100644 --- a/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/lib/common/CMakeLists.txt @@ -37,9 +37,9 @@ target_link_libraries( $ $ $ - $ + $ $ - $ + $ $ $ $) diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/CMakeLists.txt index 45cf42db0c..40cd498f42 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/CMakeLists.txt @@ -43,8 +43,8 @@ add_subdirectory(pc_sampling) target_link_libraries( rocprofiler-object-library - PUBLIC rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime - rocprofiler::rocprofiler-hip + PUBLIC rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hip-nolink + rocprofiler::rocprofiler-hsa-runtime-nolink PRIVATE rocprofiler::rocprofiler-build-flags rocprofiler::rocprofiler-memcheck rocprofiler::rocprofiler-common-library @@ -69,9 +69,12 @@ target_sources(rocprofiler-shared-library PRIVATE $) target_link_libraries( rocprofiler-shared-library - INTERFACE rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime - rocprofiler::rocprofiler-hip - PRIVATE rocprofiler::rocprofiler-build-flags + INTERFACE rocprofiler::rocprofiler-headers + $ + $ + PRIVATE rocprofiler::rocprofiler-hsa-runtime-nolink + rocprofiler::rocprofiler-hip-nolink + rocprofiler::rocprofiler-build-flags rocprofiler::rocprofiler-memcheck rocprofiler::rocprofiler-common-library rocprofiler::rocprofiler-cxx-filesystem @@ -110,8 +113,8 @@ target_sources(rocprofiler-static-library PRIVATE $) target_link_libraries( rocprofiler-static-library - PUBLIC rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime - rocprofiler::rocprofiler-hip + PUBLIC rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime-nolink + rocprofiler::rocprofiler-hip-nolink PRIVATE rocprofiler::rocprofiler-common-library rocprofiler::rocprofiler-object-library) diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/CMakeLists.txt index d4f05f8dd3..6377245119 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/tests/CMakeLists.txt @@ -18,7 +18,8 @@ target_sources(rocprofiler-lib-tests PRIVATE ${rocprofiler_lib_sources} details/ target_link_libraries( rocprofiler-lib-tests PRIVATE rocprofiler::rocprofiler-static-library - rocprofiler::rocprofiler-common-library GTest::gtest GTest::gtest_main) + rocprofiler::rocprofiler-common-library rocprofiler::rocprofiler-hsa-runtime + GTest::gtest GTest::gtest_main) gtest_add_tests( TARGET rocprofiler-lib-tests @@ -42,7 +43,8 @@ target_sources(rocprofiler-lib-tests-shared PRIVATE ${rocprofiler_shared_lib_sou target_link_libraries( rocprofiler-lib-tests-shared PRIVATE rocprofiler::rocprofiler-shared-library - rocprofiler::rocprofiler-common-library GTest::gtest GTest::gtest_main) + rocprofiler::rocprofiler-common-library rocprofiler::rocprofiler-hsa-runtime + GTest::gtest GTest::gtest_main) gtest_add_tests( TARGET rocprofiler-lib-tests-shared