conanfile.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import os
  2. from conan import ConanFile
  3. from conan.errors import ConanInvalidConfiguration
  4. from conan.tools.build import check_min_cppstd
  5. from conan.tools.scm import Version
  6. from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, rmdir, copy
  7. from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout
  8. required_conan_version = ">=1.52.0"
  9. class RotorConan(ConanFile):
  10. name = "rotor"
  11. license = "MIT"
  12. homepage = "https://github.com/basiliscos/cpp-rotor"
  13. url = "https://github.com/conan-io/conan-center-index"
  14. description = (
  15. "Event loop friendly C++ actor micro-framework, supervisable"
  16. )
  17. topics = ("concurrency", "actor-framework", "actors", "actor-model", "erlang", "supervising", "supervisor")
  18. exports_sources = "CMakeLists.txt", "src/*", "include/*", "test_package/*", "cmake/*", "tests/*", "examples/*"
  19. test_requires = "catch2/3.4.0"
  20. settings = "os", "arch", "compiler", "build_type"
  21. options = {
  22. "fPIC": [True, False],
  23. "shared": [True, False],
  24. "enable_asio": [True, False],
  25. "enable_ev" : [True, False],
  26. "enable_thread": [True, False],
  27. "multithreading": [True, False], # enables multithreading support
  28. }
  29. default_options = {
  30. "fPIC": True,
  31. "shared": False,
  32. "enable_asio": True,
  33. "enable_ev" : False,
  34. "enable_thread": True,
  35. "multithreading": True,
  36. }
  37. def config_options(self):
  38. if self.settings.os == "Windows":
  39. del self.options.fPIC
  40. def configure(self):
  41. if self.options.shared:
  42. try:
  43. del self.options.fPIC
  44. except Exception:
  45. pass
  46. def requirements(self):
  47. self.requires("boost/1.83.0", transitive_headers=True)
  48. if self.options.enable_ev:
  49. self.requires("libev/4.33")
  50. def layout(self):
  51. cmake_layout(self)
  52. def generate(self):
  53. tc = CMakeToolchain(self)
  54. tc.variables["BUILD_BOOST_ASIO"] = self.options.enable_asio
  55. tc.variables["BUILD_THREAD"] = self.options.enable_thread
  56. tc.variables["BUILD_EV"] = self.options.enable_ev
  57. tc.variables["BUILD_EXAMPLES"] = os.environ.get('ROTOR_BUILD_EXAMPLES', 'OFF')
  58. tc.variables["BUILD_THREAD_UNSAFE"] = not self.options.multithreading
  59. tc.variables["BUILD_TESTING"] = not self.conf.get("tools.build:skip_test", default=True, check_type=bool)
  60. tc.generate()
  61. tc = CMakeDeps(self)
  62. tc.generate()
  63. def validate(self):
  64. minimal_cpp_standard = "17"
  65. # if self.settings.compiler.get_safe("cppstd"):
  66. # check_min_cppstd(self, minimal_cpp_standard)
  67. minimal_version = {
  68. "gcc": "7",
  69. "clang": "6",
  70. "apple-clang": "10",
  71. "Visual Studio": "15"
  72. }
  73. compiler = str(self.settings.compiler)
  74. if compiler not in minimal_version:
  75. print(
  76. f"{self.ref} recipe lacks information about the {compiler} compiler standard version support")
  77. print(
  78. f"{self.ref} requires a compiler that supports at least C++{minimal_cpp_standard}")
  79. return
  80. compiler_version = Version(self.settings.compiler.version)
  81. if compiler_version < minimal_version[compiler]:
  82. raise ConanInvalidConfiguration(f"{self.ref} requires a compiler that supports at least C++{minimal_cpp_standard}")
  83. if self.options.shared and Version(self.version) < "0.23":
  84. raise ConanInvalidConfiguration("shared option is available from v0.23")
  85. def build(self):
  86. cmake = CMake(self)
  87. cmake.configure()
  88. cmake.build()
  89. if not self.conf.get("tools.build:skip_test", default=True):
  90. cmake.test()
  91. def package(self):
  92. copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
  93. cmake = CMake(self)
  94. cmake.install()
  95. rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
  96. def package_info(self):
  97. self.cpp_info.components["core"].libs = ["rotor"]
  98. self.cpp_info.components["core"].requires = ["boost::date_time", "boost::system", "boost::regex"]
  99. if not self.options.multithreading:
  100. self.cpp_info.components["core"].defines.append("BUILD_THREAD_UNSAFE")
  101. if self.options.enable_asio:
  102. self.cpp_info.components["asio"].libs = ["rotor_asio"]
  103. self.cpp_info.components["asio"].requires = ["core"]
  104. if self.options.enable_thread:
  105. self.cpp_info.components["thread"].libs = ["rotor_thread"]
  106. self.cpp_info.components["thread"].requires = ["core"]
  107. if self.options.enable_ev:
  108. self.cpp_info.components["ev"].libs = ["rotor_ev"]
  109. self.cpp_info.components["ev"].requires = ["core", "libev::libev"]