From e21c0551ab9cb30f99fad5785b5d868b7a01e3eb Mon Sep 17 00:00:00 2001 From: Lauren Wrubleski Date: Thu, 23 May 2024 15:04:29 -0600 Subject: [PATCH 1/4] Cherrypick static build fixes (#189) * Packaging for static components (#182) * Initial changes for static packaging * Changelog update * Correct tests for new behaviour * Add missing parameter * Remove devel dependency on runtime for static builds * install executables to bin/asan for ASAN builds (#178) --- CHANGELOG.md | 19 +++ .../cmake/ROCMCreatePackage.cmake | 125 +++++++++++------- .../cmake/ROCMInstallTargets.cmake | 5 +- test/pass/rocm-package-setup-component.cmake | 13 +- test/test.cmake | 6 + 5 files changed, 112 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bda5f369..87354422 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Change Log for rocm-cmake +## [(Unreleased) rocm-cmake 0.13.0 for ROCm 6.2.0] +### Changed +- ROCmCreatePackage: Accepts a suffix parameter, automatically generating it for static or ASAN builds. + - Package names will no longer be pulled from `CPACK__PACKAGE_NAME` + - Runtime packages will no longer be generated for static builds +## [rocm-cmake 0.12.0 for ROCm 6.1.0] +### Added +- ROCMTest: Add rpath to installed tests +- AOCMCreatePackage: Allow additional provides on header-only packages +- ROCMSphinxDoc: Allow separate source and config directories +### Changed +- Renamed CMake package to ROCmCMakeBuildTools. A wrapper has been provided + to ensure that `find_package(ROCM)` continues to work, but it is recommended + that developers switch to `find_package(ROCmCMakeBuildTools)` +- ROCMInstallTargets: Stopped installing executables in ASAN builds +### Fixed +- ROCMClangTidy: Fixed invalid list index in clang tidy +- Fixed test failures when `ROCM_CMAKE_GENERATOR` is an empty string + ## [rocm-cmake 0.11.0 for ROCm 6.0.0] ### Changed - ROCMSphinxDoc: Improved validation, documentation and rocm-docs-core integration. diff --git a/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake b/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake index 746982d0..c55968d2 100755 --- a/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake @@ -269,7 +269,7 @@ endmacro() macro(rocm_create_package) set(options LDCONFIG PTH HEADER_ONLY) - set(oneValueArgs NAME DESCRIPTION SECTION MAINTAINER LDCONFIG_DIR PREFIX) + set(oneValueArgs NAME DESCRIPTION SECTION MAINTAINER LDCONFIG_DIR PREFIX SUFFIX) set(multiValueArgs DEPENDS COMPONENTS) cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -324,18 +324,18 @@ macro(rocm_create_package) endif() if (ROCM_USE_DEV_COMPONENT) + rocm_compute_component_package_name(devel "${CPACK_PACKAGE_NAME}" "${PARSE_SUFFIX}" "${PARSE_HEADER_ONLY}") list(APPEND PARSE_COMPONENTS devel) - set(CPACK_DEBIAN_DEVEL_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-dev") rocm_join_if_set(", " CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS - "${CPACK_PACKAGE_NAME}-dev (>=${CPACK_PACKAGE_VERSION})") + "${CPACK_DEBIAN_DEVEL_PACKAGE_NAME} (>=${CPACK_PACKAGE_VERSION})") rocm_find_program_version(rpmbuild GREATER_EQUAL 4.12.0 QUIET) if(rpmbuild_VERSION_OK) rocm_join_if_set(", " CPACK_RPM_RUNTIME_PACKAGE_SUGGESTS - "${CPACK_PACKAGE_NAME}-devel >= ${CPACK_PACKAGE_VERSION}" + "${CPACK_RPM_DEVEL_PACKAGE_NAME} >= ${CPACK_PACKAGE_VERSION}" ) endif() - if(PARSE_HEADER_ONLY) + if(PARSE_HEADER_ONLY OR NOT BUILD_SHARED_LIBS) rocm_join_if_set(", " CPACK_DEBIAN_DEVEL_PACKAGE_PROVIDES CPACK_DEBIAN_PACKAGE_PROVIDES @@ -411,7 +411,7 @@ macro(rocm_create_package) endif() rocm_setup_license(${PARSE_HEADER_ONLY}) if(PARSE_COMPONENTS) - rocm_set_comp_cpackvar(PARSE_HEADER_ONLY "${PARSE_COMPONENTS}") + rocm_set_comp_cpackvar(PARSE_HEADER_ONLY "${PARSE_SUFFIX}" "${PARSE_COMPONENTS}") endif() include(CPack) set(ROCM_PACKAGE_CREATED TRUE CACHE INTERNAL "Track whether rocm_create_package has been called.") @@ -449,7 +449,7 @@ macro(rocm_setup_license HEADER_ONLY) FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION share/doc/${_rocm_cpack_package_name}-asan ) - elseif(ROCM_USE_DEV_COMPONENT AND ${HEADER_ONLY}) + elseif((ROCM_USE_DEV_COMPONENT AND ${HEADER_ONLY}) OR NOT BUILD_SHARED_LIBS) install( FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION share/doc/${_rocm_cpack_package_name} @@ -464,24 +464,74 @@ macro(rocm_setup_license HEADER_ONLY) endif() endmacro() -macro(rocm_set_comp_cpackvar HEADER_ONLY components) +macro(rocm_compute_component_package_name COMPONENT_NAME BASE_NAME NAME_SUFFIX HEADER_ONLY) + # both the fully upper and lowercased names of the components will be needed + string(TOLOWER ${COMPONENT_NAME} _component_name_lower) + string(TOUPPER ${COMPONENT_NAME} _component_name_upper) + + # determine the package name suffix due to specific build conditions + if(${NAME_SUFFIX}) + string(TOLOWER ${NAME_SUFFIX} _component_suffix) + else() + if(ENABLE_ASAN_PACKAGING) + set(_component_suffix asan) + elseif(NOT ${HEADER_ONLY} AND NOT ${BUILD_SHARED_LIBS}) + set(_component_suffix static) + endif() + endif() + if(_component_suffix) + set(_component_suffix "-${_component_suffix}") + endif() + + # determine the package name component + if(_component_name_lower STREQUAL "runtime") + set(_rpm_component_partial "") + set(_deb_component_partial "") + elseif(_component_name_lower STREQUAL "devel") + set(_rpm_component_partial "-devel") + set(_deb_component_partial "-dev") + else() + set(_rpm_component_partial "-${_component_name_lower}") + set(_deb_component_partial "-${_component_name_lower}") + endif() + + # set the package names + if(NOT DEFINED CPACK_RPM_${_component_name_upper}_PACKAGE_NAME + OR CPACK_RPM_${_component_name_upper}_PACKAGE_NAME STREQUAL "" + ) + set(CPACK_RPM_${_component_name_upper}_PACKAGE_NAME + "${BASE_NAME}${_rpm_component_partial}${_component_suffix}") + endif() + if(NOT DEFINED CPACK_DEBIAN_${_component_name_upper}_PACKAGE_NAME + OR CPACK_DEBIAN_${_component_name_upper}_PACKAGE_NAME STREQUAL "" + ) + set(CPACK_DEBIAN_${_component_name_upper}_PACKAGE_NAME + "${BASE_NAME}${_deb_component_partial}${_component_suffix}") + endif() + + # clean up temporary variables + unset(_deb_component_partial) + unset(_rpm_component_partial) + unset(_component_suffix) + unset(_component_name_upper) + unset(_component_name_lower) +endmacro(rocm_compute_component_package_name) + +macro(rocm_set_comp_cpackvar HEADER_ONLY NAME_SUFFIX components) # Setting component specific variables set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) if(NOT ROCM_USE_DEV_COMPONENT OR NOT ${HEADER_ONLY}) - set(CPACK_RPM_MAIN_COMPONENT "runtime") + rocm_compute_component_package_name("runtime" "${CPACK_PACKAGE_NAME}" "${NAME_SUFFIX}" ${HEADER_ONLY}) if (NOT ENABLE_ASAN_PACKAGING) - set(CPACK_RPM_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") - list(APPEND CPACK_COMPONENTS_ALL runtime) set(CPACK_DEBIAN_RUNTIME_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-${DEBIAN_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") - set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") else() - set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-asan") - set(CPACK_RPM_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") set(CPACK_RPM_RUNTIME_FILE_NAME "RPM-DEFAULT") - set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") set(CPACK_DEBIAN_RUNTIME_FILE_NAME "DEB-DEFAULT") + endif() + if (NOT ${HEADER_ONLY} AND BUILD_SHARED_LIBS) + set(CPACK_RPM_MAIN_COMPONENT "runtime") list(APPEND CPACK_COMPONENTS_ALL runtime) endif() endif() @@ -497,26 +547,12 @@ macro(rocm_set_comp_cpackvar HEADER_ONLY components) string(TOUPPER "${COMPONENT}" COMPONENT_UC) set(CPACK_RPM_${COMPONENT_UC}_FILE_NAME "RPM-DEFAULT") set(CPACK_DEBIAN_${COMPONENT_UC}_FILE_NAME "DEB-DEFAULT") - if(NOT DEFINED CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME - OR CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME STREQUAL "") - if(NOT DEFINED CPACK_DEBIAN_PACKAGE_NAME OR CPACK_DEBIAN_PACKAGE_NAME STREQUAL "") - set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") - endif() - string(TOLOWER "${CPACK_DEBIAN_PACKAGE_NAME}-${COMPONENT}" CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME) - else() - string(REGEX REPLACE "" "${CPACK_PACKAGE_NAME}" - CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME "${CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME}") - endif() - if(NOT DEFINED CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME - OR CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME STREQUAL "") - if(NOT DEFINED CPACK_RPM_PACKAGE_NAME OR CPACK_RPM_PACKAGE_NAME STREQUAL "") - set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") - endif() - string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${COMPONENT}" CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME) - else() - string(REGEX REPLACE "" "${CPACK_PACKAGE_NAME}" - CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME "${CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME}") - endif() + rocm_compute_component_package_name("${COMPONENT}" "${CPACK_PACKAGE_NAME}" "${NAME_SUFFIX}" "${HEADER_ONLY}") + + string(REGEX REPLACE "" "${CPACK_PACKAGE_NAME}" + CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME "${CPACK_DEBIAN_${COMPONENT_UC}_PACKAGE_NAME}") + string(REGEX REPLACE "" "${CPACK_PACKAGE_NAME}" + CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME "${CPACK_RPM_${COMPONENT_UC}_PACKAGE_NAME}") endforeach() if(ROCM_PACKAGE_COMPONENT_DEPENDENCIES) foreach(COMP_DEP IN LISTS ROCM_PACKAGE_COMPONENT_DEPENDENCIES) @@ -540,21 +576,16 @@ macro(rocm_package_setup_component COMPONENT_NAME) list(APPEND ROCM_PACKAGE_COMPONENTS ${COMPONENT_NAME}) - if(NOT DEFINED PARSE_PACKAGE_NAME) - string(TOLOWER "${COMPONENT_NAME}" PARSE_PACKAGE_NAME) - if(NOT BUILD_SHARED_LIBS) - set(PARSE_PACKAGE_NAME "${PARSE_PACKAGE_NAME}-static") + if(DEFINED PARSE_PACKAGE_NAME) + if(NOT DEFINED PARSE_LIBRARY_NAME) + set(PARSE_LIBRARY_NAME "") endif() - endif() - if(NOT DEFINED PARSE_LIBRARY_NAME) - set(PARSE_LIBRARY_NAME "") - endif() - - string(TOUPPER "${COMPONENT_NAME}" COMPONENT_GNAME) + string(TOUPPER "${COMPONENT_NAME}" COMPONENT_GNAME) - set(CPACK_DEBIAN_${COMPONENT_GNAME}_PACKAGE_NAME "${PARSE_LIBRARY_NAME}-${PARSE_PACKAGE_NAME}") - set(CPACK_RPM_${COMPONENT_GNAME}_PACKAGE_NAME "${PARSE_LIBRARY_NAME}-${PARSE_PACKAGE_NAME}") + set(CPACK_DEBIAN_${COMPONENT_GNAME}_PACKAGE_NAME "${PARSE_LIBRARY_NAME}-${PARSE_PACKAGE_NAME}") + set(CPACK_RPM_${COMPONENT_GNAME}_PACKAGE_NAME "${PARSE_LIBRARY_NAME}-${PARSE_PACKAGE_NAME}") + endif() if(DEFINED PARSE_PARENT) list(APPEND ROCM_PACKAGE_COMPONENT_DEPENDENCIES "${PARSE_PARENT}->${COMPONENT_NAME}") diff --git a/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake b/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake index f21fc223..463c482c 100644 --- a/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake @@ -137,7 +137,7 @@ function(rocm_install_targets) set(LIB_INSTALL_DIR ${PARSE_PREFIX}/${ROCM_INSTALL_LIBDIR}) set(INCLUDE_INSTALL_DIR ${PARSE_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) elseif(ENABLE_ASAN_PACKAGING) - set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) + set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}/asan) set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/asan) set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) else() @@ -185,9 +185,6 @@ function(rocm_install_targets) set(export_arg EXPORT ${EXPORT_FILE}) if(T_TYPE STREQUAL "EXECUTABLE") unset(export_arg) - if(ENABLE_ASAN_PACKAGING) - continue() - endif() endif() install( TARGETS ${TARGET} diff --git a/test/pass/rocm-package-setup-component.cmake b/test/pass/rocm-package-setup-component.cmake index 546e5810..b8ed8cd8 100644 --- a/test/pass/rocm-package-setup-component.cmake +++ b/test/pass/rocm-package-setup-component.cmake @@ -1,3 +1,5 @@ +cmake_minimum_required(VERSION 3.10) + use_rocm_cmake() include(ROCMCreatePackage) include(ROCMClients) @@ -8,8 +10,8 @@ set(BUILD_SHARED_LIBS ON) rocm_package_setup_component(comp-a) test_expect_eq("${ROCM_PACKAGE_COMPONENTS}" "comp-a") -test_expect_eq("${CPACK_DEBIAN_COMP-A_PACKAGE_NAME}" "-comp-a") -test_expect_eq("${CPACK_RPM_COMP-A_PACKAGE_NAME}" "-comp-a") +test_expect_undef(CPACK_DEBIAN_COMP-A_PACKAGE_NAME) +test_expect_undef(CPACK_RPM_COMP-A_PACKAGE_NAME) rocm_package_setup_component( comp-b @@ -30,6 +32,7 @@ rocm_package_setup_component( RPM "baz = 3.0" COMPONENT comp-a comp-b LIBRARY_NAME packaging + PACKAGE_NAME comp-c ) test_expect_eq("${ROCM_PACKAGE_COMPONENTS}" "comp-a;comp-b;comp-c") @@ -44,8 +47,8 @@ rocm_package_setup_client_component( DEPENDS COMPONENT comp-c ) test_expect_eq("${ROCM_PACKAGE_COMPONENTS}" "comp-a;comp-b;comp-c;client-a") -test_expect_eq("${CPACK_DEBIAN_CLIENT-A_PACKAGE_NAME}" "-client-a") -test_expect_eq("${CPACK_RPM_CLIENT-A_PACKAGE_NAME}" "-client-a") +test_expect_undef(CPACK_DEBIAN_CLIENT-A_PACKAGE_NAME) +test_expect_undef(CPACK_RPM_CLIENT-A_PACKAGE_NAME) test_expect_eq("${CPACK_DEBIAN_CLIENT-A_PACKAGE_DEPENDS}" "") test_expect_eq("${CPACK_RPM_CLIENT-A_PACKAGE_REQUIRES}" "") test_expect_eq("${ROCM_PACKAGE_COMPONENT_DEPENDENCIES}" @@ -54,7 +57,7 @@ test_expect_eq("${ROCM_PACKAGE_COMPONENT_DEPENDENCIES}" set(CPACK_PACKAGE_NAME "packtest") set(CPACK_PACKAGE_VERSION 1.0.0) -rocm_set_comp_cpackvar(FALSE "${ROCM_PACKAGE_COMPONENTS};clients") +rocm_set_comp_cpackvar(FALSE "" "${ROCM_PACKAGE_COMPONENTS};clients") test_expect_eq("${CPACK_COMPONENTS_ALL}" "runtime;comp-a;comp-b;comp-c;client-a;clients") test_expect_eq("${CPACK_DEBIAN_RUNTIME_PACKAGE_NAME}" "packtest") diff --git a/test/test.cmake b/test/test.cmake index 42430d26..3200c0c9 100755 --- a/test/test.cmake +++ b/test/test.cmake @@ -49,6 +49,12 @@ macro(test_expect_eq X Y) endif() endmacro() +macro(test_expect_undef X) + if(DEFINED "${X}") + message(FATAL_ERROR "EXPECT FAILURE: ${X} IS DEFINED ${ARGN}") + endif() +endmacro() + macro(test_expect_matches X Y) if("${X}" STREQUAL "" OR NOT "${X}" MATCHES "${Y}") message(FATAL_ERROR "EXPECT FAILURE: ${X} NOT MATCHES ${Y} ${ARGN}") From 84e35103b7389bffabfe1757081c7a444872cca6 Mon Sep 17 00:00:00 2001 From: Lauren Wrubleski Date: Thu, 27 Jun 2024 16:35:36 -0600 Subject: [PATCH 2/4] change ordering of suffixes (#201) (cherry picked from commit bd28d0fbebfe4026687360adff43e981e34db844) --- share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake b/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake index c55968d2..593af6aa 100755 --- a/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake @@ -500,13 +500,13 @@ macro(rocm_compute_component_package_name COMPONENT_NAME BASE_NAME NAME_SUFFIX H OR CPACK_RPM_${_component_name_upper}_PACKAGE_NAME STREQUAL "" ) set(CPACK_RPM_${_component_name_upper}_PACKAGE_NAME - "${BASE_NAME}${_rpm_component_partial}${_component_suffix}") + "${BASE_NAME}${_component_suffix}${_rpm_component_partial}") endif() if(NOT DEFINED CPACK_DEBIAN_${_component_name_upper}_PACKAGE_NAME OR CPACK_DEBIAN_${_component_name_upper}_PACKAGE_NAME STREQUAL "" ) set(CPACK_DEBIAN_${_component_name_upper}_PACKAGE_NAME - "${BASE_NAME}${_deb_component_partial}${_component_suffix}") + "${BASE_NAME}${_component_suffix}${_deb_component_partial}") endif() # clean up temporary variables From 5a862812cf5625b1c9f2c90c6b0dc28514902bec Mon Sep 17 00:00:00 2001 From: Lauren Wrubleski Date: Thu, 27 Jun 2024 16:35:54 -0600 Subject: [PATCH 3/4] fix names for header-only components when built statically (#202) --- share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake b/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake index 593af6aa..3733c74a 100755 --- a/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMCreatePackage.cmake @@ -475,7 +475,7 @@ macro(rocm_compute_component_package_name COMPONENT_NAME BASE_NAME NAME_SUFFIX H else() if(ENABLE_ASAN_PACKAGING) set(_component_suffix asan) - elseif(NOT ${HEADER_ONLY} AND NOT ${BUILD_SHARED_LIBS}) + elseif(NOT ${BUILD_SHARED_LIBS}) set(_component_suffix static) endif() endif() From aa86563e9b521d33f8888a5f71500812fbc6f52e Mon Sep 17 00:00:00 2001 From: Ahsan Saghir <142340507+ahsan-ca@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:46:06 -0400 Subject: [PATCH 4/4] Cherry-pick private lib changes into release 6.2 (#205) * Add flag to move libraries under project name (#188) Co-authored-by: Paul Fultz II * Turn ROCM_SYMLINK_LIBS OFF by default (#199) * Update RPATH to binaries for PRIVATE lib changes (#197) * Update RPATHs * Remove debug messages and re-indent comments * Use CMP0095 NEW policy for paths and update BIN_INSTALL_DIR paths for private binaries * Remove setting CMP0095 to NEW * Add RPATH to tests to point to private libraries. (#200) * Add RPATH to tests to point to private libraries. * Fix relative path to lib --------- Co-authored-by: Lauren Wrubleski --------- Co-authored-by: Paul Fultz II Co-authored-by: Lauren Wrubleski --- .../cmake/ROCMInstallTargets.cmake | 56 +++++++++++++++---- .../rocmcmakebuildtools/cmake/ROCMTest.cmake | 8 +-- test/libprivate/CMakeLists.txt | 51 +++++++++++++++++ test/libprivate/LICENSE | 3 + test/libprivate/importtarget.cmake | 3 + test/libprivate/include/simpleprivate.h | 12 ++++ test/libprivate/main.cpp | 6 ++ test/libprivate/simpleprivate.cpp | 7 +++ test/pass/libprivate.cmake | 11 ++++ 9 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 test/libprivate/CMakeLists.txt create mode 100644 test/libprivate/LICENSE create mode 100644 test/libprivate/importtarget.cmake create mode 100644 test/libprivate/include/simpleprivate.h create mode 100644 test/libprivate/main.cpp create mode 100644 test/libprivate/simpleprivate.cpp create mode 100644 test/pass/libprivate.cmake diff --git a/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake b/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake index 463c482c..72fdb3bb 100644 --- a/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake @@ -116,10 +116,10 @@ function(rocm_install) endif() endfunction() -option(ROCM_SYMLINK_LIBS "Create backwards compatibility symlink for library files." ON) +option(ROCM_SYMLINK_LIBS "Create backwards compatibility symlink for library files." OFF) function(rocm_install_targets) - set(options) + set(options PRIVATE) set(oneValueArgs PREFIX EXPORT COMPONENT) set(multiValueArgs TARGETS INCLUDE) @@ -133,17 +133,35 @@ function(rocm_install_targets) if(PARSE_PREFIX) set(PREFIX_DIR ${PARSE_PREFIX}) - set(BIN_INSTALL_DIR ${PARSE_PREFIX}/${CMAKE_INSTALL_BINDIR}) - set(LIB_INSTALL_DIR ${PARSE_PREFIX}/${ROCM_INSTALL_LIBDIR}) - set(INCLUDE_INSTALL_DIR ${PARSE_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) + if(PARSE_PRIVATE) + set(BIN_INSTALL_DIR ${PARSE_PREFIX}/${ROCM_INSTALL_LIBDIR}/${PROJECT_NAME}/bin) + set(LIB_INSTALL_DIR ${PARSE_PREFIX}/${ROCM_INSTALL_LIBDIR}/${PROJECT_NAME}/lib) + set(INCLUDE_INSTALL_DIR ${PARSE_PREFIX}/${ROCM_INSTALL_LIBDIR}/${PROJECT_NAME}/include) + else() + set(BIN_INSTALL_DIR ${PARSE_PREFIX}/${CMAKE_INSTALL_BINDIR}) + set(LIB_INSTALL_DIR ${PARSE_PREFIX}/${ROCM_INSTALL_LIBDIR}) + set(INCLUDE_INSTALL_DIR ${PARSE_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) + endif() elseif(ENABLE_ASAN_PACKAGING) - set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}/asan) - set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/asan) - set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + if(PARSE_PRIVATE) + set(BIN_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/asan/${PROJECT_NAME}/bin) + set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/asan/${PROJECT_NAME}/lib) + set(INCLUDE_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/asan/${PROJECT_NAME}/include) + else() + set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}/asan) + set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/asan) + set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + endif() else() - set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) - set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}) - set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + if(PARSE_PRIVATE) + set(BIN_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/${PROJECT_NAME}/bin) + set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/${PROJECT_NAME}/lib) + set(INCLUDE_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}/${PROJECT_NAME}/include) + else() + set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) + set(LIB_INSTALL_DIR ${ROCM_INSTALL_LIBDIR}) + set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + endif() endif() foreach(TARGET ${PARSE_TARGETS}) @@ -182,6 +200,17 @@ function(rocm_install_targets) foreach(TARGET IN LISTS PARSE_TARGETS) get_target_property(T_TYPE ${TARGET} TYPE) + if(NOT T_TYPE STREQUAL "INTERFACE_LIBRARY") + set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "$ORIGIN/../lib") + if(PARSE_PRIVATE) + # Adding RPATH to private binaries to point to public libraries. + set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "$ORIGIN/../../") + else() + # Adding RPATH to public binaries to point to private libraries. + set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "$ORIGIN/../lib/${PROJECT_NAME}/lib") + endif() + endif() + set(export_arg EXPORT ${EXPORT_FILE}) if(T_TYPE STREQUAL "EXECUTABLE") unset(export_arg) @@ -216,7 +245,10 @@ function(rocm_install_targets) NAMELINK_ONLY ) endif() - if(ROCM_SYMLINK_LIBS AND NOT WIN32 AND T_TYPE MATCHES ".*_LIBRARY" + if(ROCM_SYMLINK_LIBS AND PARSE_PRIVATE) + message(WARNING "ROCM_SYMLINK_LIBS is not supported with PRIVATE.") + endif() + if(ROCM_SYMLINK_LIBS AND NOT PARSE_PRIVATE AND NOT WIN32 AND T_TYPE MATCHES ".*_LIBRARY" AND NOT T_TYPE STREQUAL "INTERFACE_LIBRARY") string(TOLOWER "${PROJECT_NAME}" LINK_SUBDIR) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_symlink.cmake diff --git a/share/rocmcmakebuildtools/cmake/ROCMTest.cmake b/share/rocmcmakebuildtools/cmake/ROCMTest.cmake index 8d5a7231..f534ea42 100644 --- a/share/rocmcmakebuildtools/cmake/ROCMTest.cmake +++ b/share/rocmcmakebuildtools/cmake/ROCMTest.cmake @@ -221,11 +221,9 @@ function(rocm_install_test) set(INSTALL_PREFIX "$") if(PARSE_TARGETS) foreach(TARGET ${PARSE_TARGETS}) - if(POLICY CMP0095) - set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "\${ORIGIN}/../../../lib") - else() - set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "\\\${ORIGIN}/../../../lib") - endif() + set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "$ORIGIN/../../../../lib") + # Adding RPATH to public tests to point to private libraries. + set_property(TARGET ${TARGET} APPEND PROPERTY INSTALL_RPATH "$ORIGIN/../../../../lib/${PROJECT_NAME}/lib") endforeach() install( TARGETS ${PARSE_TARGETS} diff --git a/test/libprivate/CMakeLists.txt b/test/libprivate/CMakeLists.txt new file mode 100644 index 00000000..42d68594 --- /dev/null +++ b/test/libprivate/CMakeLists.txt @@ -0,0 +1,51 @@ +################################################################################ +# Copyright (C) 2024 Advanced Micro Devices, Inc. +################################################################################ + + +cmake_minimum_required (VERSION 3.5) +project(libprivate CXX) + +find_package(ROCmCMakeBuildTools) + +include(ROCMInstallTargets) +include(ROCMPackageConfigHelpers) +include(ROCMSetupVersion) +include(ROCMInstallSymlinks) +include(ROCMCreatePackage) + +rocm_setup_version(VERSION 1.0.0) + +if(ROCM_PREFIX) +rocm_create_package( + NAME simple-private + PREFIX ${ROCM_PREFIX} + MAINTAINER "Amd amd@amd.com" + PTH + LDCONFIG) +else() +rocm_create_package( + NAME simple-private + MAINTAINER "Amd amd@amd.com" + PTH + LDCONFIG) +endif() + +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) + +add_library(simple_private simpleprivate.cpp) +#rocm_set_soversion(simple-private 1.1.2) + +add_executable(simple_private_main main.cpp) +target_link_libraries(simple_private_main simple_private) + +if(ROCM_PREFIX) + rocm_install_targets(PRIVATE TARGETS simple_private simple_private_main INCLUDE include PREFIX ${ROCM_PREFIX}) + rocm_export_targets(TARGETS simple_private INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/importtarget.cmake PREFIX ${ROCM_PREFIX}) + rocm_install_symlink_subdir(${ROCM_PREFIX}) +else() + rocm_install_targets(PRIVATE TARGETS simple_private simple_private_main INCLUDE include) + rocm_export_targets(TARGETS simple_private INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/importtarget.cmake) +endif() diff --git a/test/libprivate/LICENSE b/test/libprivate/LICENSE new file mode 100644 index 00000000..6d0ea731 --- /dev/null +++ b/test/libprivate/LICENSE @@ -0,0 +1,3 @@ +This is a placeholder license file for the purposes of testing, and is not the license for this repository or the files +contained in this directory. The license for rocm-cmake (including all files in this directory) can be located at +"https://github.com/RadeonOpenCompute/rocm-cmake/blob/master/LICENSE". \ No newline at end of file diff --git a/test/libprivate/importtarget.cmake b/test/libprivate/importtarget.cmake new file mode 100644 index 00000000..76a90f8b --- /dev/null +++ b/test/libprivate/importtarget.cmake @@ -0,0 +1,3 @@ +# ###################################################################################################################### +# Copyright (C) 2024 Advanced Micro Devices, Inc. +# ###################################################################################################################### diff --git a/test/libprivate/include/simpleprivate.h b/test/libprivate/include/simpleprivate.h new file mode 100644 index 00000000..520359d5 --- /dev/null +++ b/test/libprivate/include/simpleprivate.h @@ -0,0 +1,12 @@ +/******************************************************************************* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + ******************************************************************************/ + + +#ifndef GUARD_SIMPLE_PRIVATE_H +#define GUARD_SIMPLE_PRIVATE_H + +void simple_private(); + + +#endif diff --git a/test/libprivate/main.cpp b/test/libprivate/main.cpp new file mode 100644 index 00000000..f8b9e7d7 --- /dev/null +++ b/test/libprivate/main.cpp @@ -0,0 +1,6 @@ + +void simple_private(); + +int main() { + simple_private(); +} diff --git a/test/libprivate/simpleprivate.cpp b/test/libprivate/simpleprivate.cpp new file mode 100644 index 00000000..33f0f31e --- /dev/null +++ b/test/libprivate/simpleprivate.cpp @@ -0,0 +1,7 @@ +/******************************************************************************* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + ******************************************************************************/ + + +void simple_private() +{} diff --git a/test/pass/libprivate.cmake b/test/pass/libprivate.cmake new file mode 100644 index 00000000..e2992175 --- /dev/null +++ b/test/pass/libprivate.cmake @@ -0,0 +1,11 @@ +# ###################################################################################################################### +# Copyright (C) 2024 Advanced Micro Devices, Inc. +# ###################################################################################################################### + +install_dir( + ${TEST_DIR}/libprivate + CMAKE_ARGS -DROCM_SYMLINK_LIBS=OFF -DROCM_PREFIX=rocm + TARGETS package) +test_expect_file(${PREFIX}/lib/libprivate/include/simpleprivate.h) +test_expect_file(${PREFIX}/lib/libprivate/lib/libsimple_private.a) +install_dir(${TEST_DIR}/libprivate)