Um dies zu emulieren, habe ich die Quellcode-Dateien in ein Verzeichnis namens Beispielexecutable . vcpkg.json befindet sich im Root-Verzeichnis. Dies scheint darauf hinzudeuten, dass die Regel lautet, dass die Abhängigkeitsdatei im selben Verzeichnis wie die root CMakelists gefunden werden muss. Es ist vielleicht etwas anderes, zum Beispiel eine vcpkg.json Abhängigkeitsdatei muss in das gleiche Verzeichnis wie eine cmakelists.txt -Datei platziert werden, wenn dieses cmakelists.txt Datei eine Abhängigkeit über das Find_Package -Who -Codes -Befehl spezifiziert. Erleuchtung?
Code: Select all
example-executable/
CMakeLists.txt
main.cpp
message.proto
vcpkg.json # ok here !
cmake-build.sh
< /code>
cmake-build.sh
Code: Select all
#!/bin/bash
cmake -B build -S example-executable -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
cmake --build build
< /code>
The other files:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(vcpkg-project-test CXX)
find_package(Protobuf REQUIRED)
set(CMAKE_CXX_STANDARD 23)
set(PROTO_FILES message.proto)
set(PROTO_GENERATE_DIR ${CMAKE_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${PROTO_GENERATE_DIR})
protobuf_generate_cpp(
PROTO_SRCS PROTO_HDRS ${PROTO_FILES}
)
add_library(
lib_proto
STATIC
${PROTO_SRCS}
)
target_include_directories(
lib_proto
PUBLIC
${Protobuf_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(
lib_proto
PUBLIC
${Protobuf_LIBRARIES}
)
add_executable(
a.out
main.cpp
)
target_link_libraries(
a.out
PRIVATE
lib_proto
protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite
)
< /code>
Main.cpp
#include "message.pb.h"
int main() {
std::cout