-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
190 lines (155 loc) · 8.19 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import os, stat, json, re, subprocess
from conans import ConanFile, CMake, tools
from conans.tools import os_info, SystemPackageTool
from conans.errors import ConanInvalidConfiguration
from conans.model import Generator
class VCVRackSDKConan(ConanFile):
name = "vcvrack-sdk"
version = "1.1.6"
license = "GPL-3.0"
author = "Andrew Belt"
url = "https://github.com/qno/conan-vcvrack-sdk"
homepage = "https://vcvrack.com"
description = "VCV Rack SDK for Rack plugin development."
settings = "os", "compiler", "arch"
_SDK_DIR = "Rack-SDK"
def configure(self):
if self._isVisualStudioBuild:
self.output.error("Rack SDK on Windows is only compatible with MinGW GCC toolchain!")
raise ConanInvalidConfiguration("VCV Rack SDK is not compatible with Visual Studio!")
if self.settings.arch != "x86_64":
raise ConanInvalidConfiguration("VCV Rack SDK currently only supports x86_64 platform!")
def requirements(self):
if self.settings.os == "Windows":
self.requires.add("msys2/20210105")
def system_requirements(self):
packages = ["git", "zip", "make", "cmake", "jq"]
if self.settings.os == "Windows":
self.output.warn("manipulate script internal environment - add MSYS_BIN to PATH for using pacman tool")
del os.environ["CONAN_SYSREQUIRES_SUDO"]
os.environ["PATH"] += os.pathsep + self.env["MSYS_BIN"]
packages = ["zip", "mingw-w64-x86_64-jq", "mingw-w64-x86_64-libwinpthread"]
if self.settings.os == "Macos":
packages += ["autoconf", "automake", "libtool"]
if self.settings.os == "Linux":
mesaPackage = { "ubuntu": "libglu1-mesa-dev",
"debian": "libglu1-mesa-dev",
"fedora": "mesa-libGLU-devel",
"centos": "mesa-libGLU-devel",
"arch": "mesa"
}
packages += [mesaPackage[os_info.linux_distro]]
installer = SystemPackageTool()
for package in packages:
installer.install(package, update=False)
def build(self):
url = "https://vcvrack.com/downloads/Rack-SDK-{}.zip".format(self.version)
self.output.info("Downloading {}".format(url))
tools.get(url)
def package(self):
self.copy("*.*", dst="include", src="{}/include".format(self._SDK_DIR))
self.copy("*.*", dst="dep", src="{}/dep".format(self._SDK_DIR))
self.copy("*.mk", dst=".", src="{}".format(self._SDK_DIR))
os.chmod(os.path.join(self._SDK_DIR, "helper.py"), stat.S_IRWXU|stat.S_IRGRP|stat.S_IROTH)
self.copy("helper.py", dst="script", src="{}".format(self._SDK_DIR))
self.copy("*Rack*.a", dst=".", keep_path=False)
def package_info(self):
if self.settings.os == "Windows":
self.cpp_info.cxxflags.append("-DARCH_WIN -D_USE_MATH_DEFINES")
self.cpp_info.libs.append("Rack")
self.env_info.path.append(os.path.join(self.deps_env_info["msys2"].MSYS_ROOT, "mingw64", "bin"))
self.cpp_info.libdirs.append(os.path.join(self.package_folder))
self.user_info.rack_sdk_dir = os.path.join(self.package_folder)
if self.settings.os == "Linux":
self.cpp_info.cxxflags.append("-DARCH_LIN")
if self.settings.os == "Macos":
self.cpp_info.cxxflags.append("-DARCH_MAC")
if self.settings.compiler == "apple-clang":
self.cpp_info.cxxflags.append("-undefined dynamic_lookup -Wno-unused-command-line-argument")
else:
self.cpp_info.cxxflags.append("-Wsuggest-override")
self.cpp_info.cxxflags.append("-march=nocona -funsafe-math-optimizations -fPIC")
self.cpp_info.cxxflags.append("-Wall -Wextra -Wno-unused-parameter")
self.cpp_info.includedirs = ["include", "dep/include"]
self.env_info.path.append(os.path.join(self.package_folder, "script"))
self.env_info.RACK_DIR = os.path.join(self.package_folder)
def package_id(self):
self.info.header_only()
@property
def _isMinGWBuild(self):
return self.settings.os == "Windows" and self.settings.compiler == "gcc"
@property
def _isVisualStudioBuild(self):
return self.settings.os == "Windows" and self.settings.compiler == "Visual Studio"
# custom generator to generate CMakeSettings.json that can be used with MS Visual Studio
class VSCMakeSettings(Generator):
@property
def filename(self):
return "CMakeSettings.json"
@property
def content(self):
if self.settings.os != "Windows":
print("*** VSCMakeSettings generator is only supported on Windows - generate empty file!")
return "VSCMakeSettings generator is only supported on Windows!"
print("*** Generate '{}' for Visual Studio".format(self.filename))
print("*** Please copy the generated '{}' manually into your Plugin source folder to use it with Visual Studio!".format(self.filename))
content = { "configurations" : [ self._createConfiguration("Release"),
self._createConfiguration("Debug")
]
}
return json.dumps(content, indent=2)
def _createConfiguration(self, cmakeBuildtype):
configuration = { "name" : "Mingw64-{}".format(cmakeBuildtype),
"generator": "Ninja",
"configurationType": cmakeBuildtype,
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "mingw_64" ],
"environments": [ self._createEnvironment ],
"variables": self._createVariables,
"intelliSenseMode": "linux-gcc-x64"
}
return configuration
@property
def _createEnvironment(self):
environment = { "MINGW64_ROOT": self._getMinGWRoot,
"BIN_ROOT": os.path.join(self._getMinGWHome, "bin"),
"FLAVOR": self._getFlavor,
"TOOLSET_VERSION": self._getToolsetVersion,
"GCC_HEADERS_ROOT": "${env.MINGW64_ROOT}\\${env.FLAVOR}\\${env.TOOLSET_VERSION}\\include",
"PATH": "${env.BIN_ROOT};${env.PATH}",
"INCLUDE": "${env.INCLUDE};${env.GCC_HEADERS_ROOT}\\c++;${env.GCC_HEADERS_ROOT}\\c++\\${env.FLAVOR};${env.GCC_HEADERS_ROOT}\\c++\\backward;${env.GCC_HEADERS_ROOT}\\include;${env.GCC_HEADERS_ROOT}\\..\\include-fixed;${env.BIN_ROOT}\\..\\${env.FLAVOR}\\include",
"environment": "mingw_64"
}
return environment
@property
def _getMinGWHome(self):
return self.conanfile.deps_env_info["mingw-w64"].MINGW_HOME
@property
def _getMinGWRoot(self):
return os.path.join(self._getMinGWHome, "lib", "gcc")
def _getGccInfo(self, option):
result = subprocess.run(os.path.join(self._getMinGWHome, "bin", "gcc.exe") + " -{}".format(option), capture_output=True)
return result.stdout.decode('utf-8').strip()
@property
def _getFlavor(self):
return self._getGccInfo("dumpmachine")
@property
def _getToolsetVersion(self):
return self._getGccInfo("dumpversion")
@property
def _createVariables(self):
variables = [ self._createCMakeVariable("CMAKE_C_COMPILER", "${env.BIN_ROOT}\\gcc.exe", "STRING"),
self._createCMakeVariable("CMAKE_CXX_COMPILER", "${env.BIN_ROOT}\\g++.exe", "STRING"),
self._createCMakeVariable("RACK_SDK", "{}".format(self.conanfile.deps_user_info["vcvrack-sdk"].rack_sdk_dir), "STRING")
]
return variables
def _createCMakeVariable(self, name, value, varType):
variable = { "name": name,
"value": value,
"type": varType
}
return variable