From 26f2633264a9b7e53cbba3cab94d512cd03a0fc1 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Tue, 9 Apr 2024 23:52:27 +0200 Subject: [PATCH] Do not re-define imported targets in rerun_sdkConfig.cmake --- rerun_cpp/Config.cmake.in | 50 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/rerun_cpp/Config.cmake.in b/rerun_cpp/Config.cmake.in index d1cac77cd438..c093c4432b0b 100644 --- a/rerun_cpp/Config.cmake.in +++ b/rerun_cpp/Config.cmake.in @@ -5,16 +5,18 @@ include("${CMAKE_CURRENT_LIST_DIR}/rerun_sdkTargets.cmake") set(RERUN_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}/../..") if(@RERUN_INSTALL_RERUN_C@) - # Setup `rerun_c` (imported libraries can't be exported!) - add_library(rerun_c STATIC IMPORTED GLOBAL) - get_filename_component(RERUN_C_LIB_NAME "@RERUN_C_LIB_LOCATION@" NAME) - set_target_properties(rerun_c PROPERTIES IMPORTED_LOCATION "${RERUN_LIB_DIR}/${RERUN_C_LIB_NAME}") - if(APPLE) - target_link_libraries(rerun_c INTERFACE "-framework CoreFoundation" "-framework IOKit") - elseif(UNIX) # if(LINUX) # CMake 3.25 - target_link_libraries(rerun_c INTERFACE "-lm -ldl -pthread") - elseif(WIN32) - target_link_libraries(rerun_c INTERFACE ws2_32.dll Bcrypt.dll Userenv.dll ntdll.dll) + if(NOT TARGET rerun_c) + # Setup `rerun_c` (imported libraries can't be exported!) + add_library(rerun_c STATIC IMPORTED GLOBAL) + get_filename_component(RERUN_C_LIB_NAME "@RERUN_C_LIB_LOCATION@" NAME) + set_target_properties(rerun_c PROPERTIES IMPORTED_LOCATION "${RERUN_LIB_DIR}/${RERUN_C_LIB_NAME}") + if(APPLE) + target_link_libraries(rerun_c INTERFACE "-framework CoreFoundation" "-framework IOKit") + elseif(UNIX) # if(LINUX) # CMake 3.25 + target_link_libraries(rerun_c INTERFACE "-lm -ldl -pthread") + elseif(WIN32) + target_link_libraries(rerun_c INTERFACE ws2_32.dll Bcrypt.dll Userenv.dll ntdll.dll) + endif() endif() endif() @@ -23,15 +25,19 @@ endif() if(@RERUN_DOWNLOAD_AND_BUILD_ARROW@ AND NOT @RERUN_ARROW_LINK_SHARED@) message(STATUS "Rerun is using bundled arrow library.") - add_library(rerun_arrow_target STATIC IMPORTED GLOBAL) - get_filename_component(RERUN_ARROW_LIB_NAME "@RERUN_ARROW_LIBRARY_FILE@" NAME) - set_target_properties(rerun_arrow_target PROPERTIES IMPORTED_LOCATION "${RERUN_LIB_DIR}/${RERUN_ARROW_LIB_NAME}") + if(NOT TARGET rerun_arrow_target) + add_library(rerun_arrow_target STATIC IMPORTED GLOBAL) + get_filename_component(RERUN_ARROW_LIB_NAME "@RERUN_ARROW_LIBRARY_FILE@" NAME) + set_target_properties(rerun_arrow_target PROPERTIES IMPORTED_LOCATION "${RERUN_LIB_DIR}/${RERUN_ARROW_LIB_NAME}") + endif() # We have to explicitly opt in the arrow bundled dependencies, otherwise we're missing the symbols for mimalloc. - add_library(arrow_targetBundledDeps STATIC IMPORTED) - get_filename_component(RERUN_ARROW_DEPS_LIB_NAME "@RERUN_ARROW_BUNDLED_DEPENDENCIES_FILE@" NAME) - set_target_properties(arrow_targetBundledDeps PROPERTIES IMPORTED_LOCATION "${RERUN_LIB_DIR}/${RERUN_ARROW_DEPS_LIB_NAME}") - target_link_libraries(rerun_arrow_target INTERFACE arrow_targetBundledDeps) + if(NOT TARGET arrow_targetBundledDeps) + add_library(arrow_targetBundledDeps STATIC IMPORTED) + get_filename_component(RERUN_ARROW_DEPS_LIB_NAME "@RERUN_ARROW_BUNDLED_DEPENDENCIES_FILE@" NAME) + set_target_properties(arrow_targetBundledDeps PROPERTIES IMPORTED_LOCATION "${RERUN_LIB_DIR}/${RERUN_ARROW_DEPS_LIB_NAME}") + target_link_libraries(rerun_arrow_target INTERFACE arrow_targetBundledDeps) + endif() else() if(@RERUN_DOWNLOAD_AND_BUILD_ARROW@ AND @RERUN_ARROW_LINK_SHARED@) message(WARNING @@ -45,9 +51,11 @@ else() message(STATUS "Rerun is using a system installed libArrow.") - if(@RERUN_ARROW_LINK_SHARED@) - add_library(rerun_arrow_target ALIAS Arrow::arrow_shared) - else() - add_library(rerun_arrow_target ALIAS Arrow::arrow_static) + if(NOT TARGET rerun_arrow_target) + if(@RERUN_ARROW_LINK_SHARED@) + add_library(rerun_arrow_target ALIAS Arrow::arrow_shared) + else() + add_library(rerun_arrow_target ALIAS Arrow::arrow_static) + endif() endif() endif()