diff --git a/ports/grpc/00012-vcpkg-cross-compile.patch b/ports/grpc/00012-vcpkg-cross-compile.patch new file mode 100644 index 00000000000000..8fbe3247f927db --- /dev/null +++ b/ports/grpc/00012-vcpkg-cross-compile.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ad15a31..1529acd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -284,6 +284,16 @@ if(WIN32) + set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32 crypt32 gdi32) + endif() + ++# VCPKG cross compile support ++if(VCPKG_HOST_TRIPLET AND NOT VCPKG_HOST_TRIPLET STREQUAL VCPKG_TARGET_TRIPLET) ++ set(CMAKE_CROSSCOMPILING ON) ++ set(_gRPC_CPP_PLUGIN "${_VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}/tools/grpc/grpc_cpp_plugin") ++ if(NOT EXISTS "${_gRPC_CPP_PLUGIN}") ++ message(WARNING "${_gRPC_CPP_PLUGIN} is not installed. Cross compile might fail. Try to install grpc:${VCPKG_HOST_TRIPLET}") ++ unset(_gRPC_CPP_PLUGIN) ++ endif() ++endif() ++ + # Create directory for generated .proto files + set(_gRPC_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens) + file(MAKE_DIRECTORY ${_gRPC_PROTO_GENS_DIR}) diff --git a/ports/grpc/CONTROL b/ports/grpc/CONTROL index f44b4e00e9b181..f5954763e7c451 100644 --- a/ports/grpc/CONTROL +++ b/ports/grpc/CONTROL @@ -1,5 +1,6 @@ Source: grpc Version: 1.33.1 +Port-Version: 1 Build-Depends: zlib, openssl, protobuf, c-ares (!uwp), upb, abseil, re2 Homepage: https://github.com/grpc/grpc Description: An RPC library and framework diff --git a/ports/grpc/portfile.cmake b/ports/grpc/portfile.cmake index a082a69634941a..1ed24ba5c25e11 100644 --- a/ports/grpc/portfile.cmake +++ b/ports/grpc/portfile.cmake @@ -17,6 +17,7 @@ vcpkg_from_github( 00009-use-system-upb.patch 00010-add-feature-absl-sync.patch 00011-fix-csharp_plugin.patch + 00012-vcpkg-cross-compile.patch snprintf.patch ) diff --git a/ports/protobuf/CONTROL b/ports/protobuf/CONTROL index 115b306c55ae64..799613ec1df9f5 100644 --- a/ports/protobuf/CONTROL +++ b/ports/protobuf/CONTROL @@ -1,6 +1,6 @@ Source: protobuf Version: 3.13.0 -Port-Version: 2 +Port-Version: 3 Homepage: https://github.com/protocolbuffers/protobuf Description: Protocol Buffers - Google's data interchange format diff --git a/ports/protobuf/vcpkg-cmake-wrapper.cmake b/ports/protobuf/vcpkg-cmake-wrapper.cmake index 1a0f683d24918c..22c89d9731dea4 100644 --- a/ports/protobuf/vcpkg-cmake-wrapper.cmake +++ b/ports/protobuf/vcpkg-cmake-wrapper.cmake @@ -11,3 +11,17 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.3) cmake_policy(POP) endif() _find_package(${ARGS}) + +if(Protobuf_FOUND AND VCPKG_HOST_TRIPLET AND NOT VCPKG_HOST_TRIPLET STREQUAL VCPKG_TARGET_TRIPLET) + foreach(prop IMPORTED_LOCATION IMPORTED_LOCATION_RELEASE IMPORTED_LOCATION_DEBUG) + get_target_property(_protoc_exe_path protobuf::protoc ${prop}) + if(_protoc_exe_path) + string(REPLACE "/${VCPKG_TARGET_TRIPLET}/" "/${VCPKG_HOST_TRIPLET}/" _protoc_exe_path "${_protoc_exe_path}") + if(NOT EXISTS "${_protoc_exe_path}") + message(WARNING "${_protoc_exe_path} is not installed. Cross compile might fail. Try to install protobuf:${VCPKG_HOST_TRIPLET}") + else() + set_target_properties(protobuf::protoc PROPERTIES ${prop} "${_protoc_exe_path}") + endif() + endif() + endforeach() +endif() diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index 2a894229775ef6..1feb6731668af0 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -213,6 +213,26 @@ endif() set(VCPKG_TARGET_TRIPLET ${_VCPKG_TARGET_TRIPLET_ARCH}-${_VCPKG_TARGET_TRIPLET_PLAT} CACHE STRING "Vcpkg target triplet (ex. x86-windows)") set(_VCPKG_TOOLCHAIN_DIR ${CMAKE_CURRENT_LIST_DIR}) +if(VCPKG_HOST_TRIPLET) + set(VCPKG_HOST_TRIPLET ${VCPKG_HOST_TRIPLET} CACHE STRING "Vcpkg host triplet (ex. arm64-linux)" FORCE) +else() + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(_VCPKG_HOST_TRIPLET_PLAT linux) + endif() + + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(_VCPKG_TARGET_TRIPLET_ARCH x64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv7l") + set(_VCPKG_TARGET_TRIPLET_ARCH arm) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(_VCPKG_TARGET_TRIPLET_ARCH arm64) + endif() + + if(_VCPKG_HOST_TRIPLET_PLAT AND _VCPKG_TARGET_TRIPLET_ARCH) + set(VCPKG_HOST_TRIPLET ${_VCPKG_TARGET_TRIPLET_ARCH}-${_VCPKG_HOST_TRIPLET_PLAT} CACHE STRING "Vcpkg host triplet (ex. arm64-linux)") + endif() +endif() + if(NOT DEFINED _VCPKG_ROOT_DIR) # Detect .vcpkg-root to figure VCPKG_ROOT_DIR set(_VCPKG_ROOT_DIR_CANDIDATE ${CMAKE_CURRENT_LIST_DIR})