0

Let's say I have 2 different conanfile.py in a project and I'm calling conan install two times to install their dependencies. I'm having trouble while adding them to cmake.

If I use basic setup

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

it only includes latest one. Is it possible to include multiple conanbuildinfo.cmake files ?

Sirdavos
  • 75
  • 1
  • 9
  • 1
    No, you cant. Why do you need 2 conanfiles? Conanfile.py is a python script, you can customize as you need, only one recipe should be enough. – uilianries Mar 20 '20 at 13:35
  • I want to keep dependencies as separate for 2 different module. For instance I was thinking to have one general conanfile.py and other conanfile.py for other modules. The only way to keep this is then update general conanfile.py with the requirement in modules if modules exist, I guess ? – Sirdavos Mar 20 '20 at 14:15
  • what do you mean by `other modules`? Is it submodules? – ymochurad Mar 20 '20 at 15:29
  • yes submodules. – Sirdavos Mar 20 '20 at 16:38
  • @uilianries the problem that I'm trying to solve is I have different submodules in my project. I may include all of them or some of them or just one. Lets say I use all modules and I put all dependencies in one conanfile.py, thats fine. But if I add ony one module and use same conanfile.py, it will install again all dependencies which is not effective. Does conan have a solution for this kind of situation ? – Sirdavos Mar 21 '20 at 13:21
  • @uilianries, what if I have two build targets and I want their dependencies to be separated? Let's assume, I have a lib and unit tests for it, I don't want to add gtest as a dependency for lib, only for unit tests. What workflow suggest Conan for this case? I'm interested in a solution that doesn't use CMake wrapper for Conan. – isnullxbh Nov 30 '21 at 19:53

1 Answers1

2

If you have 2 completely separate projects, you can have 2 different conanfiles and put the generated files in different folders:

$ conan install conanfile1.py --install-folder=folder1
$ conan install conanfile2.py --install-folder=folder2

Then in your first project:

include(<...>/folder1/conanbuildinfo.cmake)
conan_basic_setup()

And in your second project:

include(<...>/folder2/conanbuildinfo.cmake)
conan_basic_setup()

You would need to define some consistent convention to locate the generated files for each project.

Note, however, that if the different modules are intended to use together, like linked together lately, if you don't use the same dependencies and same versions, you will probably get linking or runtime errors in your global application. If the modules are related and you want to use the same versions of the dependencies, then you definitely want to use just 1 conanfile with all dependencies defined in it.

Note that there are different ways to define the specific dependencies that you want, even if you use only 1 conanfile:

  • You can use the TARGETS of the cmake generator:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)```

add_library(mylib1 ... <sources>)
target_link_libraries(mylib1 PUBLIC CONAN_PKG::Dep1 CONAN_PKG::Dep2)

add_library(mylib2 ... <sources>)
target_link_libraries(mylib2 PUBLIC CONAN_PKG::Dep3 CONAN_PKG::Dep4)
  • The cmake_find_package generators also generate one findXXXX.cmake file for each package in the dependency graph. You can use the find_package(XXXX) and later the results, specifying different dependencies. The cmake_find_package_multi generator is recommended.
drodri
  • 5,157
  • 15
  • 21
  • For now I will go your first suggestion. Its easy to manage. One conanfile usage is not effective since I need to download all the packages even if I may not use them. – Sirdavos Mar 22 '20 at 15:48