Skip to content

Commit

Permalink
Cherry-pick private lib changes into release 6.2 (#205)
Browse files Browse the repository at this point in the history
* Add flag to move libraries under project name (#188)

Co-authored-by: Paul Fultz II <pfultz2@yahoo.com>

* 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 <Lauren.Wrubleski@amd.com>

---------

Co-authored-by: Paul Fultz II <pfultz2@yahoo.com>
Co-authored-by: Lauren Wrubleski <Lauren.Wrubleski@amd.com>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent 5a86281 commit aa86563
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 17 deletions.
56 changes: 44 additions & 12 deletions share/rocmcmakebuildtools/cmake/ROCMInstallTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions share/rocmcmakebuildtools/cmake/ROCMTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,9 @@ function(rocm_install_test)
set(INSTALL_PREFIX "$<TARGET_PROPERTY:tests,ROCM_TEST_INSTALLDIR>")
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}
Expand Down
51 changes: 51 additions & 0 deletions test/libprivate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions test/libprivate/LICENSE
Original file line number Diff line number Diff line change
@@ -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".
3 changes: 3 additions & 0 deletions test/libprivate/importtarget.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ######################################################################################################################
# Copyright (C) 2024 Advanced Micro Devices, Inc.
# ######################################################################################################################
12 changes: 12 additions & 0 deletions test/libprivate/include/simpleprivate.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/libprivate/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

void simple_private();

int main() {
simple_private();
}
7 changes: 7 additions & 0 deletions test/libprivate/simpleprivate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*******************************************************************************
* Copyright (C) 2024 Advanced Micro Devices, Inc.
******************************************************************************/


void simple_private()
{}
11 changes: 11 additions & 0 deletions test/pass/libprivate.cmake
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit aa86563

Please sign in to comment.