[vlc-devel] [PATCH 3/4] contrib: protoc: build the protoc exe to run locally
Steve Lhomme
robux4 at ycbcr.xyz
Thu Feb 14 16:53:34 CET 2019
It's installed in the same place as luac and detected the same way in the VLC
configure script.
If C_FOR_BUILD/CXX_FOR_BUILD are not set, CMake will use the CC/CXX variables
and thus pick the cross compilers which will not provide executables that can
run on the host (aka build).
---
configure.ac | 8 ++-
.../src/protobuf/protobuf-native-tools.patch | 56 +++++++++++++++++++
contrib/src/protobuf/rules.mak | 36 ++++++------
3 files changed, 81 insertions(+), 19 deletions(-)
create mode 100644 contrib/src/protobuf/protobuf-native-tools.patch
diff --git a/configure.ac b/configure.ac
index 1f4ac52374..fba48e120b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -478,6 +478,12 @@ AS_IF([test -n "${CONTRIB_DIR}"], [
])
])
+ AS_IF([test -z "$PROTOC"], [
+ AS_IF([test -x "${CONTRIB_DIR}/../bin/${host_alias}-protoc${BUILDEXEEXT}"], [
+ PROTOC="${CONTRIB_DIR}/../bin/${host_alias}-protoc${BUILDEXEEXT}"
+ ])
+ ])
+
AS_IF([test "${SYS}" = "darwin"], [
export LD_LIBRARY_PATH="${CONTRIB_DIR}/lib:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="${CONTRIB_DIR}/lib:$DYLD_LIBRARY_PATH"
@@ -3790,7 +3796,7 @@ dnl Chromecast streaming support
dnl
m4_pushdef([protobuf_lite_version], 2.5.0)
AC_ARG_VAR(PROTOC, [protobuf compiler])
-AC_CHECK_PROGS(PROTOC, protoc, no)
+AC_CHECK_TOOL(PROTOC, protoc, no)
PKG_WITH_MODULES([CHROMECAST],[protobuf-lite >= protobuf_lite_version], [
AS_IF([test "x${PROTOC}" != "xno"], [
build_chromecast="yes"
diff --git a/contrib/src/protobuf/protobuf-native-tools.patch b/contrib/src/protobuf/protobuf-native-tools.patch
new file mode 100644
index 0000000000..3084b0f6ca
--- /dev/null
+++ b/contrib/src/protobuf/protobuf-native-tools.patch
@@ -0,0 +1,56 @@
+--- protobuf/cmake/install.cmake.native 2019-02-14 14:56:20.144144900 +0100
++++ protobuf/cmake/install.cmake 2019-02-14 14:56:39.741249800 +0100
+@@ -1,5 +1,6 @@
+ include(GNUInstallDirs)
+
++if (NOT protobuf_BUILD_ONLY_TOOLS)
+ foreach(_library
+ libprotobuf-lite
+ libprotobuf
+@@ -13,10 +14,12 @@ foreach(_library
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
+ endforeach()
++endif ()
+
+ install(TARGETS protoc EXPORT protobuf-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
+
++if (NOT protobuf_BUILD_ONLY_TOOLS)
+ file(STRINGS extract_includes.bat.in _extract_strings
+ REGEX "^copy")
+ foreach(_extract_string ${_extract_strings})
+@@ -80,6 +83,7 @@ foreach(_file ${nobase_dist_proto_DATA})
+ "but there not exists. The file will not be installed.")
+ endif()
+ endforeach()
++endif ()
+
+ # Install configuration
+ set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
+@@ -99,6 +103,7 @@ configure_file(protobuf-module.cmake.in
+ configure_file(protobuf-options.cmake
+ ${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
+
++if (NOT protobuf_BUILD_ONLY_TOOLS)
+ # pkg-config files
+ if(NOT MSVC)
+ set(prefix ${CMAKE_INSTALL_PREFIX})
+@@ -133,6 +138,7 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY
+ COMPONENT protobuf-export
+ PATTERN protobuf-targets.cmake EXCLUDE
+ )
++endif ()
+
+ option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF)
+ if(protobuf_INSTALL_EXAMPLES)
+--- protobuf/cmake/protobuf-options.cmake.native 2016-09-24 03:16:28.000000000 +0200
++++ protobuf/cmake/protobuf-options.cmake 2019-02-14 13:52:23.741066000 +0100
+@@ -5,3 +5,7 @@ mark_as_advanced(protobuf_VERBOSE)
+ # FindProtobuf module compatibel
+ option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF)
+ mark_as_advanced(protobuf_MODULE_COMPATIBLE)
++
++# Build only tools (when cross compiling)
++option(protobuf_BUILD_ONLY_TOOLS "Only build protoc (useful when cross compiling)" OFF)
++mark_as_advanced(protobuf_BUILD_ONLY_TOOLS)
diff --git a/contrib/src/protobuf/rules.mak b/contrib/src/protobuf/rules.mak
index 18a04dcf4b..bb691f40d0 100644
--- a/contrib/src/protobuf/rules.mak
+++ b/contrib/src/protobuf/rules.mak
@@ -2,24 +2,9 @@
PROTOBUF_VERSION := 3.1.0
PROTOBUF_URL := https://github.com/google/protobuf/releases/download/v$(PROTOBUF_VERSION)/protobuf-cpp-$(PROTOBUF_VERSION).tar.gz
-PKGS += protobuf
+PKGS += protobuf protoc
ifeq ($(call need_pkg, "protobuf-lite >= 3.1.0 protobuf-lite < 3.2.0"),)
-PKGS_FOUND += protobuf
-else
-ifeq ($(findstring protobuf,$(PKGS_DISABLE)),)
-# check we have a matching protoc to use
-PROTOC = $(shell PATH="$(PATH)" which protoc)
-ifeq ($(PROTOC),)
-PROTOC = $(error protoc not found in PATH $(PATH) - $(SYS_PROTOC) - $(PROTOC))
-else
-# make sure the installed protoc is compatible with the version we want to build
-SYS_PROTOC_VER = $(shell $(PROTOC) --version)
-SYS_PROTOC = $(word $(words $(SYS_PROTOC_VER)) , $(SYS_PROTOC_VER))
-ifneq ($(PROTOBUF_VERSION),$(SYS_PROTOC))
-PROTOC = $(error $(PROTOC) version $(SYS_PROTOC) doesn't match the protobuf $(PROTOBUF_VERSION) we're building)
-endif
-endif
-endif
+PKGS_FOUND += protobuf protoc
endif
$(TARBALLS)/protobuf-$(PROTOBUF_VERSION)-cpp.tar.gz:
@@ -37,12 +22,27 @@ PROTOBUF_CONF = -DBUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BU
protobuf: protobuf-$(PROTOBUF_VERSION)-cpp.tar.gz .sum-protobuf
$(UNPACK)
mv protobuf-$(PROTOBUF_VERSION) protobuf-$(PROTOBUF_VERSION)-cpp
- $(APPLY) $(SRC)/protobuf/dont-build-protoc.patch
$(APPLY) $(SRC)/protobuf/protobuf-win32.patch
$(APPLY) $(SRC)/protobuf/protobuf-cmake-pkgconfig.patch
+ $(APPLY) $(SRC)/protobuf/protobuf-native-tools.patch
$(MOVE)
.protobuf: protobuf toolchain.cmake
+ # target libraries
+ifdef HAVE_CROSS_COMPILE
+ -$(RM) $</cmake/CMakeCache.txt
+endif
cd $</cmake && $(HOSTVARS_PIC) $(CMAKE) $(PROTOBUF_CONF)
cd $</ && $(MAKE) -C cmake && $(MAKE) -C cmake install
touch $@
+
+.protoc: protobuf .protobuf
+ifdef HAVE_CROSS_COMPILE
+ # native tools
+ -$(RM) $</cmake/CMakeCache.txt
+ cd $</cmake && $(CMAKE) $(PROTOBUF_CONF) \
+ -DCMAKE_TOOLCHAIN_FILE= -DCMAKE_INSTALL_PREFIX=$(BUILDBINDIR) -Dprotobuf_BUILD_ONLY_TOOLS=ON \
+ -DCMAKE_C_COMPILER=$(CC_FOR_BUILD) -DCMAKE_CXX_COMPILER=$(CXX_FOR_BUILD)
+ cd $</ && $(MAKE) -C cmake && $(MAKE) -C cmake install
+endif
+ touch $@
--
2.17.1
More information about the vlc-devel
mailing list