You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.9 KiB
89 lines
2.9 KiB
6 years ago
|
# encoding: utf-8
|
||
|
# sdl2.py -- sdl2 waf plugin
|
||
|
# Copyright (C) 2018 a1batross
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
|
||
|
import os
|
||
|
|
||
|
def options(opt):
|
||
6 years ago
|
grp = opt.add_option_group('SDL2 options')
|
||
6 years ago
|
grp.add_option('-s', '--sdl2', action='store', dest = 'SDL2_PATH', default = None,
|
||
6 years ago
|
help = 'path to precompiled SDL2 library(required for Windows)')
|
||
6 years ago
|
|
||
6 years ago
|
grp.add_option('--skip-sdl2-sanity-check', action='store_false', default = True, dest='SDL2_SANITY_CHECK',
|
||
6 years ago
|
help = 'skip checking SDL2 sanity')
|
||
6 years ago
|
|
||
6 years ago
|
def my_dirname(path):
|
||
|
# really dumb, will not work with /path/framework//, but still enough
|
||
|
if path[-1] == '/':
|
||
|
path = path[:-1]
|
||
|
return os.path.dirname(path)
|
||
|
|
||
6 years ago
|
def sdl2_configure_path(conf, path):
|
||
|
conf.env.HAVE_SDL2 = 1
|
||
|
if conf.env.DEST_OS == 'darwin':
|
||
|
conf.env.INCLUDES_SDL2 = [
|
||
6 years ago
|
os.path.abspath(os.path.join(path, 'Headers'))
|
||
6 years ago
|
]
|
||
6 years ago
|
conf.env.FRAMEWORKPATH_SDL2 = [my_dirname(path)]
|
||
6 years ago
|
conf.env.FRAMEWORK_SDL2 = ['SDL2']
|
||
|
else:
|
||
6 years ago
|
conf.env.INCLUDES_SDL2 = [
|
||
6 years ago
|
os.path.abspath(os.path.join(path, 'include')),
|
||
|
os.path.abspath(os.path.join(path, 'include/SDL2'))
|
||
6 years ago
|
]
|
||
|
libpath = 'lib'
|
||
|
if conf.env.COMPILER_CC == 'msvc':
|
||
|
if conf.env.DEST_CPU == 'x86_64':
|
||
|
libpath = 'lib/x64'
|
||
|
else:
|
||
|
libpath = 'lib/' + conf.env.DEST_CPU
|
||
6 years ago
|
conf.env.LIBPATH_SDL2 = [os.path.abspath(os.path.join(path, libpath))]
|
||
6 years ago
|
conf.env.LIB_SDL2 = ['SDL2']
|
||
6 years ago
|
|
||
|
def configure(conf):
|
||
|
if conf.options.SDL2_PATH:
|
||
|
conf.start_msg('Configuring SDL2 by provided path')
|
||
|
sdl2_configure_path(conf, conf.options.SDL2_PATH)
|
||
6 years ago
|
conf.end_msg('yes: {0}, {1}, {2}'.format(conf.env.LIB_SDL2, conf.env.LIBPATH_SDL2, conf.env.INCLUDES_SDL2))
|
||
|
else:
|
||
|
try:
|
||
|
conf.check_cfg(
|
||
|
path='sdl2-config',
|
||
|
args='--cflags --libs',
|
||
|
package='',
|
||
|
msg='Checking for library SDL2',
|
||
|
uselib_store='SDL2')
|
||
|
except conf.errors.ConfigurationError:
|
||
|
conf.env.HAVE_SDL2 = 0
|
||
5 years ago
|
|
||
|
if not conf.env.HAVE_SDL2 and conf.env.CONAN:
|
||
|
conf.load('conan')
|
||
|
conf.add_conan_remote('bincrafters', 'https://api.bintray.com/conan/bincrafters/public-conan')
|
||
|
conf.add_dependency('sdl2/2.0.9@bincrafters/stable', options = { 'shared': 'True' } )
|
||
6 years ago
|
|
||
|
if conf.env.HAVE_SDL2 and conf.options.SDL2_SANITY_CHECK:
|
||
|
try:
|
||
|
conf.check_cc(
|
||
|
fragment='''
|
||
|
#define SDL_MAIN_HANDLED
|
||
|
#include <SDL.h>
|
||
|
int main( void )
|
||
|
{
|
||
|
SDL_Init( SDL_INIT_EVERYTHING );
|
||
|
return 0;
|
||
|
}''',
|
||
|
msg = 'Checking for library SDL2 sanity',
|
||
|
use = 'SDL2',
|
||
|
execute = False)
|
||
|
except conf.errors.ConfigurationError:
|
||
|
conf.env.HAVE_SDL2 = 0
|