From 8fd41bd51312445774baaf763eb3992df66f1ea2 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Tue, 16 Jun 2020 21:54:57 -0500 Subject: [PATCH] Restrict the application of --whole-library in the static builds. Interface target now depends directly on rocr dependencies and indirectly on the rocr source target. This duplicates some code but seems to be necessary to restrict application of whole-library. Change-Id: I35e836de38aad1eee5387531362871293e30da9d --- runtime/hsa-runtime/CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/runtime/hsa-runtime/CMakeLists.txt b/runtime/hsa-runtime/CMakeLists.txt index d766066dee..62c92326e3 100644 --- a/runtime/hsa-runtime/CMakeLists.txt +++ b/runtime/hsa-runtime/CMakeLists.txt @@ -253,9 +253,22 @@ set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY VERSION "${SO_VERSION_STRI set_property ( TARGET ${CORE_RUNTIME_TARGET} PROPERTY SOVERSION "${VERSION_MAJOR}" ) ## Add the public interface export target if doing a static build. +## Bind ROCr dependencies to the interface target rather than to the source build +## target so that -Wl,--whole-archive is tightly applied. Requires binding +## indirectly to the source build taret. if( NOT ${BUILD_SHARED_LIBS} ) add_library(${CORE_RUNTIME_NAME} INTERFACE) - target_link_libraries ( ${CORE_RUNTIME_NAME} INTERFACE -Wl,$/lib/cmake/${CORE_RUNTIME_NAME}/${LNKSCR} -Wl,--whole-archive ${CORE_RUNTIME_NAME}::${CORE_RUNTIME_TARGET} -Wl,--no-whole-archive) + + ## Bind to source build target interface but not its link requirements. + target_include_directories( ${CORE_RUNTIME_NAME} INTERFACE $ ) + target_link_libraries ( ${CORE_RUNTIME_NAME} INTERFACE -Wl,$/lib/cmake/${CORE_RUNTIME_NAME}/${LNKSCR} + -Wl,--whole-archive $ -Wl,--no-whole-archive) + add_dependencies( ${CORE_RUNTIME_NAME} ${CORE_RUNTIME_TARGET} ) + + ## Add external link requirements. + target_link_libraries ( ${CORE_RUNTIME_NAME} INTERFACE hsakmt::hsakmt ) + target_link_libraries ( ${CORE_RUNTIME_NAME} INTERFACE elf::elf dl pthread rt ) + install ( TARGETS ${CORE_RUNTIME_NAME} EXPORT ${CORE_RUNTIME_NAME}Targets ) endif()