LLNL / sundials

Official development repository for SUNDIALS - a SUite of Nonlinear and DIfferential/ALgebraic equation Solvers. Pull requests are welcome for bug fixes and minor changes.
https://computing.llnl.gov/projects/sundials
BSD 3-Clause "New" or "Revised" License
522 stars 130 forks source link

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

Closed dweindl closed 1 month ago

dweindl commented 2 months ago

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:

Environment:

Anything else:

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

https://github.com/LLNL/sundials/blob/c28eaa3764a03705d61decb6025b409360e9d53f/cmake/tpl/FindKLU.cmake#L33-L40

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

https://github.com/LLNL/sundials/blob/c28eaa3764a03705d61decb6025b409360e9d53f/cmake/tpl/FindKLU.cmake#L40

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()
balos1 commented 1 month ago

Fixed by #582.