-
Notifications
You must be signed in to change notification settings - Fork 1
/
conanfile.py
152 lines (128 loc) · 6.72 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
from conans import ConanFile, CMake, tools
import re, os, platform
class RtMidiConan(ConanFile):
name = "RtMidi"
version = "4.0.0"
license = "MIT"
author = "Gary P. Scavone"
url = "https://github.com/qno/conan-rtmidi"
homepage = "https://github.com/thestk/rtmidi"
description = "A set of C++ classes that provide a common API for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI & JACK) and Windows (Multimedia)."
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
options = {
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"fPIC": True
}
_pkg_name = "rtmidi-4.0.0"
_libname = "rtmidi"
def system_requirements(self):
if tools.os_info.is_linux:
if tools.os_info.with_apt:
installer = tools.SystemPackageTool()
if self.settings.arch == "x86" and tools.detected_architecture() == "x86_64":
arch_suffix = ':i386'
installer.install("g++-multilib")
else:
arch_suffix = ''
installer.install("{}{}".format("libasound2-dev", arch_suffix))
installer.install("{}{}".format("libjack-dev", arch_suffix))
elif tools.os_info.with_yum:
installer = tools.SystemPackageTool()
if self.settings.arch == "x86" and tools.detected_architecture() == "x86_64":
arch_suffix = '.i686'
else:
arch_suffix = ''
installer.install("{}{}".format("alsa-lib-devel", arch_suffix))
installer.install("{}{}".format("jack-audio-connection-kit-devel", arch_suffix))
elif tools.os_info.with_pacman:
if self.settings.arch == "x86" and tools.detected_architecture() == "x86_64":
# Note: The packages with the "lib32-" prefix will only be
# available if the user has activate Arch's multilib
# repository, See
# https://wiki.archlinux.org/index.php/official_repositories#multilib
arch_suffix = 'lib32-'
else:
arch_suffix = ''
installer = tools.SystemPackageTool()
installer.install("{}{}".format(arch_suffix, "alsa-lib"))
installer.install("{}{}".format(arch_suffix, "jack2"))
else:
self.output.warn("Could not determine package manager, skipping Linux system requirements installation.")
def source(self):
url = "http://www.music.mcgill.ca/~gary/rtmidi/release/{}.tar.gz".format(self._pkg_name)
self.output.info("Downloading {}".format(url))
tools.get(url)
# the conan_basic_setup() must be called, otherwise the compiler runtime settings won't be setup correct,
# which then leads then to linker errors if recipe e.g. is build with /MT runtime for MS compiler
# see https://github.com/conan-io/conan/issues/3312
self._patchCMakeListsFile(self._pkg_name)
def configure(self):
if self._isVisualStudioBuild():
del self.options.fPIC
def build(self):
cmake = CMake(self)
if self._isVisualStudioBuild() or self._isMinGWBuild():
if self.settings.build_type == "Debug":
cmake.definitions["CMAKE_DEBUG_POSTFIX"] = "d"
cmake.definitions["RTMIDI_BUILD_TESTING"] = False
if self.options.shared:
cmake.definitions["RTMIDI_BUILD_STATIC_LIBS"] = False
else:
cmake.definitions["RTMIDI_BUILD_SHARED_LIBS"] = False
cmake.configure(source_dir=self._pkg_name)
cmake.build()
def package(self):
self.copy("*.h", dst="include/rtmidi", excludes="contrib", src=self._pkg_name)
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="lib", keep_path=False)
self.copy("*.so*", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
release_libs = [self._libname]
debug_libs = [self._libname]
libs = []
# Note: this must be correctly refined with options added for selecting
if self.settings.os == "Linux":
libs = ["pthread", "asound", "jack"]
if self.settings.os == "Macos":
self.cpp_info.exelinkflags.append("-framework CoreMIDI -framework CoreAudio -framework CoreFoundation")
if self._isVisualStudioBuild() or self._isMinGWBuild():
debug_libs = ["{}d".format(self._libname)]
libs = ["winmm"]
release_libs.extend(libs)
debug_libs.extend(libs)
self.cpp_info.release.libs = release_libs
self.cpp_info.debug.libs = debug_libs
def _isVisualStudioBuild(self):
return self.settings.os == "Windows" and self.settings.compiler == "Visual Studio"
def _isMinGWBuild(self):
return self.settings.os == "Windows" and self.settings.compiler == "gcc"
def _patchCMakeListsFile(self, src_dir):
cmake_project_line = ""
cmake_file = "{}{}CMakeLists.txt".format(src_dir, os.sep)
self.output.warn("patch '{}' to inject conanbuildinfo".format(cmake_file))
for line in open(cmake_file, "r", encoding="utf8"):
if re.match("^PROJECT.*\\(.*\\).*", line.strip().upper()):
cmake_project_line = line.strip()
self.output.warn("found cmake project declaration '{}'".format(cmake_project_line))
break
tools.replace_in_file(cmake_file, "{}".format(cmake_project_line),
'''{}
include(${{CMAKE_BINARY_DIR}}/conanbuildinfo.cmake)
conan_basic_setup()'''.format(cmake_project_line))
self.output.warn("remove -Werror flag for Debug builds with gcc, otherwise x86 builds will fail")
tools.replace_in_file(cmake_file, "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Werror\")",
"set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS}\")")
if self.settings.os == "Linux":
self.output.warn("remove 'jack_port_rename' feature to avoid linker error on not supporting Linux systems")
tools.replace_in_file(cmake_file, "list(APPEND API_DEFS \"JACK_HAS_PORT_RENAME\")", "list(APPEND API_DEFS \"\")")
if platform.platform().startswith("Windows-2012"):
self.output.warn("set minimum required CMake version back to 3.7 on {} build server".format(platform.platform()))
tools.replace_in_file(cmake_file, "cmake_minimum_required(VERSION 3.10 FATAL_ERROR)",
"cmake_minimum_required(VERSION 3.7 FATAL_ERROR)")