Skip to content

Commit

Permalink
Updated conanfile and requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
gouriano committed Feb 2, 2024
1 parent d762520 commit 4237d6e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
72 changes: 45 additions & 27 deletions recipes/ncbi-cxx-toolkit-public/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from conan import ConanFile, conan_version
from conan.errors import ConanInvalidConfiguration, ConanException
from conan.tools.microsoft import check_min_vs, is_msvc_static_runtime, is_msvc
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.build import check_min_cppstd, cross_building
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, replace_in_file
from conan.tools.build import check_min_cppstd, cross_building, can_run
from conan.tools.scm import Version
from conan.tools.cmake import CMakeDeps, CMakeToolchain, CMake, cmake_layout
from conan.tools.env import VirtualRunEnv, VirtualBuildEnv
import os
import yaml
import re

required_conan_version = ">=1.53.0"

Expand All @@ -25,14 +27,12 @@ class NcbiCxxToolkit(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_projects": ["ANY"],
"with_targets": ["ANY"],
"with_components": ["ANY"]
}
default_options = {
"shared": False,
"fPIC": True,
"with_projects": "",
"with_targets": "",
"with_components": ""
}
Expand Down Expand Up @@ -134,11 +134,13 @@ def requirements(self):
_alltargets = self._parse_option(self.options.with_targets)
_required_components = set()
for _t in _alltargets:
_re = re.compile(_t)
for _component in self._tk_dependencies["components"]:
_libraries = self._tk_dependencies["libraries"][_component]
if _t in _libraries:
_required_components.add(_component)
break
for _lib in _libraries:
if _re.match(_lib) != None:
_required_components.add(_component)
break

_allcomponents = self._parse_option(self.options.with_components)
_required_components.update(_allcomponents)
Expand All @@ -160,9 +162,8 @@ def requirements(self):

if len(_required_components) == 0:
_required_components.update( self._tk_dependencies["components"])
else:
for component in _required_components:
self._componenttargets.update(self._tk_dependencies["libraries"][component])
for component in _required_components:
self._componenttargets.update(self._tk_dependencies["libraries"][component])

requirements = set()
for component in _required_components:
Expand All @@ -173,7 +174,7 @@ def requirements(self):

for req in requirements:
pkgs = self._translate_req(req)
if pkgs is not None:
if pkgs != None:
for pkg in pkgs:
self.requires(pkg)

Expand All @@ -184,7 +185,7 @@ def validate(self):
raise ConanInvalidConfiguration("This operating system is not supported")
if is_msvc(self):
check_min_vs(self, 192)
if self.options.shared and is_msvc_static_runtime(self):
if self.options.shared and is_msvc_static_runtime(self) and Version(self.version) < "28":
raise ConanInvalidConfiguration("This configuration is not supported")
else:
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
Expand All @@ -195,46 +196,61 @@ def validate(self):

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)
root = os.path.join(os.getcwd(), "CMakeLists.txt")
with open(root, "w", encoding="utf-8") as f:
f.write("cmake_minimum_required(VERSION 3.15)\n")
f.write("project(ncbi-cpp)\n")
f.write("include(src/build-system/cmake/CMake.NCBItoolkit.cmake)\n")
f.write("add_subdirectory(src)\n")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["NCBI_PTBCFG_PACKAGING"] = True
if self.options.shared:
tc.variables["NCBI_PTBCFG_ALLOW_COMPOSITE"] = True
tc.variables["NCBI_PTBCFG_PROJECT_LIST"] = str(self.options.with_projects) + ";-app/netcache"
tc.variables["NCBI_PTBCFG_PROJECT_LIST"] = "-app/netcache"
if self.options.with_targets != "":
tc.variables["NCBI_PTBCFG_PROJECT_TARGETS"] = self.options.with_targets
if len(self._componenttargets) != 0:
tc.variables["NCBI_PTBCFG_PROJECT_COMPONENTTARGETS"] = ";".join(self._componenttargets)
if is_msvc(self):
tc.variables["NCBI_PTBCFG_CONFIGURATION_TYPES"] = self.settings.build_type
tc.variables["NCBI_PTBCFG_PROJECT_TAGS"] = "-demo;-sample"
tc.generate()
cmdep = CMakeDeps(self)
cmdep.generate()
CMakeDeps(self).generate()
VirtualBuildEnv(self).generate()
if can_run(self):
VirtualRunEnv(self).generate(scope="build")

def _patch_sources(self):
apply_conandata_patches(self)
if self.settings.os == "Macos":
grpc = os.path.join(self.source_folder, "src", "build-system", "cmake", "CMake.NCBIptb.grpc.cmake")
replace_in_file(self, grpc,
"COMMAND ${_cmd}",
"COMMAND ${CMAKE_COMMAND} -E env \"DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}\" ${_cmd}")
root = os.path.join(self.source_folder, "CMakeLists.txt")
with open(root, "w", encoding="utf-8") as f:
f.write("cmake_minimum_required(VERSION 3.15)\n")
f.write("project(ncbi-cpp)\n")
f.write("include(src/build-system/cmake/CMake.NCBItoolkit.cmake)\n")
f.write("add_subdirectory(src)\n")

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
# Visual Studio sometimes runs "out of heap space"
if is_msvc(self):
cmake.parallel = False
# if is_msvc(self):
# cmake.parallel = False
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

@property
def _module_file_rel_path(self):
return os.path.join("res", "build-system", "cmake", "CMake.NCBIpkg.conan.cmake")

def package_info(self):
impfile = os.path.join(self.package_folder, "res", "ncbi-cpp-toolkit.imports")
with open(impfile, "r", encoding="utf-8") as f:
allexports = set(f.read().split())
allexports = set(f.read().split()).intersection(self._componenttargets)
absent = []
for component in self._tk_dependencies["components"]:
c_libs = []
Expand All @@ -261,7 +277,7 @@ def package_info(self):
n_reqs.update(self._tk_dependencies["requirements"][lib])
for req in n_reqs:
pkgs = self._translate_req(req)
if pkgs is not None:
if pkgs != None:
for pkg in pkgs:
pkg = pkg[:pkg.find("/")]
ref = pkg + "::" + pkg
Expand Down Expand Up @@ -292,4 +308,6 @@ def package_info(self):
self.cpp_info.components["core"].system_libs = ["dl", "c", "m", "pthread", "resolv"]
self.cpp_info.components["core"].frameworks = ["ApplicationServices"]
self.cpp_info.components["core"].builddirs.append("res")
self.cpp_info.components["core"].build_modules = ["res/build-system/cmake/CMake.NCBIpkg.conan.cmake"]
build_modules = [self._module_file_rel_path]
self.cpp_info.components["core"].build_modules = build_modules
self.cpp_info.set_property("cmake_build_modules", build_modules)
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ libraries:
]
web: ["xsoap_server", "xsoap",
"ncbi_web",
"xcgi_redirect","xcgi","xhtml", "xfcgi"
"xcgi_redirect","xcgi","xhtml"
]
#----------------------------------------------------------------------------
requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 27.0
#----------------------------------------------------------------------------
requirements:
BACKWARD: ["backward-cpp/1.6"]
UNWIND: ["libunwind/1.6.2", "xz_utils/5.4.4"]
UNWIND: ["libunwind/1.6.2"]
BerkeleyDB: ["libdb/5.3.28"]
BZ2: ["bzip2/1.0.8"]
GIF: ["giflib/5.2.1"]
Expand All @@ -16,7 +16,7 @@ requirements:
PROTOBUF: []
SQLITE3: ["sqlite3/3.41.1"]
TIFF: ["libtiff/4.4.0"]
XML: ["libxml2/2.11.4"]
XML: ["libxml2/2.11.6"]
XSLT: ["libxslt/1.1.34"]
UV: ["libuv/1.44.2"]
Z: ["zlib/1.2.13"]
Expand Down

0 comments on commit 4237d6e

Please sign in to comment.