microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.19k stars 6.39k forks source link

lucid bumbles #3680

Closed lucidbee closed 4 years ago

lucidbee commented 6 years ago

I am trying to use vcpkg for a protobuf c++ library. That seems okay so far.

But I also use protoc in my build process, that is the protobuf compiler.

I had a custom FindProtobuf that had some functions that did the compilation with protoc. It declared a function called protobuf_generate_cpp. This is missing when I use: set(CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake) I have this in my CMakeLists.txt: set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/scripts/cmake" ${CMAKE_MODULE_PATH}) which defines the function but it doesn't take effect when I use CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake It used to take effect but it doesn't now that I'm using vcpkg.

I see that there is a file in the vcpkg installed directory vcpkg/installed/x64-windows/share/protobuf/protobuf-module.cmake with the comment:

This file contains backwards compatibility patches for various legacy functions and variables

It seems to support the functionality I want. How do I get my cmake scripts to see it and use it? thanks.

JackBoosY commented 4 years ago

Now, you can use the following code to use it:

    find_package(protobuf CONFIG REQUIRED)
    target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)