-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conanfile.py
99 lines (81 loc) · 3.48 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import cross_building
from conan.tools.files import get, rmdir, copy, rm, export_conandata_patches, apply_conandata_patches
from conan.tools.gnu import AutotoolsToolchain, Autotools
required_conan_version = ">=1.53.0"
class FlexConan(ConanFile):
name = "flex"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/westes/flex"
description = "Flex, the fast lexical analyzer generator"
topics = ("lex", "lexer", "lexical analyzer generator")
license = "BSD-2-Clause"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def export_sources(self):
export_conandata_patches(self)
def requirements(self):
# Flex requires M4 to be compiled. If consumer does not have M4
# installed, Conan will need to know that Flex requires it.
self.requires("m4/1.4.19")
def build_requirements(self):
self.tool_requires("m4/1.4.19")
if hasattr(self, "settings_build") and cross_building(self):
self.tool_requires(f"{self.name}/{self.version}")
def validate(self):
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("Flex package is not compatible with Windows. "
"Consider using winflexbison instead.")
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
def generate(self):
at = AutotoolsToolchain(self)
at.configure_args.extend([
"--disable-nls",
"--disable-bootstrap",
"HELP2MAN=/bin/true",
"M4=m4",
# https://github.com/westes/flex/issues/247
"ac_cv_func_malloc_0_nonnull=yes", "ac_cv_func_realloc_0_nonnull=yes",
# https://github.com/easybuilders/easybuild-easyconfigs/pull/5792
"ac_cv_func_reallocarray=no",
])
at.generate()
def build(self):
apply_conandata_patches(self)
autotools = Autotools(self)
autotools.configure()
autotools.make()
def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)
def package_info(self):
self.cpp_info.libs = ["fl"]
self.cpp_info.system_libs = ["m"]
# Avoid CMakeDeps messing with Conan targets
self.cpp_info.set_property("cmake_find_mode", "none")
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
lex_path = os.path.join(bindir, "flex").replace("\\", "/")
self.output.info("Setting LEX environment variable: {}".format(lex_path))
self.env_info.LEX = lex_path