Conan and Cmake: target already exists

665 views Asked by At

I use the conan_cmake_run() macro for CMake. When I add two libs with the same external dep. it results in an error message.

Example:

conan_cmake_run(REQUIRES boost/1.74.0 BASIC_SETUP CMAKE_TARGETS)
conan_cmake_run(REQUIRES hdf5/1.10.6  BASIC_SETUP CMAKE_TARGETS)

Boost and HDF5 will add zlib as an external dep. due to that, this results in the following error message during CMake configure.

CMake Error at build/conanbuildinfo_multi.cmake:152 (add_library):
  add_library cannot create imported target "CONAN_PKG::zlib" because another
  target with the same name already exists.
Call Stack (most recent call first):
  build/conanbuildinfo_multi.cmake:286 (conan_define_targets)
  cmake/modules/conan.cmake:515 (conan_basic_setup)
  CMakeLists.txt:104 (conan_cmake_run)

Is there a way to explicitly not add the "CONAN_PKG::zlib" for boost/1.74.0 or hdf5/1.10.6?

Thanks a lot in advance!

Best,

1

There are 1 answers

0
drodri On

It is very important not to run twice the cmake_conan_run, but just once with multiple parameters, something like:

conan_cmake_run(REQUIRES boost/1.74.0 hdf5/1.10.6 BASIC_SETUP CMAKE_TARGETS)

Doing separate runs, the second one will overwrite the results from the previous one. Furthermore, in the installation there could be conflicts (like boost/1.74 depending on zlib/1.2.8 and hdf5/1.10.6 depending on zlib/1.2.11) that would be unnoticed. When installing the dependencies of a project, a single conan install, or a single conan_cmake_run() should be done.