forked from bincrafters/conan-sdl2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconanfile.py
332 lines (304 loc) · 14.9 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
class SDL2Conan(ConanFile):
name = "sdl2"
description = "Access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL, Direct3D and Vulkan"
topics = ("conan", "sdl2", "audio", "keyboard", "graphics", "opengl")
url = "https://github.com/bincrafters/conan-sdl2"
homepage = "https://www.libsdl.org"
license = "Zlib"
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = ["cmake", "pkg_config"]
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"directx": [True, False],
"alsa": [True, False],
"jack": [True, False],
"pulse": [True, False],
"nas": [True, False],
"esd": [True, False],
"arts": [True, False],
"x11": [True, False],
"xcursor": [True, False],
"xinerama": [True, False],
"xinput": [True, False],
"xrandr": [True, False],
"xscrnsaver": [True, False],
"xshape": [True, False],
"xvm": [True, False],
"wayland": [True, False],
"directfb": [True, False],
"iconv": [True, False],
"video_rpi": [True, False],
"sdl2main": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"directx": True,
"alsa": True,
"jack": True,
"pulse": True,
"nas": True,
"esd": False,
"arts": False,
"x11": True,
"xcursor": True,
"xinerama": True,
"xinput": True,
"xrandr": True,
"xscrnsaver": True,
"xshape": True,
"xvm": True,
"wayland": False,
"directfb": False,
"iconv": True,
"video_rpi": False,
"sdl2main": True
}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
_cmake = None
def requirements(self):
if self.options.iconv:
self.requires.add("libiconv/1.16")
if self.settings.os == "Linux" and tools.os_info.is_linux:
self.requires.add("libdrm/2.4.100@bincrafters/stable")
if not tools.which('pkg-config'):
self.requires.add("pkg-config_installer/0.29.2@bincrafters/stable")
if self.options.alsa:
self.requires.add("libalsa/1.1.9")
if self.options.x11:
self.requires.add("libx11/1.6.8@bincrafters/stable")
self.requires.add("libxext/1.3.4@bincrafters/stable")
if self.options.xcursor:
self.requires.add("libxcursor/1.2.0@bincrafters/stable")
if self.options.xinerama:
self.requires.add("libxinerama/1.1.4@bincrafters/stable")
if self.options.xinput:
self.requires.add("libxi/1.7.10@bincrafters/stable")
if self.options.xrandr:
self.requires.add("libxrandr/1.5.2@bincrafters/stable")
if self.options.xscrnsaver:
self.requires.add("libxscrnsaver/1.2.3@bincrafters/stable")
if self.options.xvm:
self.requires.add("libxxf86vm/1.1.4@bincrafters/stable")
if self.options.wayland:
self.requires.add("xkbcommon/0.9.1@bincrafters/stable")
if self.options.pulse:
self.requires("pulseaudio/13.0@bincrafters/stable")
self.requires("opengl/virtual@bincrafters/stable")
def system_requirements(self):
if self.settings.os == "Linux" and tools.os_info.is_linux:
if tools.os_info.with_apt or tools.os_info.with_yum:
installer = tools.SystemPackageTool()
packages = []
packages_apt = []
packages_yum = []
packages_apt.append('libgbm-dev')
packages_yum.append('gdm-devel')
if self.options.jack:
packages_apt.append('libjack-dev')
packages_yum.append('jack-audio-connection-kit-devel')
if self.options.nas:
packages_apt.append('libaudio-dev')
packages_yum.append('nas-devel')
if self.options.esd:
packages_apt.append('libesd0-dev')
packages_yum.append('esound-devel')
if self.options.arts:
packages_apt.append('artsc0-dev')
if self.options.wayland:
packages_apt.extend(['libwayland-dev',
'wayland-protocols'])
packages_yum.extend(['wayland-devel',
'wayland-protocols-devel'])
if self.options.directfb:
packages_apt.append('libdirectfb-dev')
if tools.os_info.with_apt:
packages = packages_apt
elif tools.os_info.with_yum:
packages = packages_yum
for package in packages:
installer.install(package)
def config_options(self):
if self.settings.os != "Linux":
self.options.remove("alsa")
self.options.remove("jack")
self.options.remove("pulse")
self.options.remove("nas")
self.options.remove("esd")
self.options.remove("arts")
self.options.remove("x11")
self.options.remove("xcursor")
self.options.remove("xinerama")
self.options.remove("xinput")
self.options.remove("xrandr")
self.options.remove("xscrnsaver")
self.options.remove("xshape")
self.options.remove("xvm")
self.options.remove('wayland')
self.options.remove('directfb')
self.options.remove('video_rpi')
if self.settings.os != "Windows":
self.options.remove("directx")
def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.settings.compiler == 'Visual Studio':
del self.options.fPIC
if self.settings.os == "Macos" and not self.options.iconv:
raise ConanInvalidConfiguration("On macOS iconv can't be disabled")
def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "SDL2-" + self.version
os.rename(extracted_dir, self._source_subfolder)
if "patches" in self.conan_data and self.version in self.conan_data["patches"]:
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
def build(self):
# ensure sdl2-config is created for MinGW
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"if(NOT WINDOWS OR CYGWIN)",
"if(NOT WINDOWS OR CYGWIN OR MINGW)")
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"if(NOT (WINDOWS OR CYGWIN))",
"if(NOT (WINDOWS OR CYGWIN OR MINGW))")
self._build_cmake()
def _check_pkg_config(self, option, package_name):
if option:
pkg_config = tools.PkgConfig(package_name)
if not pkg_config.provides:
raise ConanInvalidConfiguration('package %s is not available' % package_name)
def _check_dependencies(self):
if self.settings.os == 'Linux':
self._check_pkg_config(self.options.jack, 'jack')
self._check_pkg_config(self.options.esd, 'esound')
self._check_pkg_config(self.options.wayland, 'wayland-client')
self._check_pkg_config(self.options.wayland, 'wayland-protocols')
self._check_pkg_config(self.options.directfb, 'directfb')
def _configure_cmake(self):
if not self._cmake:
self._check_dependencies()
self._cmake = CMake(self)
# FIXME: self.install_folder not defined? Neccessary?
self._cmake.definitions['CONAN_INSTALL_FOLDER'] = self.install_folder
if self.settings.os != 'Windows':
if not self.options.shared:
self._cmake.definitions['SDL_STATIC_PIC'] = self.options.fPIC
if self.settings.compiler == 'Visual Studio' and not self.options.shared:
self._cmake.definitions['HAVE_LIBC'] = True
self._cmake.definitions['SDL_SHARED'] = self.options.shared
self._cmake.definitions['SDL_STATIC'] = not self.options.shared
if self.settings.os == "Linux":
# See https://github.com/bincrafters/community/issues/696
self._cmake.definitions['SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS'] = 1
self._cmake.definitions['ALSA'] = self.options.alsa
if self.options.alsa:
self._cmake.definitions['HAVE_ASOUNDLIB_H'] = True
self._cmake.definitions['HAVE_LIBASOUND'] = True
self._cmake.definitions['JACK'] = self.options.jack
self._cmake.definitions['PULSEAUDIO'] = self.options.pulse
self._cmake.definitions['NAS'] = self.options.nas
self._cmake.definitions['VIDEO_X11'] = self.options.x11
if self.options.x11:
self._cmake.definitions['HAVE_XEXT_H'] = True
self._cmake.definitions['VIDEO_X11_XCURSOR'] = self.options.xcursor
if self.options.xcursor:
self._cmake.definitions['HAVE_XCURSOR_H'] = True
self._cmake.definitions['VIDEO_X11_XINERAMA'] = self.options.xinerama
if self.options.xinerama:
self._cmake.definitions['HAVE_XINERAMA_H'] = True
self._cmake.definitions['VIDEO_X11_XINPUT'] = self.options.xinput
if self.options.xinput:
self._cmake.definitions['HAVE_XINPUT_H'] = True
self._cmake.definitions['VIDEO_X11_XRANDR'] = self.options.xrandr
if self.options.xrandr:
self._cmake.definitions['HAVE_XRANDR_H'] = True
self._cmake.definitions['VIDEO_X11_XSCRNSAVER'] = self.options.xscrnsaver
if self.options.xscrnsaver:
self._cmake.definitions['HAVE_XSS_H'] = True
self._cmake.definitions['VIDEO_X11_XSHAPE'] = self.options.xshape
if self.options.xshape:
self._cmake.definitions['HAVE_XSHAPE_H'] = True
self._cmake.definitions['VIDEO_X11_XVM'] = self.options.xvm
if self.options.xvm:
self._cmake.definitions['HAVE_XF86VM_H'] = True
self._cmake.definitions['VIDEO_WAYLAND'] = self.options.wayland
self._cmake.definitions['VIDEO_DIRECTFB'] = self.options.directfb
self._cmake.definitions['VIDEO_RPI'] = self.options.video_rpi
self._cmake.definitions['HAVE_VIDEO_OPENGL'] = True
self._cmake.definitions['HAVE_VIDEO_OPENGL_EGL'] = True
elif self.settings.os == "Windows":
self._cmake.definitions["DIRECTX"] = self.options.directx
self._cmake.configure(build_dir=self._build_subfolder)
return self._cmake
def _build_cmake(self):
if self.settings.os == "Linux":
if self.options.pulse:
os.rename('libpulse.pc', 'libpulse-simple.pc')
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy(pattern="COPYING.txt", dst="license", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install(build_dir=self._build_subfolder)
tools.rmdir(os.path.join(self.package_folder, "cmake"))
def _add_libraries_from_pc(self, library, static=None):
if static is None:
static = not self.options.shared
pkg_config = tools.PkgConfig(library, static=static)
libs = [lib[2:] for lib in pkg_config.libs_only_l] # cut -l prefix
lib_paths = [lib[2:] for lib in pkg_config.libs_only_L] # cut -L prefix
self.cpp_info.libs.extend(libs)
self.cpp_info.libdirs.extend(lib_paths)
self.cpp_info.sharedlinkflags.extend(pkg_config.libs_only_other)
self.cpp_info.exelinkflags.extend(pkg_config.libs_only_other)
def package_id(self):
del self.info.options.sdl2main
@staticmethod
def _chmod_plus_x(filename):
if os.name == 'posix':
os.chmod(filename, os.stat(filename).st_mode | 0o111)
def package_info(self):
sdl2_config = os.path.join(self.package_folder, 'bin', "sdl2-config")
self._chmod_plus_x(sdl2_config)
self.output.info('Creating SDL2_CONFIG environment variable: %s' % sdl2_config)
self.env_info.SDL2_CONFIG = sdl2_config
self.output.info('Creating SDL_CONFIG environment variable: %s' % sdl2_config)
self.env_info.SDL_CONFIG = sdl2_config
self.cpp_info.libs = [lib for lib in tools.collect_libs(self) if '2.0' not in lib]
if not self.options.sdl2main:
self.cpp_info.libs = [lib for lib in self.cpp_info.libs]
else:
# ensure that SDL2main is linked first
sdl2mainlib = "SDL2main"
if self.settings.build_type == "Debug":
sdl2mainlib = "SDL2maind"
self.cpp_info.libs.insert(0, self.cpp_info.libs.pop(self.cpp_info.libs.index(sdl2mainlib)))
self.cpp_info.includedirs.append(os.path.join('include', 'SDL2'))
if self.settings.os == "Linux":
self.cpp_info.system_libs.extend(['dl', 'rt', 'pthread'])
if self.options.jack:
self._add_libraries_from_pc('jack')
if self.options.nas:
self.cpp_info.libs.append('audio')
if self.options.esd:
self._add_libraries_from_pc('esound')
if self.options.directfb:
self._add_libraries_from_pc('directfb')
if self.options.video_rpi:
self.cpp_info.libs.append('bcm_host')
self.cpp_info.includedirs.extend(["/opt/vc/include",
"/opt/vc/include/interface/vcos/pthreads",
"/opt/vc/include/interface/vmcs_host/linux"])
self.cpp_info.libdirs.append("/opt/vc/lib")
self.cpp_info.sharedlinkflags.append("-Wl,-rpath,/opt/vc/lib")
self.cpp_info.exelinkflags.append("-Wl,-rpath,/opt/vc/lib")
elif self.settings.os == "Macos":
self.cpp_info.frameworks.extend(['Cocoa', 'Carbon', 'IOKit', 'CoreVideo', 'CoreAudio', 'AudioToolbox', 'ForceFeedback'])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.extend(['user32', 'gdi32', 'winmm', 'imm32', 'ole32', 'oleaut32', 'version', 'uuid', 'advapi32', 'setupapi', 'shell32'])