-
Notifications
You must be signed in to change notification settings - Fork 4
/
conanfile.py
129 lines (111 loc) · 4.24 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# (C) Copyright IBM 2024.
#
# This code is part of Qiskit.
#
# This code is licensed under the Apache License, Version 2.0 with LLVM
# Exceptions. You may obtain a copy of this license in the LICENSE.txt
# file in the root directory of this source tree.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
import os
import platform
import subprocess
from conans import ConanFile
from conans.tools import save
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from setuptools_scm import get_version as get_version_scm
def get_version():
try:
return get_version_scm()
except: # noqa: E722
return None
class QasmConan(ConanFile):
name = "qe-qasm"
version = get_version()
url = "https://github.com/openqasm/qe-qasm.git"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "examples": [True, False]}
default_options = {
"shared": False,
"examples": True,
# Enforce dynamic linking against LGPL dependencies
"gmp:shared": True,
"mpc:shared": True,
"mpfr:shared": True,
}
license = "Apache-2.0"
author = "OpenQASM Organization"
topics = ("Parser", "OpenQASM3", "Quantum", "Computing")
description = "A flex/bison parser for OpenQASM v3. A part of the Quantum Engine project."
generators = "CMakeDeps"
def requirements(self):
# Private deps won't be linked against by consumers, which is important
# at least for Flex which does not expose a CMake target.
private_deps = ["bison", "flex"]
for req in self.conan_data["requirements"]:
private = any(req.startswith(d) for d in private_deps)
self.requires(req, private=private)
def build_requirements(self):
for req in self.conan_data["build_requirements"]:
self.tool_requires(req)
def export_sources(self):
sources = [
"cmake*",
"examples*",
"include*",
"lib*",
"licenses*",
"LICENSE*",
"utils*",
"cmake*",
"tests*",
"Makefile*",
"CMakeLists*",
"VERSION.txt",
]
for source in sources:
self.copy(source)
save(os.path.join(self.export_sources_folder, "VERSION.txt"), self.version)
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
tc.cache_variables["BUILD_STATIC_LIBS"] = not self.options.shared
tc.cache_variables["OPENQASM_BUILD_EXAMPLES"] = self.options.examples
tc.generate()
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
use_monitor = False
if self.should_build:
# Note that if a job does not produce output for a longer period of
# time, then Travis will cancel that job.
# Avoid that timeout by running vmstat in the background, which reports
# free memory and other stats every 30 seconds.
use_monitor = platform.system() == "Linux"
if use_monitor:
subprocess.run("free -h ; lscpu", shell=True)
monitor = subprocess.Popen(["vmstat", "-w", "30", "-t"])
cmake.build()
if use_monitor:
monitor.terminate()
monitor.wait(1)
if self.should_test:
self.test(cmake)
def test(self, cmake):
# Tests require examples to be built
if self.options.examples:
cmake.test(target="test")
def package(self):
cmake = CMake(self)
cmake.install()
self.copy("*.tab.cpp", dst="include/lib/Parser", src="lib/Parser")
self.copy("*.tab.h", dst="include/lib/Parser", src="lib/Parser")
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "qasm")
self.cpp_info.set_property("cmake_target_name", "qasm::qasm")
self.cpp_info.libs = ["qasmParser", "qasmFrontend", "qasmAST", "qasmDIAG"]