Skip to content

Commit

Permalink
CMake: Consistently name CMake Targets (#1082)
Browse files Browse the repository at this point in the history
* Change all rocprofiler-X target names to rocprofiler-sdk-X

* Update rocprofiler-sdk-config.cmake

- fix install tree target names
- simplify logic for using find w/ components and find w/o components

* Update rocprofiler-sdk-roctx-config.cmake

- simplify logic for using find w/ components and find w/o components

* Update samples/intercept_table/CMakeLists.txt

- demonstrate/test use of `find_package(rocprofiler-sdk ... COMPONENTS ...)`
  • Loading branch information
jrmadsen authored Oct 25, 2024
1 parent d93d4d9 commit 74facf8
Show file tree
Hide file tree
Showing 59 changed files with 441 additions and 408 deletions.
14 changes: 6 additions & 8 deletions cmake/Templates/rocprofiler-sdk-roctx/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ else()
include("${@PACKAGE_NAME@_CMAKE_DIR}/@PACKAGE_NAME@-targets.cmake")

# Library dependencies
foreach(TARG @PROJECT_BUILD_TARGETS@)
set(TARG @PACKAGE_NAME@::${TARG})
if(NOT @PACKAGE_NAME@_FIND_COMPONENTS)
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
target_link_libraries(@PACKAGE_NAME@::@PACKAGE_NAME@ INTERFACE ${TARG})
endif()
endforeach()

if(@PACKAGE_NAME@_FIND_COMPONENTS)
foreach(COMP ${@PACKAGE_NAME@_FIND_COMPONENTS})
set(TARG @PACKAGE_NAME@::@PACKAGE_NAME@-${COMP})
Expand All @@ -62,6 +54,12 @@ else()
set(@PACKAGE_NAME@_${COMP}_FOUND 0)
endif()
endforeach()
else()
foreach(TARG @PROJECT_BUILD_TARGETS@)
set(TARG @PACKAGE_NAME@::${TARG})
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
target_link_libraries(@PACKAGE_NAME@::@PACKAGE_NAME@ INTERFACE ${TARG})
endforeach()
endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions cmake/Templates/rocprofiler-sdk/build-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

if(@PACKAGE_NAME@_FIND_COMPONENTS)
foreach(COMP ${@PACKAGE_NAME@_FIND_COMPONENTS})
set(TARG @PACKAGE_NAME@::@PROJECT_NAME@-${COMP})
set(TARG @PACKAGE_NAME@::@PACKAGE_NAME@-${COMP})
if(TARGET ${TARG})
set(@PACKAGE_NAME@_${COMP}_FOUND 1)
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
Expand All @@ -17,7 +17,7 @@ else()
endif()

foreach(COMP @PROJECT_BUILD_TREE_TARGETS@)
set(TARG @PACKAGE_NAME@::@PROJECT_NAME@-${COMP})
set(TARG @PACKAGE_NAME@::@PACKAGE_NAME@-${COMP})
if(TARGET ${TARG})
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
target_link_libraries(@PACKAGE_NAME@::@PACKAGE_NAME@ INTERFACE ${TARG})
Expand Down
16 changes: 7 additions & 9 deletions cmake/Templates/rocprofiler-sdk/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,9 @@ else()
@PROJECT_NAME@_config_nolink_target(@PACKAGE_NAME@::@PACKAGE_NAME@-external-nolink amd_comgr)

# Library dependencies
foreach(TARG @PROJECT_BUILD_TARGETS@)
set(TARG @PACKAGE_NAME@::@PROJECT_NAME@-${TARG})
if(NOT @PACKAGE_NAME@_FIND_COMPONENTS)
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
target_link_libraries(@PACKAGE_NAME@::@PACKAGE_NAME@ INTERFACE ${TARG})
endif()
endforeach()

if(@PACKAGE_NAME@_FIND_COMPONENTS)
foreach(COMP ${@PACKAGE_NAME@_FIND_COMPONENTS})
set(TARG @PACKAGE_NAME@::${COMP})
set(TARG @PACKAGE_NAME@::@PACKAGE_NAME@-${COMP})
if(TARGET ${TARG})
set(@PACKAGE_NAME@_${COMP}_FOUND 1)
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
Expand All @@ -129,6 +121,12 @@ else()
set(@PACKAGE_NAME@_${COMP}_FOUND 0)
endif()
endforeach()
else()
foreach(TARG @PROJECT_BUILD_TARGETS@)
set(TARG @PACKAGE_NAME@::@PACKAGE_NAME@-${TARG})
list(APPEND @PACKAGE_NAME@_LIBRARIES ${TARG})
target_link_libraries(@PACKAGE_NAME@::@PACKAGE_NAME@ INTERFACE ${TARG})
endforeach()
endif()

target_link_libraries(@PACKAGE_NAME@::@PACKAGE_NAME@
Expand Down
77 changes: 39 additions & 38 deletions cmake/rocprofiler_build_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ include(FindPackageHandleStandardArgs)
include(rocprofiler_compilers)
include(rocprofiler_utilities)

target_compile_definitions(rocprofiler-build-flags INTERFACE $<$<CONFIG:DEBUG>:DEBUG>)
target_compile_definitions(rocprofiler-sdk-build-flags INTERFACE $<$<CONFIG:DEBUG>:DEBUG>)

if(ROCPROFILER_BUILD_CI)
rocprofiler_target_compile_definitions(rocprofiler-build-flags
rocprofiler_target_compile_definitions(rocprofiler-sdk-build-flags
INTERFACE ROCPROFILER_CI)
endif()

if(ROCPROFILER_BUILD_CODECOV)
target_link_libraries(rocprofiler-build-flags INTERFACE gcov)
target_link_libraries(rocprofiler-sdk-build-flags INTERFACE gcov)
endif()

# ----------------------------------------------------------------------------------------#
Expand All @@ -38,40 +38,41 @@ foreach(_TYPE dl rt)
find_package_handle_standard_args(${_TYPE}-library REQUIRED_VARS ${_TYPE}_LIBRARY)
if(${_TYPE}-library_FOUND)
string(TOUPPER "${_TYPE}" _TYPE_UC)
rocprofiler_target_compile_definitions(rocprofiler-${_TYPE}
rocprofiler_target_compile_definitions(rocprofiler-sdk-${_TYPE}
INTERFACE ROCPROFILER_${_TYPE_UC}=1)
target_link_libraries(rocprofiler-${_TYPE} INTERFACE ${${_TYPE}_LIBRARY})
target_link_libraries(rocprofiler-sdk-${_TYPE} INTERFACE ${${_TYPE}_LIBRARY})
if("${_TYPE}" STREQUAL "dl" AND NOT ROCPROFILER_ENABLE_CLANG_TIDY)
# This instructs the linker to add all symbols, not only used ones, to the
# dynamic symbol table. This option is needed for some uses of dlopen or
# to allow obtaining backtraces from within a program.
rocprofiler_target_compile_options(
rocprofiler-${_TYPE}
rocprofiler-sdk-${_TYPE}
LANGUAGES C CXX
LINK_LANGUAGES C CXX
INTERFACE "-rdynamic")
endif()
else()
rocprofiler_target_compile_definitions(rocprofiler-${_TYPE}
rocprofiler_target_compile_definitions(rocprofiler-sdk-${_TYPE}
INTERFACE ROCPROFILER_${_TYPE_UC}=0)
endif()
endif()
endforeach()

target_link_libraries(rocprofiler-build-flags INTERFACE rocprofiler-sdk::rocprofiler-dl)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-dl)

# ----------------------------------------------------------------------------------------#
# set the compiler flags
#
rocprofiler_target_compile_options(rocprofiler-build-flags
rocprofiler_target_compile_options(rocprofiler-sdk-build-flags
INTERFACE "-W" "-Wall" "-Wno-unknown-pragmas")

# compiler version specific flags
function(set_compiler_options compiler_id version)
if(CMAKE_CXX_COMPILER_ID STREQUAL ${compiler_id} AND CMAKE_CXX_COMPILER_VERSION
VERSION_LESS_EQUAL ${version})
rocprofiler_target_compile_options(
rocprofiler-build-flags
rocprofiler-sdk-build-flags
INTERFACE "-Wno-error=extra" "-Wno-unused-variable"
"-Wno-error=unused-but-set-variable"
"-Wno-error=unused-but-set-parameter" "-Wno-error=shadow")
Expand All @@ -89,111 +90,111 @@ set_compiler_options("Clang" "13.0")
#

rocprofiler_target_compile_options(
rocprofiler-debug-flags INTERFACE "-g3" "-fno-omit-frame-pointer"
"-fno-optimize-sibling-calls")
rocprofiler-sdk-debug-flags INTERFACE "-g3" "-fno-omit-frame-pointer"
"-fno-optimize-sibling-calls")

target_compile_options(
rocprofiler-debug-flags
rocprofiler-sdk-debug-flags
INTERFACE $<$<COMPILE_LANGUAGE:C>:$<$<C_COMPILER_ID:GNU>:-rdynamic>>
$<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:GNU>:-rdynamic>>)

if(NOT APPLE AND NOT ROCPROFILER_ENABLE_CLANG_TIDY)
target_link_options(rocprofiler-debug-flags INTERFACE
target_link_options(rocprofiler-sdk-debug-flags INTERFACE
$<$<CXX_COMPILER_ID:GNU>:-rdynamic>)
endif()

if(dl_LIBRARY)
target_link_libraries(rocprofiler-debug-flags INTERFACE ${dl_LIBRARY})
target_link_libraries(rocprofiler-sdk-debug-flags INTERFACE ${dl_LIBRARY})
endif()

if(rt_LIBRARY)
target_link_libraries(rocprofiler-debug-flags INTERFACE ${rt_LIBRARY})
target_link_libraries(rocprofiler-sdk-debug-flags INTERFACE ${rt_LIBRARY})
endif()

if(ROCPROFILER_BUILD_DEBUG)
target_link_libraries(rocprofiler-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-debug-flags)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-debug-flags)
endif()

# ----------------------------------------------------------------------------------------#
# debug-safe optimizations
#
rocprofiler_target_compile_options(
rocprofiler-build-flags
rocprofiler-sdk-build-flags
LANGUAGES CXX
INTERFACE "-faligned-new")

# ----------------------------------------------------------------------------------------#
# fstack-protector
#
rocprofiler_target_compile_options(
rocprofiler-stack-protector
rocprofiler-sdk-stack-protector
LANGUAGES C CXX
INTERFACE "-fstack-protector-strong" "-Wstack-protector")

if(ROCPROFILER_BUILD_STACK_PROTECTOR)
target_link_libraries(rocprofiler-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-stack-protector)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-stack-protector)
endif()

# ----------------------------------------------------------------------------------------#
# developer build flags
#
rocprofiler_target_compile_options(
rocprofiler-developer-flags
rocprofiler-sdk-developer-flags
LANGUAGES C CXX
INTERFACE "-Werror" "-Wdouble-promotion" "-Wshadow" "-Wextra" "-Wvla")

if(ROCPROFILER_BUILD_DEVELOPER)
target_link_libraries(rocprofiler-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-developer-flags)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-developer-flags)
endif()

# ----------------------------------------------------------------------------------------#
# release build flags
#
rocprofiler_target_compile_options(
rocprofiler-release-flags
rocprofiler-sdk-release-flags
LANGUAGES C CXX
INTERFACE "-g1" "-feliminate-unused-debug-symbols" "-gno-column-info"
"-gno-variable-location-views" "-gline-tables-only")

if(ROCPROFILER_BUILD_RELEASE)
target_link_libraries(rocprofiler-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-release-flags)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-release-flags)
endif()

# ----------------------------------------------------------------------------------------#
# static lib flags
#
target_compile_options(
rocprofiler-static-libgcc
rocprofiler-sdk-static-libgcc
INTERFACE $<$<COMPILE_LANGUAGE:C>:$<$<C_COMPILER_ID:GNU>:-static-libgcc>>
$<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:GNU>:-static-libgcc>>)
target_link_options(
rocprofiler-static-libgcc INTERFACE
rocprofiler-sdk-static-libgcc INTERFACE
$<$<COMPILE_LANGUAGE:C>:$<$<C_COMPILER_ID:GNU,Clang>:-static-libgcc>>
$<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:GNU,Clang>:-static-libgcc>>)

target_compile_options(
rocprofiler-static-libstdcxx
rocprofiler-sdk-static-libstdcxx
INTERFACE $<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:GNU>:-static-libstdc++>>)
target_link_options(
rocprofiler-static-libstdcxx INTERFACE
rocprofiler-sdk-static-libstdcxx INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:GNU,Clang>:-static-libstdc++>>)

if(ROCPROFILER_BUILD_STATIC_LIBGCC)
target_link_libraries(rocprofiler-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-static-libgcc)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-static-libgcc)
endif()

if(ROCPROFILER_BUILD_STATIC_LIBSTDCXX)
target_link_libraries(rocprofiler-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-static-libstdcxx)
target_link_libraries(rocprofiler-sdk-build-flags
INTERFACE rocprofiler-sdk::rocprofiler-sdk-static-libstdcxx)
endif()

if(ROCPROFILER_UNSAFE_NO_VERSION_CHECK)
rocprofiler_target_compile_definitions(rocprofiler-build-flags
rocprofiler_target_compile_definitions(rocprofiler-sdk-build-flags
INTERFACE ROCPROFILER_UNSAFE_NO_VERSION_CHECK)
endif()

Expand All @@ -203,5 +204,5 @@ endif()
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)

if(NOT APPLE OR "$ENV{CONDA_PYTHON_EXE}" STREQUAL "")
rocprofiler_target_user_flags(rocprofiler-build-flags "CXX")
rocprofiler_target_user_flags(rocprofiler-sdk-build-flags "CXX")
endif()
6 changes: 3 additions & 3 deletions cmake/rocprofiler_config_install_roctx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ set(${PACKAGE_NAME}_BUILD_TREE

set(PROJECT_BUILD_TREE_TARGETS
${SDK_PACKAGE_NAME}::${PACKAGE_NAME}-shared-library
${SDK_PACKAGE_NAME}::${PROJECT_NAME}-headers
${SDK_PACKAGE_NAME}::${PROJECT_NAME}-build-flags
${SDK_PACKAGE_NAME}::${PROJECT_NAME}-stack-protector)
${SDK_PACKAGE_NAME}::${SDK_PACKAGE_NAME}-headers
${SDK_PACKAGE_NAME}::${SDK_PACKAGE_NAME}-build-flags
${SDK_PACKAGE_NAME}::${SDK_PACKAGE_NAME}-stack-protector)

configure_file(
${PROJECT_SOURCE_DIR}/cmake/Templates/${PACKAGE_NAME}/build-config.cmake.in
Expand Down
Loading

0 comments on commit 74facf8

Please sign in to comment.