Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] CMake: cannot create ALIAS target "SUNDIALS::KLU" because target "SuiteSparse::KLU" is itself an ALIAS #579

Closed
dweindl opened this issue Sep 28, 2024 · 1 comment

Comments

@dweindl
Copy link

dweindl commented Sep 28, 2024

Current Behavior:

Configuring sundials with KLU fails with

  -- KLU version: 2.3.4
  -- KLU include: /home/dweindl/src/AMICI-devel/python/sdist/amici/include/suitesparse
  -- KLU library: /home/dweindl/src/AMICI-devel/python/sdist/amici/lib/libklu.a
  -- KLU static:  /home/dweindl/src/AMICI-devel/python/sdist/amici/lib/libklu.a
  CMake Error at cmake/tpl/FindKLU.cmake:40 (add_library):
    add_library cannot create ALIAS target "SUNDIALS::KLU" because target
    "SuiteSparse::KLU" is itself an ALIAS.
  Call Stack (most recent call first):
    cmake/tpl/SundialsKLU.cmake:48 (find_package)
    cmake/SundialsSetupTPLs.cmake:113 (include)
    CMakeLists.txt:186 (include)

Expected Behavior:

Configuring succeeds.

Steps To Reproduce:

  • Build SuiteSparse 7.8.2 with BUILD_SHARED_LIBS=OFF
  • Set CMAKE_PREFIX_PATH so the SuiteSparse CMake config can be found
  • Configure sundials with -DENABLE_KLU=ON (and not setting any KLU_*)

Environment:

  • SUNDIALS: 7.1.1
  • SuiteSparse: 7.8.2
  • OS: Ubuntu 24.04
  • CMake: 3.30.3

Anything else:

Here, sundials tries to create an ALIAS target SUNDIALS::KLU for SuiteSparse::KLU:

if (NOT (KLU_INCLUDE_DIR OR KLU_LIBRARY_DIR OR KLU_LIBRARY))
# Prefer the import target from upstream SuiteSparse if it is available
# and the user didn't point to a specific (different) version.
find_package(KLU CONFIG)
if(TARGET SuiteSparse::KLU)
if(NOT TARGET SUNDIALS::KLU)
add_library(SUNDIALS::KLU ALIAS SuiteSparse::KLU)

This works as long as SuiteSparse::KLU is not an alias target itself.

However, for a SuiteSparse static-only build, SuiteSparse::KLU is already an ALIAS of SuiteSparse::KLU_static:

https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/c8c3a9de1c8eef54da5ff19fd0bcf7ca6e8bc9de/KLU/Config/KLUConfig.cmake.in#L113-L116

Proposed fix:

Replace

add_library(SUNDIALS::KLU ALIAS SuiteSparse::KLU)

by

      get_target_property(klu_aliased_target SuiteSparse::KLU ALIASED_TARGET)
      if (klu_aliased_target)
          add_library(SUNDIALS::KLU ALIAS ${klu_aliased_target})
      else()
          add_library(SUNDIALS::KLU ALIAS SuiteSparse::KLU)
      endif()
dweindl added a commit to dweindl/sundials that referenced this issue Sep 30, 2024
Fixes a CMake configuration issue related to aliasing an ``ALIAS`` target when
using ``ENABLE_KLU=ON`` in combination with a static-only build of SuiteSparse.

See LLNL#579 for details.

Fixes LLNL#579.

Signed-off-by: Daniel Weindl <[email protected]>
dweindl added a commit to dweindl/sundials that referenced this issue Sep 30, 2024
Fixes a CMake configuration issue related to aliasing an ``ALIAS`` target when
using ``ENABLE_KLU=ON`` in combination with a static-only build of SuiteSparse.

See LLNL#579 for details.

Fixes LLNL#579.

Signed-off-by: Daniel Weindl <[email protected]>
@balos1 balos1 added this to the SUNDIALS Next milestone Sep 30, 2024
balos1 pushed a commit that referenced this issue Sep 30, 2024
Fixes a CMake configuration issue related to aliasing an ``ALIAS``
target when using ``ENABLE_KLU=ON`` in combination with a static-only
build of SuiteSparse.

See #579 for details.

Fixes #579.

---------

Signed-off-by: Daniel Weindl <[email protected]>
Co-authored-by: Daniel R. Reynolds <[email protected]>
@balos1
Copy link
Member

balos1 commented Oct 8, 2024

Fixed by #582.

@balos1 balos1 closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants