4

We can use meson build system in conan. But I cannot find any document about how to add conan package as dependency in meson.build. It is very simple in cmake, we can simply use conan_cmake_run. How can I do the similar thing in meson?

Wang
  • 7,250
  • 4
  • 35
  • 66

2 Answers2

2

Since meson has not supported Conan yet, we need to bridge them by ourselves. Fortunately it is simple, an example:


conan_pkgs= {
    'fmt':'fmt/5.3.0@',  # <- Must contain @, otherwise Conan will think it is a path
    # you can add more ...
}
deps=[]
foreach pkg_name, conan_ref : conan_pkgs
    module_path = meson.current_build_dir() / 'conan-cmake' / pkg_name
    run_command('conan','install',conan_ref, '-if',module_path,
        '-g','cmake_find_package', check: true)
    deps += dependency(pkg_name, method: 'cmake', cmake_module_path: module_path)
endforeach

executable('exe_need_deps',  ['main.cpp'],
    dependencies: deps
)

Reference: This gist

hydev
  • 66
  • 2
  • this actually does not work at least in 1.25. `conan install ref@ -if somepath` does not work as you expected. It will not install anything to that path if the package is already installed to standard place `.conan/data/` – Wang May 16 '20 at 19:09
  • Moreover, unless the package defined a deploy() method, the `-if` has no effect at all. – Wang May 16 '20 at 19:18
  • in order to copy everything depended on from conan/data to meson folder for packaging, I have to specify '-g deploy' – Wang May 16 '20 at 19:54
  • @Wang Maybe your packages need the `deploy` generator to work. For my C/C++ projects, the `cmake_find_package` is good enough, it generates the de facto FindXXX.cmake recipe which points to the `.conan/data/` cache and sets the appropriate flags. – hydev May 28 '20 at 13:23
  • In conan the term install does not mean to install the actual package to the path, but rather download the package into a cache and installing metadata to the specified path (unless you specify the deploy generator). This metadata depends on the generator that is used. This is really the answer I was looking for. – Jakob Stark Apr 08 '22 at 12:18
0

This is what I did:

run_command('conan', 'install', '--install-folder', meson.build_root(), meson.source_root(), check: true)
kpeace
  • 11
  • 2