Any way to integrate conan into my existing cmake project

59 Views Asked by At

I have used this command to full deploy in my project

conan install . --output-folder=dependencies --deployer=full_deploy --generator=CMakeToolchain pause

The problem is that it generates a CMakePresets.json and a CMakeUserPresets.json but I ALREADY HAVE ONE IN MY PROJECT

I want to only use the conan_toolchain.cmake that it makes to find the conan dependencies for my cmake build

1

There are 1 best solutions below

0
Loop On

The solution that worked for me

I had to specify arch as x86 (we are building 32 bit, and default from conan is 64 bit)

conan install ..\app\Service\. --output-folder=dependencies --deployer=full_deploy --remote=adm-alm-conan-dev -s build_type=Release -s arch=x86 --build=missing

Additionally, I had to use both CMakeDeps and CMakeToolkit

I only had toolkit

After which it made the correct files which I can find with find_package()

Step 1: Add what open source dependency we need in conanfile.py (for example, from Conan Central) conanfile.py Example:

def requirements(self):
    #Example:
    self.requires("grpc/1.54.3")   

Step 2: Then consume it in the target CMakeLists.txt you want CMakeLists.txt Example:

find_package(gRPC REQUIRED)
find_package(Protobuf REQUIRED)
# Link the conan imported dependencies
target_link_libraries(${PROJECT_NAME} PRIVATE
    gRPC::grpc++
    protobuf::libprotobuf
)