blob: bdd832c36b83f269647c702289a4222b68e79da1 [file] [log] [blame]
Uilian Riesf0769b62018-01-12 14:18:20 -02001#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""Conan recipe package for Google FlatBuffers
5"""
6import os
Uilian Ries1f03bec2018-08-16 16:17:52 -03007import shutil
Uilian Riesf0769b62018-01-12 14:18:20 -02008from conans import ConanFile, CMake, tools
9
10
11class FlatbuffersConan(ConanFile):
12 name = "flatbuffers"
Uilian Ries1f03bec2018-08-16 16:17:52 -030013 license = "Apache-2.0"
Uilian Riesf0769b62018-01-12 14:18:20 -020014 url = "https://github.com/google/flatbuffers"
Uilian Ries1f03bec2018-08-16 16:17:52 -030015 homepage = "http://google.github.io/flatbuffers/"
16 author = "Wouter van Oortmerssen"
Uilian Riesdd892282018-11-12 14:49:42 -020017 topics = ("conan", "flatbuffers", "serialization", "rpc", "json-parser")
Uilian Riesf0769b62018-01-12 14:18:20 -020018 description = "Memory Efficient Serialization Library"
Uilian Ries1f03bec2018-08-16 16:17:52 -030019 settings = "os", "compiler", "build_type", "arch"
20 options = {"shared": [True, False], "fPIC": [True, False]}
Uilian Riesdd892282018-11-12 14:49:42 -020021 default_options = {"shared": False, "fPIC": True}
Uilian Riesf0769b62018-01-12 14:18:20 -020022 generators = "cmake"
23 exports = "LICENSE.txt"
Uilian Ries1f03bec2018-08-16 16:17:52 -030024 exports_sources = ["CMake/*", "include/*", "src/*", "grpc/*", "CMakeLists.txt", "conan/CMakeLists.txt"]
Uilian Riesf0769b62018-01-12 14:18:20 -020025
Uilian Ries1f03bec2018-08-16 16:17:52 -030026 def source(self):
27 """Wrap the original CMake file to call conan_basic_setup
Uilian Riesf0769b62018-01-12 14:18:20 -020028 """
Uilian Ries1f03bec2018-08-16 16:17:52 -030029 shutil.move("CMakeLists.txt", "CMakeListsOriginal.txt")
30 shutil.move(os.path.join("conan", "CMakeLists.txt"), "CMakeLists.txt")
31
32 def config_options(self):
33 """Remove fPIC option on Windows platform
34 """
35 if self.settings.os == "Windows":
36 self.options.remove("fPIC")
37
38 def configure_cmake(self):
39 """Create CMake instance and execute configure step
40 """
41 cmake = CMake(self)
42 cmake.definitions["FLATBUFFERS_BUILD_TESTS"] = False
43 cmake.definitions["FLATBUFFERS_BUILD_SHAREDLIB"] = self.options.shared
44 cmake.definitions["FLATBUFFERS_BUILD_FLATLIB"] = not self.options.shared
45 cmake.configure()
46 return cmake
Uilian Riesf0769b62018-01-12 14:18:20 -020047
48 def build(self):
49 """Configure, build and install FlatBuffers using CMake.
50 """
Uilian Ries1f03bec2018-08-16 16:17:52 -030051 cmake = self.configure_cmake()
Uilian Riesf0769b62018-01-12 14:18:20 -020052 cmake.build()
Uilian Riesf0769b62018-01-12 14:18:20 -020053
54 def package(self):
55 """Copy Flatbuffers' artifacts to package folder
56 """
Uilian Ries1f03bec2018-08-16 16:17:52 -030057 cmake = self.configure_cmake()
58 cmake.install()
Uilian Riesf0769b62018-01-12 14:18:20 -020059 self.copy(pattern="LICENSE.txt", dst="licenses")
Uilian Riesdd892282018-11-12 14:49:42 -020060 self.copy(pattern="FindFlatBuffers.cmake", dst=os.path.join("lib", "cmake", "flatbuffers"), src="CMake")
Uilian Riesf0769b62018-01-12 14:18:20 -020061 self.copy(pattern="flathash*", dst="bin", src="bin")
Kamil Rojewski42515cf2018-08-06 21:45:35 +020062 self.copy(pattern="flatc*", dst="bin", src="bin")
Uilian Ries1f03bec2018-08-16 16:17:52 -030063 if self.settings.os == "Windows" and self.options.shared:
64 if self.settings.compiler == "Visual Studio":
65 shutil.move(os.path.join(self.package_folder, "lib", "%s.dll" % self.name),
66 os.path.join(self.package_folder, "bin", "%s.dll" % self.name))
67 elif self.settings.compiler == "gcc":
68 shutil.move(os.path.join(self.package_folder, "lib", "lib%s.dll" % self.name),
69 os.path.join(self.package_folder, "bin", "lib%s.dll" % self.name))
Uilian Riesf0769b62018-01-12 14:18:20 -020070
71 def package_info(self):
72 """Collect built libraries names and solve flatc path.
73 """
74 self.cpp_info.libs = tools.collect_libs(self)
Kamil Rojewski42515cf2018-08-06 21:45:35 +020075 self.user_info.flatc = os.path.join(self.package_folder, "bin", "flatc")