From e4e6bdcf57c2a4d860b38aa6a43a643318178433 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 17 Sep 2024 10:21:12 +0200 Subject: [PATCH] Fix "target with the same name already exists" ``` CMake Error at /__w/parPE/parPE/deps/AMICI/build/AmiciConfig.cmake:60 (add_library): add_library cannot create imported target "SUNDIALS::KLU" because another target with the same name already exists. Call Stack (most recent call first): model/CMakeLists.txt:38 (find_package) CMake Error at /__w/parPE/parPE/deps/AMICI/build/AmiciConfig.cmake:61 (target_link_libraries): Cannot specify link libraries for target "SUNDIALS::KLU" which is not built by this project. Call Stack (most recent call first): model/CMakeLists.txt:38 (find_package) -- Configuring incomplete, errors occurred! ``` --- deps/AMICI/cmake/AmiciConfig.cmake | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/deps/AMICI/cmake/AmiciConfig.cmake b/deps/AMICI/cmake/AmiciConfig.cmake index e73bc579..531840d7 100644 --- a/deps/AMICI/cmake/AmiciConfig.cmake +++ b/deps/AMICI/cmake/AmiciConfig.cmake @@ -33,16 +33,18 @@ find_dependency(KLU REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/AmiciFindBLAS.cmake") -add_library(SUNDIALS::KLU INTERFACE IMPORTED) -target_link_libraries( - SUNDIALS::KLU - INTERFACE "${KLU_STATIC}" - INTERFACE "${COLAMD_STATIC}" - INTERFACE "${BTF_STATIC}" - INTERFACE "${AMD_STATIC}" - INTERFACE "${SUITESPARSE_CONFIG_STATIC}") -set_target_properties(SUNDIALS::KLU PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${KLU_INCLUDE_DIR}") +if(NOT TARGET SUNDIALS::KLU) + add_library(SUNDIALS::KLU INTERFACE IMPORTED) + target_link_libraries( + SUNDIALS::KLU + INTERFACE "${KLU_STATIC}" + INTERFACE "${COLAMD_STATIC}" + INTERFACE "${BTF_STATIC}" + INTERFACE "${AMD_STATIC}" + INTERFACE "${SUITESPARSE_CONFIG_STATIC}") + set_target_properties(SUNDIALS::KLU PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${KLU_INCLUDE_DIR};${KLU_INCLUDE_DIR}/suitesparse") +endif() find_dependency(SUNDIALS REQUIRED PATHS "@CMAKE_SOURCE_DIR@/ThirdParty/sundials/build/@CMAKE_INSTALL_LIBDIR@/cmake/sundials/")