Moved all custom config checks to separate files.

This commit is contained in:
Sergey Popov 2008-05-06 13:19:38 +00:00
parent a09fb63227
commit 5610e7f241
4 changed files with 220 additions and 245 deletions

View file

@ -130,240 +130,6 @@ for example, to point scons at non-default library locations.
if env["cachedir"]:
CacheDir(env["cachedir"])
#
# Generic pkg-config support is not presentluy used, but might be in the future
#
def CheckPKGConfig(context, version):
context.Message( 'Checking for pkg-config... ' )
ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
context.Result( ret )
return ret
def CheckPKG(context, name):
context.Message( 'Checking for %s... ' % name )
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result( ret )
return ret
#
# Most of our required runtime support is from Boost SDL.
#
def backup_env(env, vars):
backup = dict()
for var in vars:
backup[var] = env.get(var, [])
return backup
def restore_env(env, backup):
for var in backup.keys():
env[var] = backup[var]
def CheckCPlusPlus(context, gcc_version = None):
message = "Checking whether C++ compiler works "
test_program = """
#include <iostream>
int main()
{
std::cout << "Hello, world\\n";
}
"""
if gcc_version and "gcc" in context.env["TOOLS"]:
message += "(g++ version >= %s required)" % gcc_version
import operator
version = gcc_version.split(".", 3)
version = map(int, version)
version = map(lambda x,y: x or y, version, (0,0,0))
multipliers = (10000, 100, 1)
version_num = sum(map(operator.mul, version, multipliers))
test_program += """
#define GCC_VERSION (__GNUC__ * 10000 \\
+ __GNUC_MINOR__ * 100 \\
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < %d
#error Compiler version is too old!
#endif
\n""" % version_num
message += "... "
context.Message(message)
if context.TryBuild(context.env.Program, test_program, ".cpp") == 1 and context.lastTarget.get_contents() != "":
context.Result("yes")
return True
else:
context.Result("no")
return False
def CheckBoostLib(context, boost_lib, require_version = None):
env = context.env
boostdir = env.get("boostdir", "/usr/include")
boostlibdir = env.get("boostlibdir", "/usr/lib")
backup = backup_env(env, ["CPPPATH", "LIBPATH", "LIBS"])
boost_headers = { "regex" : "regex/config.hpp",
"iostreams" : "iostreams/constants.hpp",
"unit_test_framework" : "test/unit_test.hpp" }
header_name = boost_headers.get(boost_lib, boost_lib + ".hpp")
libname = "boost_" + boost_lib + env.get("boost_suffix", "")
env.AppendUnique(CPPPATH = [boostdir], LIBPATH = [boostlibdir])
env.AppendUnique(LIBS = [libname])
test_program = """
#include <boost/%s>
\n""" % header_name
if require_version:
version = require_version.split(".", 2)
major = int(version[0])
minor = int(version[1])
try:
sub_minor = int(version[2])
except (ValueError, IndexError):
sub_minor = 0
test_program += "#include <boost/version.hpp>\n"
test_program += \
"#if BOOST_VERSION < %d\n#error Boost version is too old!\n#endif\n" \
% (major * 100000 + minor * 100 + sub_minor)
test_program += """
int main()
{
}
\n"""
if context.TryLink(test_program, ".cpp"):
return True
else:
restore_env(env, backup)
return False
def CheckBoost(context, boost_lib, require_version = None):
if require_version:
context.Message("Checking for Boost %s library version >= %s... " % (boost_lib, require_version))
else:
context.Message("Checking for Boost %s library... " % boost_lib)
check_result = CheckBoostLib(context, boost_lib, require_version)
if not check_result and not context.env.get("boost_suffix"):
context.env["boost_suffix"] = "-mt"
check_result = CheckBoostLib(context, boost_lib, require_version)
if check_result:
context.Result("yes")
else:
context.Result("no")
return check_result
def CheckSDL(context, sdl_lib = "SDL", require_version = None):
if require_version:
version = require_version.split(".", 2)
major_version = int(version[0])
minor_version = int(version[1])
try:
patchlevel = int(version[2])
except (ValueError, IndexError):
patch_level = 0
backup = backup_env(context.env, ["CPPPATH", "LIBPATH", "LIBS"])
sdldir = context.env.get("sdldir", "")
if sdl_lib == "SDL":
if require_version:
context.Message("Checking for Simple DirectMedia Layer library version >= %d.%d.%d... " % (major_version, minor_version, patchlevel))
else:
context.Message("Checking for Simple DirectMedia Layer library... ")
env = context.env
if sdldir:
env.AppendUnique(CPPPATH = [os.path.join(sdldir, "include/SDL")], LIBPATH = [os.path.join(sdldir, "lib")])
else:
for foo_config in [
"pkg-config --cflags --libs sdl > $TARGET",
"sdl-config --cflags --libs > $TARGET"
]:
result, output = context.TryAction(foo_config)
if result == 1:
env.MergeFlags(output)
break
if env["PLATFORM"] == "win32":
env.AppendUnique(CCFLAGS = ["-D_GNU_SOURCE"])
env.AppendUnique(LIBS = Split("mingw32 SDLmain SDL"))
env.AppendUnique(LINKFLAGS = ["-mwindows"])
else:
if require_version:
context.Message("Checking for %s library version >= %d.%d.%d... " % (sdl_lib, major_version, minor_version, patchlevel))
else:
context.Message("Checking for %s library... " % sdl_lib)
context.env.AppendUnique(LIBS = [sdl_lib])
test_program = """
#include <%s.h>
\n""" % sdl_lib
if require_version:
test_program += "#if SDL_VERSIONNUM(%s, %s, %s) < SDL_VERSIONNUM(%d, %d, %d)\n#error Library is too old!\n#endif\n" % \
(sdl_lib.upper() + "_MAJOR_VERSION", \
sdl_lib.upper() + "_MINOR_VERSION", \
sdl_lib.upper() + "_PATCHLEVEL", \
major_version, minor_version, patchlevel)
test_program += """
int main(int argc, char** argv)
{
}
\n"""
if context.TryLink(test_program, ".c"):
context.Result("yes")
return True
else:
context.Result("no")
restore_env(context.env, backup)
return False
def CheckOgg(context):
test_program = '''
#include <SDL_mixer.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
Mix_Music* music = Mix_LoadMUS("data/core/music/main_menu.ogg");
if (music == NULL) {
exit(1);
}
exit(0);
}
\n
'''
#context.env.AppendUnique(LIBS = "SDL_mixer")
context.Message("Checking for Ogg Vorbis support in SDL... ")
(result, output) = context.TryRun(test_program, ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
return False
def CheckPNG(context):
test_program = '''
#include <SDL_image.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
SDL_RWops *src;
char *testimage = "images/buttons/button-pressed.png";
src = SDL_RWFromFile(testimage, "rb");
if (src == NULL) {
exit(2);
}
exit(!IMG_isPNG(src));
}
\n
'''
context.Message("Checking for PNG support in SDL... ")
(result, output) = context.TryRun(test_program, ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
return False
#
# Check some preconditions
#
@ -378,16 +144,7 @@ def Warning(message):
sys.path.append("./scons")
from metasconf import init_metasconf
custom_checks = { 'CheckCPlusPlus' : CheckCPlusPlus,
'CheckPKGConfig' : CheckPKGConfig,
'CheckPKG' : CheckPKG,
'CheckSDL' : CheckSDL,
'CheckOgg' : CheckOgg,
'CheckPNG' : CheckPNG,
'CheckBoost' : CheckBoost }
custom_checks.update(init_metasconf(env, ["python_devel"]))
conf = Configure(env, custom_tests = custom_checks)
conf = Configure(env, custom_tests = init_metasconf(env, ["cplusplus", "python_devel", "sdl", "boost"]))
if env["prereqs"]:
if env["gettextdir"]:
@ -442,7 +199,7 @@ env = conf.Finish()
# Implement configuration switches
#
# FIXME: Unix-specific.
# FIXME: gcc-specific.
# Link only on demand, so we don't need separate link lists for each binary
env.Append(LINKFLAGS = "-Wl,--as-needed")

60
scons/boost.py Normal file
View file

@ -0,0 +1,60 @@
# vi: syntax=python:et:ts=4
from config_check_utils import *
def CheckBoostLib(context, boost_lib, require_version = None):
env = context.env
boostdir = env.get("boostdir", "/usr/include")
boostlibdir = env.get("boostlibdir", "/usr/lib")
backup = backup_env(env, ["CPPPATH", "LIBPATH", "LIBS"])
boost_headers = { "regex" : "regex/config.hpp",
"iostreams" : "iostreams/constants.hpp",
"unit_test_framework" : "test/unit_test.hpp" }
header_name = boost_headers.get(boost_lib, boost_lib + ".hpp")
libname = "boost_" + boost_lib + env.get("boost_suffix", "")
env.AppendUnique(CPPPATH = [boostdir], LIBPATH = [boostlibdir])
env.AppendUnique(LIBS = [libname])
test_program = """
#include <boost/%s>
\n""" % header_name
if require_version:
version = require_version.split(".", 2)
major = int(version[0])
minor = int(version[1])
try:
sub_minor = int(version[2])
except (ValueError, IndexError):
sub_minor = 0
test_program += "#include <boost/version.hpp>\n"
test_program += \
"#if BOOST_VERSION < %d\n#error Boost version is too old!\n#endif\n" \
% (major * 100000 + minor * 100 + sub_minor)
test_program += """
int main()
{
}
\n"""
if context.TryLink(test_program, ".cpp"):
return True
else:
restore_env(env, backup)
return False
def CheckBoost(context, boost_lib, require_version = None):
if require_version:
context.Message("Checking for Boost %s library version >= %s... " % (boost_lib, require_version))
else:
context.Message("Checking for Boost %s library... " % boost_lib)
check_result = CheckBoostLib(context, boost_lib, require_version)
if not check_result and not context.env.get("boost_suffix"):
context.env["boost_suffix"] = "-mt"
check_result = CheckBoostLib(context, boost_lib, require_version)
if check_result:
context.Result("yes")
else:
context.Result("no")
return check_result
config_checks = { "CheckBoost" : CheckBoost }

38
scons/cplusplus.py Normal file
View file

@ -0,0 +1,38 @@
# vi: syntax=python:et:ts=4
from config_check_utils import *
def CheckCPlusPlus(context, gcc_version = None):
message = "Checking whether C++ compiler works "
test_program = """
#include <iostream>
int main()
{
std::cout << "Hello, world\\n";
}
"""
if gcc_version and "gcc" in context.env["TOOLS"]:
message += "(g++ version >= %s required)" % gcc_version
import operator
version = gcc_version.split(".", 3)
version = map(int, version)
version = map(lambda x,y: x or y, version, (0,0,0))
multipliers = (10000, 100, 1)
version_num = sum(map(operator.mul, version, multipliers))
test_program += """
#define GCC_VERSION (__GNUC__ * 10000 \\
+ __GNUC_MINOR__ * 100 \\
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < %d
#error Compiler version is too old!
#endif
\n""" % version_num
message += "... "
context.Message(message)
if context.TryBuild(context.env.Program, test_program, ".cpp") == 1 and context.lastTarget.get_contents() != "":
context.Result("yes")
return True
else:
context.Result("no")
return False
config_checks = { "CheckCPlusPlus" : CheckCPlusPlus }

120
scons/sdl.py Normal file
View file

@ -0,0 +1,120 @@
# vi: syntax=python:et:ts=4
from config_check_utils import *
def CheckSDL(context, sdl_lib = "SDL", require_version = None):
if require_version:
version = require_version.split(".", 2)
major_version = int(version[0])
minor_version = int(version[1])
try:
patchlevel = int(version[2])
except (ValueError, IndexError):
patch_level = 0
backup = backup_env(context.env, ["CPPPATH", "LIBPATH", "LIBS"])
sdldir = context.env.get("sdldir", "")
if sdl_lib == "SDL":
if require_version:
context.Message("Checking for Simple DirectMedia Layer library version >= %d.%d.%d... " % (major_version, minor_version, patchlevel))
else:
context.Message("Checking for Simple DirectMedia Layer library... ")
env = context.env
if sdldir:
env.AppendUnique(CPPPATH = [os.path.join(sdldir, "include/SDL")], LIBPATH = [os.path.join(sdldir, "lib")])
else:
for foo_config in [
"pkg-config --cflags --libs sdl > $TARGET",
"sdl-config --cflags --libs > $TARGET"
]:
result, output = context.TryAction(foo_config)
if result == 1:
env.MergeFlags(output)
break
if env["PLATFORM"] == "win32":
env.AppendUnique(CCFLAGS = ["-D_GNU_SOURCE"])
env.AppendUnique(LIBS = Split("mingw32 SDLmain SDL"))
env.AppendUnique(LINKFLAGS = ["-mwindows"])
else:
if require_version:
context.Message("Checking for %s library version >= %d.%d.%d... " % (sdl_lib, major_version, minor_version, patchlevel))
else:
context.Message("Checking for %s library... " % sdl_lib)
context.env.AppendUnique(LIBS = [sdl_lib])
test_program = """
#include <%s.h>
\n""" % sdl_lib
if require_version:
test_program += "#if SDL_VERSIONNUM(%s, %s, %s) < SDL_VERSIONNUM(%d, %d, %d)\n#error Library is too old!\n#endif\n" % \
(sdl_lib.upper() + "_MAJOR_VERSION", \
sdl_lib.upper() + "_MINOR_VERSION", \
sdl_lib.upper() + "_PATCHLEVEL", \
major_version, minor_version, patchlevel)
test_program += """
int main(int argc, char** argv)
{
}
\n"""
if context.TryLink(test_program, ".c"):
context.Result("yes")
return True
else:
context.Result("no")
restore_env(context.env, backup)
return False
def CheckOgg(context):
test_program = '''
#include <SDL_mixer.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
Mix_Music* music = Mix_LoadMUS("data/core/music/main_menu.ogg");
if (music == NULL) {
exit(1);
}
exit(0);
}
\n
'''
#context.env.AppendUnique(LIBS = "SDL_mixer")
context.Message("Checking for Ogg Vorbis support in SDL... ")
(result, output) = context.TryRun(test_program, ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
return False
def CheckPNG(context):
test_program = '''
#include <SDL_image.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
SDL_RWops *src;
char *testimage = "images/buttons/button-pressed.png";
src = SDL_RWFromFile(testimage, "rb");
if (src == NULL) {
exit(2);
}
exit(!IMG_isPNG(src));
}
\n
'''
context.Message("Checking for PNG support in SDL... ")
(result, output) = context.TryRun(test_program, ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
return False
config_checks = { 'CheckSDL' : CheckSDL,
'CheckOgg' : CheckOgg,
'CheckPNG' : CheckPNG }