Skip to content

Commit

Permalink
Only link library specific files (#84)
Browse files Browse the repository at this point in the history
* Only link library specific files

* Circumvent lack of genex in `install(CODE)`

* Create cmake symlink in export

* Correct formatting

* Don't use symlink_libs in tests

* Don't try to symlink interface libraries

* Update test to use Windows 2022

* Switch to Windows 2019

* Skip CMake 3.10 on Windows

* Switch to macos 10-15
  • Loading branch information
lawruble13 authored Apr 6, 2022
1 parent c4b8a73 commit 644af5c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ jobs:
matrix:
platform:
- ubuntu-18.04
- macos-10.14
- windows-2016
- macos-10.15
- windows-2019
cmake-version:
- 3.20.0
- 3.10.2
exclude:
- platform: windows-2019
cmake-version: 3.10.2

steps:
- uses: actions/checkout@v1
Expand Down
48 changes: 38 additions & 10 deletions share/rocm/cmake/ROCMInstallTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,26 @@ function(rocm_install_targets)
NAMELINK_ONLY
)
endif()
if(T_TYPE MATCHES ".*_LIBRARY" AND ROCM_SYMLINK_LIBS AND NOT ROCM_CREATED_${PROJECT_NAME}_SYMLINK
AND NOT CMAKE_HOST_WIN32)

set(ROCM_CREATED_${PROJECT_NAME}_SYMLINK TRUE CACHE INTERNAL "Record symlink created.")
if(ROCM_SYMLINK_LIBS AND NOT WIN32 AND T_TYPE MATCHES ".*_LIBRARY"
AND NOT T_TYPE STREQUAL "INTERFACE_LIBRARY")
string(TOLOWER "${PROJECT_NAME}" LINK_SUBDIR)

set(INSTALL_CMD "
set(LINK_DIR \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${LINK_SUBDIR})
file(MAKE_DIRECTORY \${LINK_DIR})
execute_process(COMMAND ln -sf ../lib \${LINK_DIR}/${ROCM_INSTALL_LIBDIR})
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_symlink.cmake
CONTENT "
set(SRC_DIR \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX})
set(LINK_DIR \${SRC_DIR}/${LINK_SUBDIR})
if(NOT EXISTS \${LINK_DIR}/${ROCM_INSTALL_LIBDIR})
file(MAKE_DIRECTORY \${LINK_DIR}/${ROCM_INSTALL_LIBDIR})
endif()
file(RELATIVE_PATH LINK_PATH
\${LINK_DIR}/${ROCM_INSTALL_LIBDIR}
\${SRC_DIR}/${ROCM_INSTALL_LIBDIR})
execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink
\${LINK_PATH}/$<TARGET_LINKER_FILE_NAME:${TARGET}>
\${LINK_DIR}/${ROCM_INSTALL_LIBDIR}/$<TARGET_LINKER_FILE_NAME:${TARGET}>
)
")
rocm_install(CODE "${INSTALL_CMD}")

rocm_install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_symlink.cmake")
endif()
endforeach()
endfunction()
Expand Down Expand Up @@ -319,4 +327,24 @@ function(rocm_export_targets)
DESTINATION
${CONFIG_PACKAGE_INSTALL_DIR})

if(ROCM_SYMLINK_LIBS AND NOT WIN32)
string(TOLOWER "${PROJECT_NAME}" LINK_SUBDIR)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cmake_symlink.cmake"
CONTENT "
set(SRC_DIR \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX})
set(LINK_DIR \${SRC_DIR}/${LINK_SUBDIR})
if(NOT EXISTS \${LINK_DIR}/${ROCM_INSTALL_LIBDIR}/cmake)
file(MAKE_DIRECTORY \${LINK_DIR}/${ROCM_INSTALL_LIBDIR}/cmake)
endif()
file(RELATIVE_PATH LINK_PATH
\${LINK_DIR}/${ROCM_INSTALL_LIBDIR}/cmake
\${SRC_DIR}/${CONFIG_PACKAGE_INSTALL_DIR}
)
execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink
\${LINK_PATH}
\${LINK_DIR}/${CONFIG_PACKAGE_INSTALL_DIR}
)
")
rocm_install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/cmake_symlink.cmake")
endif()
endfunction()
2 changes: 1 addition & 1 deletion test/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function(install_dir DIR)
configure_dir(
${DIR}
TARGETS all ${PARSE_TARGETS} install
CMAKE_ARGS ${PARSE_CMAKE_ARGS})
CMAKE_ARGS ${PARSE_CMAKE_ARGS} -DROCM_SYMLINK_LIBS=OFF)
endfunction()

function(write_version_cmake DIR VERSION CONTENT)
Expand Down

0 comments on commit 644af5c

Please sign in to comment.