c++cmakepoco-librariesconan

How to add c++ poco library using conan and cmake?


I'm a newbie with conan and i want to add poco library to my project using cmake. I installed poco 1.13.0 using:

$ conan install . --output-folder=build --build=missing.

Then i used new toolchain with:

$ cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release

Finally, i tried to add poco headers to my code but got build error: no such file or directory. I use CLion, CMake 3.28.1 and Conan 2.0.17. What did i do wrong?

CMakeLists.txt:

cmake_minimum_required(VERSION 3.27)
project(poco_test)

include_directories(build)

find_package(Poco REQUIRED)

add_executable(poco_test main.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE Poco::Poco)

conanfile.txt:

[requires]
poco/1.13.0

[generators]
CMakeDeps
CMakeToolchain

main.cpp:

#include <iostream>
#include "Poco/Exception.h"

int main() {
    return 0;
}

Solution

  • I've just tested your setup on my Ubuntu 22.04 with g++13.1.0 and CMake 3.28.3 and it works without any modifications. I'm able to build and run the compiled target.

    Based on your description ("no such file or directory"), it seems that you're referring to the error that the compiler doesn't have the include path to Poco's headers.

    In your CMakeLists.txt after specifying the executable, you can add:

    target_include_directories(${PROJECT_NAME} PRIVATE ${Poco_INCLUDE_DIRS})
    

    Q: How did I find Poco_INCLUDE_DIRS?

    A: Take a look into the poco's CMake files created during the conan installation, namely: PocoConfig.cmake and after it, Poco-release-x86_64-data.cmake