conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
944 stars 1.71k forks source link

[package] eigen3/3.3.9: CMake Warning stating that target name `Eigen3::Eigen` already exists. #8949

Open Lorac opened 2 years ago

Lorac commented 2 years ago

Package and Environment Details (include every applicable attribute)

Conan profile (output of conan profile show default or conan profile show <profile> if custom profile is in use)

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=7
compiler.libcxx=libstdc++
build_type=Release
[options]
[conf]
[build_requires]
[env]

Steps to reproduce (Include if Applicable)

If you have a requirement with eigen and find_package(Eigen3 CONFIG) you get the warning.

[requires]
eigen/3.3.9#4c35d86148747164763f493d90277d8f
[generators]
CMakeDeps

You get the following warning:

CMake Warning at build/x64/Eigen3Targets.cmake:15 (message):
  Component target name 'Eigen3::Eigen' already exists.
Call Stack (most recent call first):
  build/x64/Eigen3Config.cmake:11 (include)
  CMakeLists.txt:154 (find_package)

If I don't use find_package I don't get a warning, but I should use find_package, shouldn't I?

find_package(Eigen3 REQUIRED CONFIG)

SpaceIm commented 2 years ago

Looks like a small issue in CMakeDeps generator rather than eigen recipe itself. Maybe Eigen3Targets.cmake generated by CMakeDeps is included multiple time through multiple find_package(Eigen) of different downstream libraries, leading to this warning?

Indeed this file contains:

foreach(_COMPONENT ${eigen_COMPONENT_NAMES} )
    if(NOT TARGET ${_COMPONENT})
        add_library(${_COMPONENT} INTERFACE IMPORTED)
        conan_message(STATUS "Conan: Component target declared '${_COMPONENT}'")
    else()
        message(WARNING "Component target name '${_COMPONENT}' already exists.")
    endif()
endforeach()

It's worth noting that official config target files generated by install(EXPORT) have sophisticated multi inclusion guard logic that files generated by CMakeDeps seem to lack:

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget Eigen3::Eigen)
  list(APPEND _expectedTargets ${_expectedTarget})
  if(NOT TARGET ${_expectedTarget})
    list(APPEND _targetsNotDefined ${_expectedTarget})
  endif()
  if(TARGET ${_expectedTarget})
    list(APPEND _targetsDefined ${_expectedTarget})
  endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
  unset(_targetsDefined)
  unset(_targetsNotDefined)
  unset(_expectedTargets)
  set(CMAKE_IMPORT_FILE_VERSION)
  cmake_policy(POP)
  return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
  message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)

So it's not so different, but official config target files don't display warnings. I think it should be fixed in CMakeDeps generator

/cc @czoido