-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protoc: simplify recipe #1
Changes from 2 commits
33a050a
59aa6a8
ecb4af3
75c0881
248c077
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
cmake_minimum_required(VERSION 2.8.12) | ||
project(cmake_wrapper) | ||
|
||
message(STATUS "Conan CMake Wrapper") | ||
include("conanbuildinfo.cmake") | ||
include(conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory("source_subfolder/cmake") | ||
add_subdirectory(source_subfolder/cmake) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
|
||
|
||
class ProtocConan(ConanFile): | ||
|
@@ -10,9 +11,10 @@ class ProtocConan(ConanFile): | |
homepage = "https://github.com/protocolbuffers/protobuf" | ||
license = "BSD-3-Clause" | ||
exports_sources = ["CMakeLists.txt", "patches/*"] | ||
generators = "cmake", "cmake_find_package" | ||
short_paths = True | ||
settings = "os_build", "arch_build", "compiler", "arch" | ||
generators = "cmake" | ||
settings = "os_build", "arch_build", "os", "arch", "compiler" | ||
|
||
_cmake = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
|
@@ -26,6 +28,10 @@ def _build_subfolder(self): | |
def _cmake_base_path(self): | ||
return os.path.join("lib", "cmake", "protoc") | ||
|
||
def configure(self): | ||
if self.settings.os_build != self.settings.os and self.settings.arch_build != self.settings.arch: | ||
raise ConanInvalidConfiguration("This recipe does not support cross building") | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_folder = "protobuf-" + self.version | ||
|
@@ -35,13 +41,16 @@ def requirements(self): | |
self.requires.add("protobuf/3.9.1", private=True) | ||
|
||
def _configure_cmake(self): | ||
cmake = CMake(self) | ||
cmake.definitions["protobuf_BUILD_TESTS"] = False | ||
cmake.definitions["protobuf_WITH_ZLIB"] = False | ||
if self._cmake: | ||
return self._cmake | ||
self._cmake = CMake(self) | ||
self._cmake.definitions["CMAKE_INSTALL_CMAKEDIR"] = self._cmake_base_path.replace("\\", "/") | ||
self._cmake.definitions["protobuf_BUILD_TESTS"] = False | ||
self._cmake.definitions["protobuf_WITH_ZLIB"] = False | ||
if self.settings.compiler == "Visual Studio": | ||
cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in self.settings.compiler.runtime | ||
cmake.configure(build_folder=self._build_subfolder) | ||
return cmake | ||
self._cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in self.settings.compiler.runtime | ||
self._cmake.configure(build_folder=self._build_subfolder) | ||
return self._cmake | ||
|
||
def build(self): | ||
tools.patch(**self.conan_data["patches"][self.version]) | ||
|
@@ -50,37 +59,25 @@ def build(self): | |
|
||
def package(self): | ||
self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||
# os.makedirs(os.path.join(self.package_folder, self._cmake_base_path)) | ||
cmake = self._configure_cmake() | ||
cmake.install() | ||
cmake_folder = os.path.join(self.package_folder, self._cmake_base_path) | ||
os.unlink(os.path.join(cmake_folder, "protoc-config-version.cmake")) | ||
# FIXME: To find protoc the cmake generator is required | ||
cmake_path = os.path.join(cmake_folder, "protoc-targets-noconfig.cmake") | ||
tools.replace_in_file(cmake_path, "${_IMPORT_PREFIX}/bin/", "${CONAN_BIN_DIRS_PROTOC}/") | ||
|
||
def package_id(self): | ||
del self.info.settings.compiler | ||
del self.info.settings.arch | ||
self.info.include_build_settings() | ||
|
||
def package_info(self): | ||
bindir = os.path.join(self.package_folder, "bin") | ||
self.output.info("Appending PATH environment variable: {}".format(bindir)) | ||
self.env_info.PATH.append(bindir) | ||
self.cpp_info.builddirs = [self._cmake_base_path] | ||
# INFO: Google Protoc exports a bunch of functions/macro that can be consumed by CMake | ||
# protoc-config.cmake: provides protobuf_generate function | ||
# protoc-module.cmake: provides legacy functions, PROTOBUF_GENERATE_CPP PROTOBUF_GENERATE_PYTHON | ||
# protoc-options.cmake: required by protoc-tools.cmake | ||
# protoc-targets.cmake: required by protoc-tools.cmake | ||
# protoc-targets-noconfig.cmake: declare protobuf:protoc as target | ||
|
||
self.cpp_info.build_modules = [ | ||
os.path.join(self._cmake_base_path, "protoc-config.cmake"), | ||
os.path.join(self._cmake_base_path, "protoc-module.cmake"), | ||
os.path.join(self._cmake_base_path, "protoc-options.cmake"), | ||
os.path.join(self._cmake_base_path, "protoc-targets.cmake"), | ||
os.path.join(self._cmake_base_path, "protoc-targets-noconfig.cmake") | ||
os.path.join(self._cmake_base_path, "protoc-generate.cmake"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is that protoc-generate.cmake ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds pretty interesting :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I named it generate because it contains the |
||
] | ||
self.cpp_info.builddirs = [self._cmake_base_path] | ||
|
||
protoc = "protoc.exe" if self.settings.os_build == "Windows" else "protoc" | ||
self.env_info.PROTOC_BIN = os.path.normpath(os.path.join(self.package_folder, "bin", protoc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, we need to support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new crossbuilding pr by jsgogo will fix this.
(so this recipe should be modified again to use arch and os instead of arch_build and os_build)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's wait with this pr until that pr lands?
Because that might take some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, we can push it forward, and update once that feature is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Can you review and merge it?
(and maybe rebase on top of CCI's master since this branch is quite old)