Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ports/cartographer/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ vcpkg_cmake_configure(
OPTIONS
-DGFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION=OFF
-DGLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION=OFF
"-DProtobuf_PROTOC_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
-Dgtest_disable_pthreads=ON
-DCMAKE_USE_PTHREADS_INIT=OFF
OPTIONS_DEBUG
Expand Down
10 changes: 9 additions & 1 deletion ports/cartographer/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "cartographer",
"version": "1.0.0",
"port-version": 5,
"port-version": 6,
"description": "Google 2D & 3D SLAM package",
"homepage": "https://github.com/googlecartographer/cartographer",
"license": "Apache-2.0",
"dependencies": [
"boost-iostreams",
"cairo",
Expand All @@ -18,6 +19,13 @@
"gtest",
"lua",
"protobuf",
{
"name": "protobuf",
"host": true,
"features": [
"codegen"
]
},
{
"name": "vcpkg-cmake",
"host": true
Expand Down
1 change: 1 addition & 0 deletions ports/google-cloud-cpp/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ vcpkg_cmake_configure(
-DGOOGLE_CLOUD_CPP_ENABLE_CCACHE=OFF
-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES=OFF
-DBUILD_TESTING=OFF
"-D_protobuf_PROTOC_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
)

vcpkg_cmake_install()
Expand Down
7 changes: 5 additions & 2 deletions ports/google-cloud-cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "google-cloud-cpp",
"version": "2.1.0",
"port-version": 2,
"port-version": 3,
"description": "C++ Client Libraries for Google Cloud Platform APIs.",
"homepage": "https://github.com/googleapis/google-cloud-cpp",
"license": "Apache-2.0",
Expand Down Expand Up @@ -448,7 +448,10 @@
"protobuf",
{
"name": "protobuf",
"host": true
"host": true,
"features": [
"codegen"
]
}
]
},
Expand Down
10 changes: 0 additions & 10 deletions ports/grpc/gRPCTargets-vcpkg-tools.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions ports/grpc/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ if (gRPC_BUILD_CODEGEN)
grpc_cpp_plugin
grpc_ruby_plugin
)
else()
configure_file("${CMAKE_CURRENT_LIST_DIR}/gRPCTargets-vcpkg-tools.cmake" "${CURRENT_PACKAGES_DIR}/share/grpc/gRPCTargets-vcpkg-tools.cmake" @ONLY)
endif()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share" "${CURRENT_PACKAGES_DIR}/debug/include")
Expand Down
7 changes: 5 additions & 2 deletions ports/grpc/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grpc",
"version-semver": "1.48.0",
"port-version": 1,
"port-version": 2,
"description": "An RPC library and framework",
"homepage": "https://github.com/grpc/grpc",
"license": "Apache-2.0",
Expand All @@ -22,7 +22,10 @@
"protobuf",
{
"name": "protobuf",
"host": true
"host": true,
"features": [
"codegen"
]
},
"re2",
"upb",
Expand Down
39 changes: 39 additions & 0 deletions ports/offscale-libetcd-cpp/fix-crosscompile-protobuf-grpc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62ae7c4..45a4175 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,8 +4,9 @@ project(libetcd-cpp VERSION 0.0.1)

set(CMAKE_CXX_STANDARD 17)

-find_package(gRPC REQUIRED)
-find_package(protobuf REQUIRED)
+find_package(gRPC CONFIG REQUIRED)
+find_package(Protobuf CONFIG REQUIRED)
+find_program(gRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED)

file(GLOB_RECURSE protos LIST_DIRECTORIES false "proto/*.proto")
file(GLOB main_proto LIST_DIRECTORIES false "proto/rpc.proto")
@@ -28,17 +29,17 @@ endforeach()

add_custom_command(
OUTPUT ${rpc_protofiles}
- COMMAND protobuf::protoc
- ARGS --grpc_out=${generated_path} -I ${protodir_path} --plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin> ${main_proto}
- DEPENDS gRPC::grpc_cpp_plugin protobuf::protoc ${main_proto}
+ COMMAND "${Protobuf_PROTOC_EXECUTABLE}"
+ ARGS --grpc_out=${generated_path} -I ${protodir_path} "--plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN}" ${main_proto}
+ DEPENDS ${main_proto}
COMMENT "Running grpc protocol buffer compiler on ${main_proto}"
VERBATIM )

add_custom_command(
OUTPUT ${common_protofiles}
- COMMAND protobuf::protoc
+ COMMAND "${Protobuf_PROTOC_EXECUTABLE}"
ARGS --cpp_out=${generated_path} -I ${protodir_path} ${protos}
- DEPENDS ${protos} protobuf::protoc
+ DEPENDS ${protos}
COMMENT "Running cpp protocol buffer compiler on ${protos}"
VERBATIM )
Comment on lines +30 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not simply fix the target protobuf::protoc for crosscompiling instead of patching everyone downstream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'm unsure of the best solution, and I'm still trying to wrap my head around CMake cross compilation best practices and what vcpkg is doing.

I was under the impression that it's probably best to expect that any exported targets from a find_package call are all the same architecture, OS, etc... However, as I keep investigating all of this, I wonder how useful an exported executable target is if it needs to be replaced or goes unused during cross compilation. It seems like a cross-compilation-compatible solution would either:

  1. Rely on find_program to find all host executables that will be run during the build
  2. Separate config files for library and executable targets where the user would need to either specify an exact *_DIR path to the host config file or (after much testing) rely on find_package with NO_CMAKE_PATH, NO_CMAKE_FIND_ROOT_PATH, and HINTS ${CMAKE_SYSTEM_PREFIX_PATH} options to search only the host directories,1 i.e.,
    find_package(Protobuf CONFIG HINTS ${CMAKE_SYSTEM_PREFIX_PATH} NO_CMAKE_PATH NO_CMAKE_FIND_ROOT_PATH)

fix the target protobuf::protoc

I believe what you're describing is attempted with these lines

find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc PATHS "${CMAKE_CURRENT_LIST_DIR}/../../tools/protobuf" NO_DEFAULT_PATH)

# Import target "protobuf::protoc" for configuration "Release"
set_property(TARGET protobuf::protoc APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(protobuf::protoc PROPERTIES
IMPORTED_LOCATION_RELEASE "${Protobuf_PROTOC_EXECUTABLE}"
)

I've removed these files in my PR, but I should investigate this again as you suggest. However, these files, being only in vcpkg, would hide downstream projects' issues if they tried to cross compile outside of vcpkg without also fixing the target. What I mean is that I think there is room for a patch in upstream protobuf for better cross compilation support, and I'm wondering what a good solution is and want to test it here.

list(INSERT CMAKE_SYSTEM_PREFIX_PATH 0 "${VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}") # CMake 3.15 is required for list(PREPEND ...).

Footnotes

  1. Vcpkg currently doesn't touch CMAKE_SYSTEM_PREFIX_PATH, so we'd want to add the path to the host triplet installation root. I've done very light testing locally by adding the following to scripts/buildsystem/vcpkg.cmake:


4 changes: 4 additions & 0 deletions ports/offscale-libetcd-cpp/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ vcpkg_from_github(
PATCHES
fix-dependency-grpc.patch
install-debug.patch
fix-crosscompile-protobuf-grpc.patch
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
DISABLE_PARALLEL_CONFIGURE # see https://github.com/microsoft/vcpkg/pull/21168#issuecomment-961588989 why
OPTIONS
"-DProtobuf_PROTOC_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
"-DgRPC_CPP_PLUGIN=${CURRENT_HOST_INSTALLED_DIR}/tools/grpc/grpc_cpp_plugin${VCPKG_HOST_EXECUTABLE_SUFFIX}"
)
vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME etcdcpp)
Expand Down
24 changes: 22 additions & 2 deletions ports/offscale-libetcd-cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
{
"name": "offscale-libetcd-cpp",
"version-date": "2019-07-10",
"port-version": 3,
"port-version": 4,
"description": "A C++ client library for etcd. etcd is a distributed, reliable key-value store.",
"homepage": "https://github.com/offscale/libetcd-cpp",
"license": "Apache-2.0 OR MIT",
"dependencies": [
"grpc",
"protobuf",
{
"name": "grpc",
"host": true,
"features": [
"codegen"
]
},
{
"name": "protobuf",
"features": [
"codegen"
]
},
{
"name": "protobuf",
"host": true,
"features": [
"codegen"
]
},
{
"name": "vcpkg-cmake",
"host": true
Expand Down
2 changes: 1 addition & 1 deletion ports/onnx/fix-dependency-protobuf.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ index 1295eab..0fb9f17 100644
include(googletest)
endif()

+find_package(protobuf CONFIG REQUIRED)
+find_package(Protobuf CONFIG REQUIRED)
if((ONNX_USE_LITE_PROTO AND TARGET protobuf::libprotobuf-lite) OR ((NOT ONNX_USE_LITE_PROTO) AND TARGET protobuf::libprotobuf))
# Sometimes we need to use protoc compiled for host architecture while linking
# libprotobuf against target architecture. See https://github.com/caffe2/caffe
4 changes: 3 additions & 1 deletion ports/onnx/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
-DPython3_EXECUTABLE=${PYTHON3}
"-DPython3_EXECUTABLE=${PYTHON3}"
-DONNX_ML=ON
-DONNX_GEN_PB_TYPE_STUBS=ON
-DONNX_USE_PROTOBUF_SHARED_LIBS=${USE_PROTOBUF_SHARED}
-DONNX_USE_LITE_PROTO=OFF
-DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME}
-DONNX_BUILD_TESTS=OFF
-DONNX_BUILD_BENCHMARKS=OFF
"-DONNX_CUSTOM_PROTOC_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
"-DProtobuf_PROTOC_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
MAYBE_UNUSED_VARIABLES
ONNX_USE_MSVC_STATIC_RUNTIME
)
Expand Down
7 changes: 5 additions & 2 deletions ports/onnx/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "onnx",
"version-semver": "1.10.2",
"port-version": 1,
"port-version": 2,
"description": "Open standard for machine learning interoperability",
"homepage": "https://onnx.ai",
"license": "Apache-2.0",
Expand All @@ -10,7 +10,10 @@
"protobuf",
{
"name": "protobuf",
"host": true
"host": true,
"features": [
"codegen"
]
},
{
"name": "python3",
Expand Down
1 change: 1 addition & 0 deletions ports/opencv4/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ vcpkg_cmake_configure(
###### PROTOBUF
-DPROTOBUF_UPDATE_FILES=${BUILD_opencv_dnn}
-DUPDATE_PROTO_FILES=${BUILD_opencv_dnn}
"-DProtobuf_PROTOC_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
###### PYLINT/FLAKE8
-DENABLE_PYLINT=OFF
-DENABLE_FLAKE8=OFF
Expand Down
11 changes: 9 additions & 2 deletions ports/opencv4/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opencv4",
"version": "4.6.0",
"port-version": 4,
"port-version": 5,
"description": "computer vision library",
"homepage": "https://github.com/opencv/opencv",
"license": "Apache-2.0",
Expand Down Expand Up @@ -103,7 +103,14 @@
"dnn": {
"description": "Enable dnn module",
"dependencies": [
"protobuf"
"protobuf",
{
"name": "protobuf",
"host": true,
"features": [
"codegen"
]
}
]
},
"eigen": {
Expand Down
29 changes: 29 additions & 0 deletions ports/protobuf/fix-crosscompile-protoc-generate-cmake-config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in
index 61669118c..5e32d4ecb 100644
--- a/cmake/protobuf-config.cmake.in
+++ b/cmake/protobuf-config.cmake.in
@@ -7,6 +7,12 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
# Imported targets
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")

+set(_protobuf_generate_compiler protobuf::protoc)
+if(CMAKE_CROSSCOMPILING)
+ find_program(Protobuf_PROTOC_EXECUTABLE protoc DOC "Host protobuf compiler path")
+ set(_protobuf_generate_compiler "${Protobuf_PROTOC_EXECUTABLE}")
+endif()
+
function(protobuf_generate)
include(CMakeParseArguments)

@@ -146,9 +152,9 @@ function(protobuf_generate)

add_custom_command(
OUTPUT ${_generated_srcs}
- COMMAND protobuf::protoc
+ COMMAND "${_protobuf_generate_compiler}"
ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
- DEPENDS ${_abs_file} protobuf::protoc
+ DEPENDS ${_abs_file} "${_protobuf_generate_compiler}"
COMMENT ${_comment}
VERBATIM )
endforeach()
49 changes: 19 additions & 30 deletions ports/protobuf/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ vcpkg_from_github(
fix-static-build.patch
fix-default-proto-file-path.patch
compile_options.patch
fix-crosscompile-protoc-generate-cmake-config.patch
)

string(COMPARE EQUAL "${TARGET_TRIPLET}" "${HOST_TRIPLET}" protobuf_BUILD_PROTOC_BINARIES)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" protobuf_BUILD_SHARED_LIBS)
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" protobuf_MSVC_STATIC_RUNTIME)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
zlib protobuf_WITH_ZLIB
codegen protobuf_BUILD_PROTOC_BINARIES
zlib protobuf_WITH_ZLIB
)

if(VCPKG_TARGET_IS_UWP)
set(protobuf_BUILD_LIBPROTOC OFF)
else()
set(protobuf_BUILD_LIBPROTOC ON)
endif()
set(protobuf_BUILD_LIBPROTOC ${protobuf_BUILD_PROTOC_BINARIES})

if (VCPKG_DOWNLOAD_MODE)
# download PKGCONFIG in download mode which is used in `vcpkg_fixup_pkgconfig()` at the end of this script.
Expand All @@ -40,7 +37,6 @@ vcpkg_cmake_configure(
-Dprotobuf_MSVC_STATIC_RUNTIME=${protobuf_MSVC_STATIC_RUNTIME}
-Dprotobuf_BUILD_TESTS=OFF
-DCMAKE_INSTALL_CMAKEDIR:STRING=share/protobuf
-Dprotobuf_BUILD_PROTOC_BINARIES=${protobuf_BUILD_PROTOC_BINARIES}
-Dprotobuf_BUILD_LIBPROTOC=${protobuf_BUILD_LIBPROTOC}
${FEATURE_OPTIONS}
)
Expand All @@ -60,32 +56,30 @@ endfunction()

protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/debug/include")

if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-release.cmake"
"\${_IMPORT_PREFIX}/bin/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
"\${_IMPORT_PREFIX}/tools/protobuf/protoc${VCPKG_HOST_EXECUTABLE_SUFFIX}"
)
endif()

if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
file(READ "${CURRENT_PACKAGES_DIR}/debug/share/protobuf/protobuf-targets-debug.cmake" DEBUG_MODULE)
string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" DEBUG_MODULE "${DEBUG_MODULE}")
string(REPLACE "\${_IMPORT_PREFIX}/debug/bin/protoc${EXECUTABLE_SUFFIX}" "\${_IMPORT_PREFIX}/tools/protobuf/protoc${EXECUTABLE_SUFFIX}" DEBUG_MODULE "${DEBUG_MODULE}")
file(WRITE "${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-debug.cmake" "${DEBUG_MODULE}")
endif()
if(protobuf_BUILD_PROTOC_BINARIES)
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-release.cmake"
"\${_IMPORT_PREFIX}/bin/protoc${EXECUTABLE_SUFFIX}"
"\${_IMPORT_PREFIX}/tools/protobuf/protoc${EXECUTABLE_SUFFIX}"
)
endif()

protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/debug/share")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
file(READ "${CURRENT_PACKAGES_DIR}/debug/share/protobuf/protobuf-targets-debug.cmake" DEBUG_MODULE)
string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" DEBUG_MODULE "${DEBUG_MODULE}")
string(REPLACE "\${_IMPORT_PREFIX}/debug/bin/protoc${EXECUTABLE_SUFFIX}" "\${_IMPORT_PREFIX}/tools/protobuf/protoc${EXECUTABLE_SUFFIX}" DEBUG_MODULE "${DEBUG_MODULE}")
file(WRITE "${CURRENT_PACKAGES_DIR}/share/protobuf/protobuf-targets-debug.cmake" "${DEBUG_MODULE}")
endif()

if(protobuf_BUILD_PROTOC_BINARIES)
if(VCPKG_TARGET_IS_WINDOWS)
vcpkg_copy_tools(TOOL_NAMES protoc AUTO_CLEAN)
else()
vcpkg_copy_tools(TOOL_NAMES protoc protoc-${version}.0 AUTO_CLEAN)
endif()
else()
file(COPY "${CURRENT_HOST_INSTALLED_DIR}/tools/${PORT}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools")
endif()

protobuf_try_remove_recurse_wait("${CURRENT_PACKAGES_DIR}/debug/share")

vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-config.cmake"
"if(protobuf_MODULE_COMPATIBLE)"
"if(ON)"
Expand Down Expand Up @@ -120,9 +114,4 @@ endforeach()

vcpkg_fixup_pkgconfig()

if(NOT protobuf_BUILD_PROTOC_BINARIES)
configure_file("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets-vcpkg-protoc.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/protobuf-targets-vcpkg-protoc.cmake" COPYONLY)
endif()

configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY)
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
Loading