conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
949 stars 1.73k forks source link

[question] protobuf/3.9.1 with cmake_paths generator #2091

Open pananton opened 4 years ago

pananton commented 4 years ago

Hello! I'm using conan protobuf/3.9.1 recipe in my project with cmake_paths generator. Here is one simple example of conan_paths.cmake:

set(CONAN_PROTOBUF_ROOT "/root/.conan/data/protobuf/3.9.1/_/_/package/66c5327ebdcecae0a01a863939964495fa019a06")

set(CMAKE_MODULE_PATH "/root/.conan/data/protobuf/3.9.1/_/_/package/66c5327ebdcecae0a01a863939964495fa019a06/lib/cmake/protobuf" ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR})

set(CMAKE_PREFIX_PATH "/root/.conan/data/protobuf/3.9.1/_/_/package/66c5327ebdcecae0a01a863939964495fa019a06/lib/cmake/protobuf" ${CMAKE_PREFIX_PATH} ${CMAKE_CURRENT_LIST_DIR})

I include this file to by project, but find_package fails. As you can see - cmake's variables used for searching package (CMAKE_MODULE_PATH and CMAKE_PREFIX_PATH) are not set to the root of protobuf directory and cmake's FindProtobuf module fails to do its job. If I manually set CMAKE_MODULEPATH to ```/root/.conan/data/protobuf/3.9.1//_/package/66c5327ebdcecae0a01a863939964495fa019a06``` then everything works fine as expected.

The question is why conan sets those cmake variables to such values?

uilianries commented 4 years ago

@pananton Protobuf is a special case, it requires extra cmake file exported by the project: https://github.com/conan-io/conan-center-index/blob/959001e539c45e4750d9e9b98ecde5f9e7d38ef6/recipes/protobuf/all/conanfile.py#L98

That's why is used a different path to load those modules. Did you try cmake_find_package too?

jgsogo commented 4 years ago

We strongly recommend you to use Conan generated files with cmake_find_package[_multi] generator. You can read other use-cases and some rationale in the docs (https://github.com/conan-io/conan-center-index/wiki/FAQ#why-are-cmake-findconfig-files-and-pkg-config-files-not-packaged) and this issue.

Croydon commented 4 years ago

and this issue.

Well, "this issue" is literally --this-- issue 😄

jgsogo commented 4 years ago

hahahaha, have a look to that issue then 🤦

(I've edited the comment above too)