Skip to content

Commit

Permalink
[protobuf] Enable Android/iOS cross building
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-danielsson committed Mar 9, 2021
1 parent 60a672d commit 6a14a09
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
8 changes: 8 additions & 0 deletions recipes/protobuf/all/conandata.yml
Expand Up @@ -17,6 +17,14 @@ patches:
base_path: "source_subfolder"
- patch_file: "patches/upstream-issue-7567-no-export-template-define.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-7288-android-log.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-8301-bundle-destination.patch"
base_path: "source_subfolder"
3.13.0:
- patch_file: "patches/upstream-pr-7761-cmake-regex-fix.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-7288-android-log.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-8301-bundle-destination.patch"
base_path: "source_subfolder"
6 changes: 5 additions & 1 deletion recipes/protobuf/all/conanfile.py
Expand Up @@ -86,7 +86,7 @@ def _patch_sources(self):
find_protoc = """
# Find the protobuf compiler within the paths added by Conan, for use below.
find_program(PROTOC_PROGRAM protoc)
find_program(PROTOC_PROGRAM protoc PATHS ENV PATH NO_DEFAULT_PATH)
if(NOT PROTOC_PROGRAM)
set(PROTOC_PROGRAM "protoc")
endif()
Expand Down Expand Up @@ -177,6 +177,8 @@ def package_info(self):
self.cpp_info.components["libprotobuf"].system_libs.append("pthread")
if self._is_clang_x86 or "arm" in str(self.settings.arch):
self.cpp_info.components["libprotobuf"].system_libs.append("atomic")
if self.settings.os == "Android":
self.cpp_info.components["libprotobuf"].system_libs.append("log")
if self.settings.os == "Windows":
if self.options.shared:
self.cpp_info.components["libprotobuf"].defines = ["PROTOBUF_USE_DLLS"]
Expand Down Expand Up @@ -215,6 +217,8 @@ def package_info(self):
if self.settings.os == "Windows":
if self.options.shared:
self.cpp_info.components["libprotobuf-lite"].defines = ["PROTOBUF_USE_DLLS"]
if self.settings.os == "Android":
self.cpp_info.components["libprotobuf-lite"].system_libs.append("log")

self.cpp_info.components["libprotobuf-lite"].builddirs = [self._cmake_install_base_path]
self.cpp_info.components["libprotobuf-lite"].build_modules.extend([
Expand Down
26 changes: 26 additions & 0 deletions recipes/protobuf/all/patches/upstream-pr-7288-android-log.patch
@@ -0,0 +1,26 @@
https://github.com/protocolbuffers/protobuf/pull/7288
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -121,6 +121,9 @@ endif()
if(protobuf_LINK_LIBATOMIC)
target_link_libraries(libprotobuf atomic)
endif()
+if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
+ target_link_libraries(libprotobuf log)
+endif()
target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf

--- a/cmake/libprotobuf-lite.cmake
+++ b/cmake/libprotobuf-lite.cmake
@@ -67,6 +67,9 @@ target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
if(protobuf_LINK_LIBATOMIC)
target_link_libraries(libprotobuf-lite atomic)
endif()
+if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
+ target_link_libraries(libprotobuf-lite log)
+endif()
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf-lite
@@ -0,0 +1,11 @@
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -30,7 +30,7 @@ endforeach()

if (protobuf_BUILD_PROTOC_BINARIES)
install(TARGETS protoc EXPORT protobuf-targets
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
if (UNIX AND NOT APPLE)
set_property(TARGET protoc
PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
5 changes: 0 additions & 5 deletions recipes/protobuf/all/test_package/CMakeLists.txt
Expand Up @@ -6,11 +6,6 @@ conan_basic_setup(TARGETS)

find_package(protobuf CONFIG REQUIRED)

find_program(PROTOC_PROGRAM protoc)
if (NOT PROTOC_PROGRAM)
message(WARNING "Protoc was not found")
endif()

add_executable(${PROJECT_NAME} test_package.cpp addressbook.proto)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_BINARY_DIR}")
Expand Down
13 changes: 8 additions & 5 deletions recipes/protobuf/all/test_package/conanfile.py
Expand Up @@ -6,12 +6,15 @@ class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build_requirements(self):
if tools.cross_building(self.settings):
self.build_requires(str(self.requires['protobuf']))

def build(self):
if not tools.cross_building(self.settings, skip_x64_x86=True):
cmake = CMake(self)
cmake.definitions["protobuf_LITE"] = self.options["protobuf"].lite
cmake.configure()
cmake.build()
cmake = CMake(self)
cmake.definitions["protobuf_LITE"] = self.options["protobuf"].lite
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
Expand Down

0 comments on commit 6a14a09

Please sign in to comment.