My project require protobuf 3.5.1, I built it and want cmake use it instead of installed in system (2.5.0). It is my CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(test)
set(ENV{PKG_CONFIG_PATH} "/path_to_protobuf/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Protobuf 3.5.1 REQUIRED)
link_directories(
${PROTOBUF_LIBRARY_DIRS}
)
include_directories(
src
${PROTOBUF_INCLUDE_DIRS}
)
protobuf_generate_cpp(
PROTO_SRCS PROTO_HDRS
../my_proto.proto
)
set(sourceDir "${PROJECT_SOURCE_DIR}/src")
file(GLOB_RECURSE allFiles "${sourceDir}/*.h" "${sourceDir}/*.cpp")
add_executable(
test
${allFiles}
${PROTO_SRCS}
${PROTO_HDRS})
target_link_libraries(
test
${PROTOBUF_LIBRARIES}
)
But cmake finishes with error message:
CMake Warning at lib_build/share/cmake-3.11/Modules/FindProtobuf.cmake:455 (message):
Protobuf compiler version 3.5.1 doesn't match library version 2.5.0
Call Stack (most recent call first):
CMakeLists.txt:36 (find_package)
CMake Error at lib_build/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Protobuf: Found unsuitable version "2.5.0", but required is
at least "3.5.1" (found /usr/lib64/libprotobuf.so;-lpthread)
Call Stack (most recent call first):
lib_build/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:376 (_FPHSA_FAILURE_MESSAGE)
lib_build/share/cmake-3.11/Modules/FindProtobuf.cmake:543 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:36 (find_package)
— Configuring incomplete, errors occurred!
See also "/home/user/app/CMakeFiles/CMakeOutput.log".
See also "/home/user/app/CMakeFiles/CMakeError.log".
How to specify module search path correctly? Can I do that without writing self FindProtobuf.cmake file?