Skip to content

Commit

Permalink
[protobuf] Add option to build tools
Browse files Browse the repository at this point in the history
Avoid adding to env if cross building.
Add patch that fixes android build (already fixed upstream)
Add patch fixes ios build (upstream patch necessary)
  • Loading branch information
anton-danielsson committed Feb 16, 2021
1 parent beffbf8 commit 08297d7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
4 changes: 4 additions & 0 deletions recipes/protobuf/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ patches:
base_path: "source_subfolder"
- patch_file: "patches/upstream-issue-7949-build-libprotoc-separately.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-7288-android-log.patch"
base_path: "source_subfolder"
- patch_file: "patches/bundle-destination.patch"
base_path: "source_subfolder"
22 changes: 17 additions & 5 deletions recipes/protobuf/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ class ProtobufConan(ConanFile):
generators = "cmake"
short_paths = True
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "with_zlib": [True, False], "fPIC": [True, False], "lite": [True, False]}
default_options = {"with_zlib": False, "shared": False, "fPIC": True, "lite": False}
options = {
"shared": [True, False],
"with_zlib": [True, False],
"fPIC": [True, False],
"lite": [True, False],
"tools": [True, False]
}
default_options = {
"with_zlib": False,
"shared": False,
"fPIC": True,
"lite": False,
"tools": True,
}

_cmake = None

Expand Down Expand Up @@ -72,8 +84,8 @@ def _configure_cmake(self):
self._cmake.definitions["CMAKE_INSTALL_CMAKEDIR"] = self._cmake_install_base_path.replace("\\", "/")
self._cmake.definitions["protobuf_WITH_ZLIB"] = self.options.with_zlib
self._cmake.definitions["protobuf_BUILD_TESTS"] = False
self._cmake.definitions["protobuf_BUILD_PROTOC_BINARIES"] = not tools.cross_building(self.settings)
self._cmake.definitions["protobuf_BUILD_LIBPROTOC"] = True
self._cmake.definitions["protobuf_BUILD_PROTOC_BINARIES"] = True
self._cmake.definitions["protobuf_BUILD_LIBPROTOC"] = self.options.tools
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in str(self.settings.compiler.runtime)
self._cmake.configure(build_folder=self._build_subfolder)
Expand Down Expand Up @@ -198,7 +210,7 @@ def package_info(self):
self.cpp_info.components["libprotoc"].libs = [lib_prefix + "protoc" + lib_suffix]
self.cpp_info.components["libprotoc"].requires = ["libprotobuf"]

if not tools.cross_building(self.settings):
if self.options.tools and not tools.cross_building(self.settings):
self.cpp_info.components["protoc"].name = "protoc"
self.cpp_info.components["protoc"].requires.extend(["libprotoc", "libprotobuf"])

Expand Down
11 changes: 11 additions & 0 deletions recipes/protobuf/all/patches/bundle-destination.patch
Original file line number Diff line number Diff line change
@@ -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}")
25 changes: 25 additions & 0 deletions recipes/protobuf/all/patches/upstream-pr-7288-android-log.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- 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
10 changes: 5 additions & 5 deletions recipes/protobuf/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
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()

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)

find_package(protobuf CONFIG REQUIRED)

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

0 comments on commit 08297d7

Please sign in to comment.