0

I have prepared a simple reproductive draft of my problem.

conanfile.txt:

[requires]
grpc/1.48.0

[generators]
cmake_paths

CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 3.18.3)
PROJECT(GRPC_FIND_PACKAGE_TEST)

# Default values
IF(NOT CMAKE_BUILD_TYPE 
    OR 
    (
        NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug" 
        AND NOT ${CMAKE_BUILD_TYPE} MATCHES "Release"
    )
)
  #SET(CMAKE_BUILD_TYPE Debug)
  MESSAGE(FATAL_ERROR "Build type is unknown!")
ENDIF()

SET(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")

    
# Conan initialization command
SET(CONAN_INITIALIZATION_COMMAND 
    conan install "${CMAKE_CURRENT_LIST_DIR}" -s build_type=${CMAKE_BUILD_TYPE} --build=missing
)
        
# Executes conan initialization command
EXECUTE_PROCESS(
    COMMAND ${CONAN_INITIALIZATION_COMMAND}
    WORKING_DIRECTORY "${BUILD_DIR}"
    RESULT_VARIABLE CMD_RESULT_CODE
    ERROR_VARIABLE CMD_ERROR
    COMMAND_ECHO STDOUT
)

INCLUDE(${BUILD_DIR}/conan_paths.cmake)

# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

Issue

For some reason, FIND_PACKAGE cannot find the grpc package. I had also error with:

find_package(Protobuf CONFIG REQUIRED)

I had to remove "CONFIG" and it started detecting this package properly.

What's going on? what's the problem?

montjet
  • 525
  • 1
  • 4
  • 13
  • https://cmake.org/cmake/help/latest/command/find_package.html CONFIG mode looks for `package_name.config`. MODULE mode loosk for `FindPackage.cmake` – Sergey Kolesnik Aug 06 '22 at 08:04
  • also I would rather avoid exposing Conan within your CMakeLists.txt. As far as I remember, you can provide a Conan toolchain file for cmake, which will contain all the necessary variables that are needed for `find_package` to get the packages from the right place – Sergey Kolesnik Aug 06 '22 at 08:07
  • The `grpc` package from ConanCenter (all packages from ConanCenter), do not package xxx-config.cmake scripts, but they need some other generators, like ``CMakeDeps`` to generate files for them on the fly (and other generators for other build systems) – drodri Aug 08 '22 at 16:26

0 Answers0