1

I want to use conan in an existing CMake project. I have the conanfile.txt in the root directory and run conan install . --build=missing --output-folder=build/conan, but I don't know how to get CMake to find the dependencies it has built/downloaded.

I am using the VSCode CMake extension and it runs this command to generate: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ -S/home/me/myproject -B/home/me/myproject/build/Debug -G Ninja

conanfile.txt

[requires]
boost/1.85.0
fmt/10.2.1
openssl/3.0.9
cryptopp/8.9.0

[generators]
CMakeDeps

Also, I am using find_package in CMake to find them.

2
  • You need to use the CMakeToolchain generator and then use -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake or better the cmake --preset conan-default/conan-release. Also better to use the [layout] with cmake_layout and forget about the --output-folder argument Commented Jun 3, 2024 at 16:24
  • You also need to align the dependencies arguments. If you want to build in Debug, then you need to pass the right arguments to conan install, like conan install ... -s build_type=Debug. Likewise, if those compilers are not the default ones in the system (in that case you wouldn't need to define them in command line), better define them in a profile file too, in the [buildenv] section as CC/CXX env-vars, or with [conf] like tools.build:compiler_executables. Check the getting started tutorial: docs.conan.io/2/tutorial/consuming_packages/… Commented Jun 3, 2024 at 16:26

1 Answer 1

0

A bit late to the party but it may help people landing on this page with the same issue.

I had a similar problem trying integrate conan 2 into my CMake workflow so wrote a CMake module to invoke (and even install, if needed) conan, possibly depending on CMake options or variables. It is available from https://github.com/tkhyn/cmake-conanfile. It requires a conanfile.py and doesn't work with conanfile.txt but the conversion is easy enough.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.