Update build for rocprofiler-library to support unit tests (#76)

* Update build for rocprofiler-library

- Build rocprofiler OBJECT library (rocprofiler-object-library)
- Generate rocprofiler shared library via rocprofiler-object-library
- Generate rocprofiler static library via rocprofiler-object-library
  - this target is excluded from all target and, thus, is only built when another target links to it

* Update lib/rocprofiler/CMakeLists.txt

- tweak order of EXCLUDE_FROM_ALL and STATIC in add_library(rocprofiler-static-library ...)

* Update samples

- link against rocprofiler::rocprofiler instead of rocprofiler::rocprofiler-library following target renaming

* Update cmake

- fix PROJECT_BUILD_TARGETS for rocprofiler::rocprofiler target in rocprofiler-config.cmake
- disable <OS>-<VERSION> in CPack package name
- Add ROCPROFILER_BUILD_CODECOV option

[ROCm/rocprofiler-sdk commit: 5c07deb159]
This commit is contained in:
Jonathan R. Madsen
2023-09-21 18:01:20 -05:00
zatwierdzone przez GitHub
rodzic 218666ebe9
commit ba4c3a123e
11 zmienionych plików z 98 dodań i 81 usunięć
@@ -17,7 +17,7 @@ install(
set(PROJECT_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
set(PROJECT_BUILD_TARGETS user)
set(PROJECT_BUILD_TARGETS headers shared-library)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/Templates/${PROJECT_NAME}-config.cmake.in
@@ -1,37 +1,6 @@
# configure packaging
function(rocprofiler_parse_release)
if(EXISTS /etc/lsb-release AND NOT IS_DIRECTORY /etc/lsb-release)
file(READ /etc/lsb-release _LSB_RELEASE)
if(_LSB_RELEASE)
string(REGEX
REPLACE "DISTRIB_ID=(.*)\nDISTRIB_RELEASE=(.*)\nDISTRIB_CODENAME=.*"
"\\1-\\2" _SYSTEM_NAME "${_LSB_RELEASE}")
endif()
elseif(EXISTS /etc/os-release AND NOT IS_DIRECTORY /etc/os-release)
file(READ /etc/os-release _OS_RELEASE)
if(_OS_RELEASE)
string(REPLACE "\"" "" _OS_RELEASE "${_OS_RELEASE}")
string(REPLACE "-" " " _OS_RELEASE "${_OS_RELEASE}")
string(REGEX REPLACE "NAME=.*\nVERSION=([0-9\.]+).*\nID=([a-z]+).*" "\\2-\\1"
_SYSTEM_NAME "${_OS_RELEASE}")
endif()
endif()
string(TOLOWER "${_SYSTEM_NAME}" _SYSTEM_NAME)
if(NOT _SYSTEM_NAME)
set(_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
endif()
set(_SYSTEM_NAME
"${_SYSTEM_NAME}"
PARENT_SCOPE)
endfunction()
# parse either /etc/lsb-release or /etc/os-release
rocprofiler_parse_release()
if(NOT _SYSTEM_NAME)
set(_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
endif()
#
# configure packaging settings
#
# Add packaging directives
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
@@ -44,7 +13,7 @@ set(CPACK_PACKAGE_CONTACT "jonathan.madsen@amd.com")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(ROCPROFILER_CPACK_SYSTEM_NAME
"${_SYSTEM_NAME}"
"${CMAKE_SYSTEM_NAME}"
CACHE STRING "System name, e.g. Linux or Ubuntu-18.04")
set(ROCPROFILER_CPACK_PACKAGE_SUFFIX "")
@@ -38,6 +38,8 @@ rocprofiler_add_option(ROCPROFILER_BUILD_TESTS "Enable building the tests"
${ROCPROFILER_BUILD_CI})
rocprofiler_add_option(ROCPROFILER_BUILD_SAMPLES "Enable building the code samples"
${ROCPROFILER_BUILD_CI})
rocprofiler_add_option(ROCPROFILER_BUILD_CODECOV
"Enable building for code coverage analysis" OFF)
# CLI and FILE plugins are always built
foreach(_PLUGIN "ATT" "CTF" "PERFETTO")
@@ -25,7 +25,7 @@ foreach(_TYPE DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
endif()
endforeach()
if(NOT TARGET rocprofiler::rocprofiler-library)
if(NOT TARGET rocprofiler::rocprofiler)
find_package(rocprofiler REQUIRED)
endif()
@@ -33,7 +33,7 @@ add_library(buffered-api-tracing-client SHARED)
target_sources(buffered-api-tracing-client PRIVATE client.cpp client.hpp)
target_link_libraries(
buffered-api-tracing-client
PRIVATE rocprofiler::rocprofiler-library
PRIVATE rocprofiler::rocprofiler
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
set_source_files_properties(main.cpp PROPERTIES LANGUAGE HIP)
@@ -56,5 +56,5 @@ set_tests_properties(
LABELS
"samples"
ENVIRONMENT
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV};HSA_TOOLS_LIB=$<TARGET_FILE:rocprofiler::rocprofiler-library>"
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV};HSA_TOOLS_LIB=$<TARGET_FILE:rocprofiler::rocprofiler>"
)
@@ -25,7 +25,7 @@ foreach(_TYPE DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
endif()
endforeach()
if(NOT TARGET rocprofiler::rocprofiler-library)
if(NOT TARGET rocprofiler::rocprofiler)
find_package(rocprofiler REQUIRED)
endif()
@@ -33,7 +33,7 @@ add_library(callback-api-tracing-client SHARED)
target_sources(callback-api-tracing-client PRIVATE client.cpp client.hpp)
target_link_libraries(
callback-api-tracing-client
PRIVATE rocprofiler::rocprofiler-library
PRIVATE rocprofiler::rocprofiler
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
set_source_files_properties(main.cpp PROPERTIES LANGUAGE HIP)
@@ -56,5 +56,5 @@ set_tests_properties(
LABELS
"samples"
ENVIRONMENT
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV};HSA_TOOLS_LIB=$<TARGET_FILE:rocprofiler::rocprofiler-library>"
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV};HSA_TOOLS_LIB=$<TARGET_FILE:rocprofiler::rocprofiler>"
)
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
project(rocprofiler-samples-pc-sampling LANGUAGES C CXX)
if(NOT TARGET rocprofiler::rocprofiler-library)
if(NOT TARGET rocprofiler::rocprofiler)
find_package(rocprofiler REQUIRED)
endif()
@@ -14,7 +14,7 @@ target_sources(pc_sampling_single-user-host-trap PRIVATE common.h
single-user-host-trap.cpp)
target_link_libraries(
pc_sampling_single-user-host-trap
PRIVATE rocprofiler::rocprofiler-library
PRIVATE rocprofiler::rocprofiler
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
add_executable(pc_sampling_single-user-host-trap-retry)
@@ -22,7 +22,7 @@ target_sources(pc_sampling_single-user-host-trap-retry
PRIVATE common.h single-user-host-trap-retries-service-instantiation.cpp)
target_link_libraries(
pc_sampling_single-user-host-trap-retry
PRIVATE rocprofiler::rocprofiler-library
PRIVATE rocprofiler::rocprofiler
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
add_executable(pc_sampling_single-user-multiple-agents)
@@ -30,5 +30,5 @@ target_sources(pc_sampling_single-user-multiple-agents
PRIVATE common.h single-user-multiple-agents.cpp)
target_link_libraries(
pc_sampling_single-user-multiple-agents
PRIVATE rocprofiler::rocprofiler-library
PRIVATE rocprofiler::rocprofiler
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
@@ -8,17 +8,85 @@ set(ROCPROFILER_LIB_SOURCES
buffer.cpp buffer_tracing.cpp callback_tracing.cpp context.cpp internal_threading.cpp
rocprofiler.cpp registration.cpp)
add_library(rocprofiler-library SHARED)
add_library(rocprofiler::rocprofiler-library ALIAS rocprofiler-library)
# ----------------------------------------------------------------------------------------#
#
# object library allows us to compile rocprofiler code once and generate both a shared and
# static library
#
# ----------------------------------------------------------------------------------------#
target_sources(rocprofiler-library PRIVATE ${ROCPROFILER_LIB_SOURCES}
${ROCPROFILER_LIB_HEADERS})
add_library(rocprofiler-object-library OBJECT)
add_library(rocprofiler::rocprofiler-object-library ALIAS rocprofiler-object-library)
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_SOURCES}
${ROCPROFILER_LIB_HEADERS})
add_subdirectory(hsa)
add_subdirectory(context)
target_link_libraries(
rocprofiler-library
rocprofiler-object-library
PUBLIC rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime
rocprofiler::rocprofiler-hip
PRIVATE rocprofiler::rocprofiler-build-flags rocprofiler::rocprofiler-memcheck
rocprofiler::rocprofiler-common-library rocprofiler::rocprofiler-stdcxxfs
rocprofiler::rocprofiler-dl rocprofiler::rocprofiler-amd-comgr)
target_compile_definitions(rocprofiler-object-library PRIVATE rocprofiler_EXPORTS=1)
set_target_properties(rocprofiler-object-library PROPERTIES POSITION_INDEPENDENT_CODE ON)
# ----------------------------------------------------------------------------------------#
#
# shared library
#
# ----------------------------------------------------------------------------------------#
add_library(rocprofiler-shared-library SHARED)
add_library(rocprofiler::rocprofiler-shared-library ALIAS rocprofiler-shared-library)
target_sources(rocprofiler-shared-library
PRIVATE $<TARGET_OBJECTS:rocprofiler::rocprofiler-object-library>)
target_link_libraries(
rocprofiler-shared-library
INTERFACE rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime
rocprofiler::rocprofiler-hip
PRIVATE rocprofiler::rocprofiler-build-flags rocprofiler::rocprofiler-memcheck
rocprofiler::rocprofiler-common-library rocprofiler::rocprofiler-stdcxxfs
rocprofiler::rocprofiler-dl rocprofiler::rocprofiler-amd-comgr)
set_target_properties(
rocprofiler-shared-library
PROPERTIES OUTPUT_NAME rocprofiler64
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
SKIP_BUILD_RPATH OFF
BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
DEFINE_SYMBOL rocprofiler_EXPORTS)
add_library(rocprofiler::rocprofiler-library ALIAS rocprofiler-shared-library)
add_library(rocprofiler::rocprofiler ALIAS rocprofiler-shared-library)
install(
TARGETS rocprofiler-shared-library
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT core
EXPORT ${PROJECT_NAME}-library-targets)
# ----------------------------------------------------------------------------------------#
#
# static library (only built if another target links to it)
#
# ----------------------------------------------------------------------------------------#
add_library(rocprofiler-static-library EXCLUDE_FROM_ALL STATIC)
add_library(rocprofiler::rocprofiler-static-library ALIAS rocprofiler-static-library)
target_sources(rocprofiler-static-library
PRIVATE $<TARGET_OBJECTS:rocprofiler::rocprofiler-object-library>)
target_link_libraries(
rocprofiler-static-library
PUBLIC rocprofiler::rocprofiler-headers rocprofiler::rocprofiler-hsa-runtime
rocprofiler::rocprofiler-hip
PRIVATE rocprofiler::rocprofiler-build-flags rocprofiler::rocprofiler-memcheck
@@ -26,15 +94,5 @@ target_link_libraries(
rocprofiler::rocprofiler-dl rocprofiler::rocprofiler-amd-comgr)
set_target_properties(
rocprofiler-library
PROPERTIES OUTPUT_NAME rocprofiler64
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
INSTALL_RPATH "\$ORIGIN"
DEFINE_SYMBOL rocprofiler_EXPORTS)
install(
TARGETS rocprofiler-library
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT core
EXPORT ${PROJECT_NAME}-library-targets)
rocprofiler-static-library PROPERTIES OUTPUT_NAME rocprofiler64 DEFINE_SYMBOL
rocprofiler_EXPORTS)
@@ -4,11 +4,5 @@
set(ROCPROFILER_LIB_CONFIG_SOURCES context.cpp domain.cpp)
set(ROCPROFILER_LIB_CONFIG_HEADERS context.hpp domain.hpp allocator.hpp)
target_sources(rocprofiler-library PRIVATE ${ROCPROFILER_LIB_CONFIG_SOURCES}
${ROCPROFILER_LIB_CONFIG_HEADERS})
# add_executable(rocr-example hsa.cpp rocr.hpp) target_link_libraries(rocr-example PRIVATE
# rocprofiler-v2) target_include_directories( rocr-example PRIVATE ${PROJECT_SOURCE_DIR}
# ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/src)
# target_compile_definitions( rocr-example PRIVATE AMD_INTERNAL_BUILD PROF_API_IMPL
# HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1)
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_CONFIG_SOURCES}
${ROCPROFILER_LIB_CONFIG_HEADERS})
@@ -4,7 +4,7 @@
set(ROCPROFILER_LIB_HSA_SOURCES hsa.cpp)
set(ROCPROFILER_LIB_HSA_HEADERS hsa.hpp defines.hpp types.hpp utils.hpp)
target_sources(rocprofiler-library PRIVATE ${ROCPROFILER_LIB_HSA_SOURCES}
${ROCPROFILER_LIB_HSA_HEADERS})
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_HSA_SOURCES}
${ROCPROFILER_LIB_HSA_HEADERS})
add_subdirectory(details)
@@ -4,5 +4,5 @@
set(ROCPROFILER_LIB_HSA_DETAILS_SOURCES)
set(ROCPROFILER_LIB_HSA_DETAILS_HEADERS ostream.hpp)
target_sources(rocprofiler-library PRIVATE ${ROCPROFILER_LIB_HSA_DETAILS_SOURCES}
${ROCPROFILER_LIB_HSA_DETAILS_HEADERS})
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_HSA_DETAILS_SOURCES}
${ROCPROFILER_LIB_HSA_DETAILS_HEADERS})
@@ -1,9 +1,3 @@
#
# Integration tests
#
# placeholder test
add_test(
NAME cmake-version
COMMAND ${CMAKE_COMMAND} --version
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})