2007-04-24 22:41:54 +02:00
-- this file provides package_add_extern_libs, which takes care of the
-- dirty details of adding the libraries' include and lib paths.
--
-- TYPICAL TASK: add new library. Instructions:
-- 1) add a new extern_lib_defs entry
2007-05-11 11:41:46 +02:00
-- 2) add library name to extern_libs tables in premake.lua for all 'packages' that want to use it
2007-04-24 22:41:54 +02:00
-- directory in which all library subdirectories reside.
libraries_dir = " ../../../libraries/ "
2007-05-17 05:37:49 +02:00
local function add_extern_lib_paths ( extern_lib )
-- Add '<libraries root>/<libraryname>/lib' and '/include' to the includepaths and libpaths
-- Often, the headers in libraries/ are windows-specific (always, except
-- for cxxtest and fcollada). So don't add the include dir unless on
-- windows or processing one of those libs.
2009-08-08 11:56:50 +02:00
if OS == " windows " or extern_lib == " cxxtest " or extern_lib == " fcollada " or extern_lib == " valgrind " or extern_lib == " spidermonkey " then
2007-05-17 05:37:49 +02:00
tinsert ( package.includepaths , libraries_dir .. extern_lib .. " /include " )
2009-08-11 00:38:51 +02:00
-- Insert libs at pos=1 (i.e. the front of the list) so they take
-- precedence over system libraries
tinsert ( package.libpaths , 1 , libraries_dir .. extern_lib .. " /lib " )
2007-05-17 05:37:49 +02:00
end
end
2007-04-24 22:41:54 +02:00
2009-08-08 11:56:50 +02:00
-- For unixes: add buildflags and linkflags from the given pkg-config module.
local function pkgconfig ( lib )
tinsert ( package.buildoptions , " `pkg-config " .. lib .. " --cflags` " )
tinsert ( package.gnu_external , " `pkg-config " .. lib .. " --libs` " )
end
2007-04-24 22:41:54 +02:00
-- library definitions
-- in a perfect world, libraries would have a common installation template,
-- i.e. location of include directory, naming convention for .lib, etc.
-- this table provides a means of working around each library's differences.
--
-- the default assumptions are:
-- * extern_lib (name of library [string]) is subdirectory of libraries_dir;
-- * this directory contains include and lib subdirectories which hold the
-- appendant files
-- * debug import library and DLL are distinguished with a "d" suffix
-- * the library should be marked for delay-loading.
--
-- the following options can override these:
-- * win_names: table of import library / DLL names (no extension) when
-- running on Windows.
-- * unix_names: as above; shared object names when running on non-Windows.
2009-07-18 04:03:29 +02:00
-- * osx_names: as above; for OS X specificall (overrides unix_names if both are
-- specified)
-- * linux_names: ditto for Linux (overrides unix_names if both given)
--
-- win- and unix-names are 'required'; if not specified, no linking against the
2008-06-28 22:02:05 +02:00
-- library happens on platforms whose *_names are missing.
2009-07-18 04:03:29 +02:00
-- (rationale: this allows for libraries that do not link against anything,
-- e.g. Boost).
--
2007-04-24 22:41:54 +02:00
-- * dbg_suffix: changes the debug suffix from the above default.
-- can be "" to indicate the library doesn't have a debug build;
-- in that case, the same library (without suffix) is used in
-- all build configurations.
-- * no_delayload: indicate the library is not to be delay-loaded.
-- this is necessary for some libraries that do not support it,
-- e.g. Xerces (which is so stupid as to export variables).
-- * add_func: a function that overrides everything else. responsible for
-- setting include and library paths, adding .links (linker input), and
-- arranging for delay-loading. this is necessary e.g. for wxWidgets,
-- which is unfortunately totally incompatible with our
-- library installation rules.
2009-08-08 11:56:50 +02:00
-- * depends: a table of external libraries that this library depends on
2009-12-28 17:45:42 +01:00
-- * defines: a table of symbols to define
2007-04-24 22:41:54 +02:00
extern_lib_defs = {
boost = {
2009-08-06 21:41:18 +02:00
unix_names = { " boost_signals-mt " , " boost_filesystem-mt " , " boost_system-mt " } ,
2009-07-18 04:03:29 +02:00
osx_names = { " boost_signals-mt " , " boost_filesystem-mt " , " boost_system-mt " }
2007-04-24 22:41:54 +02:00
} ,
2007-05-11 11:41:46 +02:00
cryptopp = {
2010-01-09 20:20:14 +01:00
win_names = { " cryptopp " } ,
unix_names = { " cryptopp " } ,
2007-05-11 11:41:46 +02:00
} ,
2007-04-24 22:41:54 +02:00
cxxtest = {
} ,
misc = {
} ,
2007-06-30 18:45:24 +02:00
comsuppw = {
win_names = { " comsuppw " } ,
dbg_suffix = " d " ,
no_delayload = 1
} ,
2007-04-24 22:41:54 +02:00
devil = {
unix_names = { " IL " , " ILU " } ,
} ,
2009-07-18 21:55:27 +02:00
dl = {
win_names = { } ,
unix_names = { " dl " } ,
} ,
2008-06-28 22:22:49 +02:00
-- rationale: see libraries_dir..enet/lib/rationale.txt
2008-05-31 22:00:37 +02:00
enet =
{
2008-06-28 22:02:05 +02:00
add_func = function ( )
if OS == " windows " then
tinsert ( package.includepaths , libraries_dir .. " enet/include " )
tinsert ( package.config [ " Debug " ] . libpaths , libraries_dir .. " enet/lib/debug " )
tinsert ( package.config [ " Testing " ] . libpaths , libraries_dir .. " enet/lib/debug " )
tinsert ( package.config [ " Release " ] . libpaths , libraries_dir .. " enet/lib/release " )
tinsert ( package.config [ " Debug " ] . links , " enet_dbg " )
tinsert ( package.config [ " Testing " ] . links , " enet_dbg " )
tinsert ( package.config [ " Release " ] . links , " enet " )
else
2009-08-08 11:56:50 +02:00
-- We should be using pkgconfig, but (at least on ubuntu) that adds /usr/include/enet which contains a time.h that gets used before the system header...
2009-08-06 21:41:18 +02:00
tinsert ( package.links , " enet " )
2008-06-28 22:02:05 +02:00
end
end ,
2008-05-31 22:00:37 +02:00
} ,
2007-04-24 22:41:54 +02:00
fcollada = {
win_names = { " FCollada " } ,
unix_names = { " FColladaSD " } ,
dbg_suffix = " D " ,
no_delayload = 1 ,
} ,
ffmpeg = {
win_names = { " avcodec-51 " , " avformat-51 " , " avutil-49 " , " swscale-0 " } ,
unix_names = { " avcodec " , " avformat " , " avutil " } ,
dbg_suffix = " " ,
} ,
libjpg = {
win_names = { " jpeg-6b " } ,
unix_names = { " jpeg " } ,
} ,
libpng = {
win_names = { " libpng13 " } ,
unix_names = { " png " } ,
} ,
2009-03-22 20:06:21 +01:00
libxml2 = {
add_func = function ( )
if OS == " windows " then
tinsert ( package.includepaths , libraries_dir .. " libxml2/include " )
tinsert ( package.libpaths , libraries_dir .. " libxml2/lib " )
tinsert ( package.config [ " Debug " ] . links , " libxml2 " )
tinsert ( package.config [ " Testing " ] . links , " libxml2 " )
tinsert ( package.config [ " Release " ] . links , " libxml2 " )
2009-07-18 04:03:29 +02:00
else
2009-08-08 11:56:50 +02:00
pkgconfig ( " libxml-2.0 " )
2009-08-07 09:58:32 +02:00
-- libxml2 needs _REENTRANT or __MT__ for thread support;
-- OS X doesn't get either set by default, so do it manually
2009-08-07 14:22:56 +02:00
if OS == " macosx " then
2009-08-07 09:58:32 +02:00
tinsert ( package.defines , " _REENTRANT " )
end
2009-03-22 20:06:21 +01:00
end
end ,
} ,
2009-08-08 11:56:50 +02:00
nspr = {
-- On windows, this is somehow baked into the js library (ask philip)
-- but on unix we need to explicitly include this (it's used by libjs).
add_func = function ( )
if OS ~= " windows " then
pkgconfig ( " nspr " )
end
end ,
} ,
2007-04-24 22:41:54 +02:00
openal = {
win_names = { " openal32 " } ,
unix_names = { " openal " } ,
2007-05-17 05:37:49 +02:00
osx_frameworks = { " OpenAL " } ,
2007-04-24 22:41:54 +02:00
dbg_suffix = " " ,
} ,
opengl = {
win_names = { " opengl32 " , " glu32 " , " gdi32 " } ,
unix_names = { " GL " , " GLU " , " X11 " } ,
2007-09-03 14:56:45 +02:00
osx_frameworks = { " OpenGL " } ,
2007-04-24 22:41:54 +02:00
dbg_suffix = " " ,
} ,
2009-07-18 21:55:27 +02:00
sdl = {
add_func = function ( )
add_extern_lib_paths ( " sdl " )
if OS ~= " windows " then
2009-08-08 11:56:50 +02:00
pkgconfig ( " sdl " )
2009-07-18 21:55:27 +02:00
end
end
} ,
2009-12-28 17:45:42 +01:00
spidermonkey =
options [ " with-spidermonkey-tip " ] and
{
add_func = function ( )
tinsert ( package.config [ " Debug " ] . includepaths , libraries_dir .. " spidermonkey-tip/include/debug " )
tinsert ( package.config [ " Testing " ] . includepaths , libraries_dir .. " spidermonkey-tip/include/debug " )
tinsert ( package.config [ " Release " ] . includepaths , libraries_dir .. " spidermonkey-tip/include/release " )
tinsert ( package.libpaths , libraries_dir .. " spidermonkey-tip/lib " )
2010-03-19 20:26:41 +01:00
tinsert ( package.config [ " Debug " ] . links , " mozjs-ps-debug " )
tinsert ( package.config [ " Testing " ] . links , " mozjs-ps-release " )
tinsert ( package.config [ " Release " ] . links , " mozjs-ps-release " )
2009-12-28 17:45:42 +01:00
end ,
}
or -- SpiderMonkey 1.6
{
2007-04-24 22:41:54 +02:00
win_names = { " js32 " } ,
unix_names = { " js " } ,
2009-12-28 17:45:42 +01:00
depends = { " nspr " } ,
defines = { " JS_THREADSAFE " } ,
2007-04-24 22:41:54 +02:00
} ,
2007-09-03 01:41:06 +02:00
valgrind = {
} ,
2007-04-24 22:41:54 +02:00
vorbis = {
win_names = { " vorbisfile " } ,
unix_names = { " vorbisfile " } ,
dbg_suffix = " _d " ,
} ,
wxwidgets = {
add_func = function ( )
if OS == " windows " then
tinsert ( package.includepaths , libraries_dir .. " wxwidgets/include/msvc " )
tinsert ( package.includepaths , libraries_dir .. " wxwidgets/include " )
tinsert ( package.libpaths , libraries_dir .. " wxwidgets/lib/vc_lib " )
2007-05-13 12:27:48 +02:00
tinsert ( package.config [ " Debug " ] . links , " wxmsw28ud_gl " )
tinsert ( package.config [ " Testing " ] . links , " wxmsw28ud_gl " )
tinsert ( package.config [ " Release " ] . links , " wxmsw28u_gl " )
2007-04-24 22:41:54 +02:00
else
2009-07-14 12:23:56 +02:00
tinsert ( package.buildoptions , " `wx-config --unicode=yes --cxxflags` " )
2009-08-06 21:41:18 +02:00
tinsert ( package.gnu_external , " `wx-config --unicode=yes --libs std,gl` " )
2007-04-24 22:41:54 +02:00
end
end ,
} ,
2009-07-18 21:55:27 +02:00
x11 = {
win_names = { } ,
unix_names = { " X11 " } ,
} ,
2007-04-24 22:41:54 +02:00
xerces = {
win_names = { " xerces-c_2 " } ,
unix_names = { " xerces-c " } ,
no_delayload = 1 ,
} ,
zlib = {
win_names = { " zlib1 " } ,
unix_names = { " z " } ,
} ,
}
local function add_delayload ( name , suffix , def )
if def [ " no_delayload " ] then
return
end
-- currently only supported by VC; nothing to do on other platforms.
if OS ~= " windows " then
return
end
-- no extra debug version; use same library in all configs
if suffix == " " then
tinsert ( package.linkoptions , " /DELAYLOAD: " .. name .. " .dll " )
-- extra debug version available; use in debug/testing config
else
local dbg_cmd = " /DELAYLOAD: " .. name .. suffix .. " .dll "
local cmd = " /DELAYLOAD: " .. name .. " .dll "
tinsert ( package.config [ " Debug " ] . linkoptions , dbg_cmd )
-- 'Testing' config uses 'Debug' DLLs
tinsert ( package.config [ " Testing " ] . linkoptions , dbg_cmd )
tinsert ( package.config [ " Release " ] . linkoptions , cmd )
end
end
local function add_extern_lib ( extern_lib , def )
2007-05-17 05:37:49 +02:00
add_extern_lib_paths ( extern_lib )
2007-04-24 22:41:54 +02:00
-- careful: make sure to only use *_names when on the correct platform.
local names = { }
if OS == " windows " then
if def.win_names then
names = def.win_names
end
2009-07-18 04:03:29 +02:00
elseif OS == " linux " and def.linux_names then
names = def.linux_names
elseif OS == " macosx " and def.osx_names then
names = def.osx_names
elseif def.unix_names then
names = def.unix_names
2007-04-24 22:41:54 +02:00
end
local suffix = " d "
-- library is overriding default suffix (typically "" to indicate there is none)
if def [ " dbg_suffix " ] then
suffix = def [ " dbg_suffix " ]
end
-- non-Windows doesn't have the distinction of debug vs. release libraries
-- (to be more specific, they do, but the two are binary compatible;
-- usually only one type - debug or release - is installed at a time).
if OS ~= " windows " then
suffix = " "
end
2009-12-28 17:45:42 +01:00
if def.defines then
tinsert ( package.defines , def.defines )
end
2007-05-17 05:37:49 +02:00
-- OS X "Frameworks" need to be added in a special way to the link
-- i.e. by linkoptions += "-framework ..."
if OS == " macosx " and def.osx_frameworks then
2009-07-21 19:38:27 +02:00
for i , name in pairs ( def.osx_frameworks ) do
2007-05-17 05:37:49 +02:00
tinsert ( package.linkoptions , " -framework " .. name )
end
else
2009-07-21 19:38:27 +02:00
for i , name in pairs ( names ) do
2007-05-17 05:37:49 +02:00
tinsert ( package.config [ " Debug " ] . links , name .. suffix )
-- 'Testing' config uses 'Debug' DLLs
tinsert ( package.config [ " Testing " ] . links , name .. suffix )
tinsert ( package.config [ " Release " ] . links , name )
add_delayload ( name , suffix , def )
end
2007-04-24 22:41:54 +02:00
end
end
-- add a set of external libraries to the package; takes care of
-- include / lib path and linking against the import library.
-- extern_libs: table of library names [string]
function package_add_extern_libs ( extern_libs )
2009-08-08 11:56:50 +02:00
local function add_with_deps ( libs , lib )
local def = extern_lib_defs [ lib ]
assert ( def , " external library " .. lib .. " not defined " )
tinsert ( libs , lib )
if def.depends then
for i , dep in pairs ( def.depends ) do
add_with_deps ( libs , dep )
end
end
end
local libs = { }
2009-07-21 19:38:27 +02:00
for i , extern_lib in pairs ( extern_libs ) do
2009-08-08 11:56:50 +02:00
add_with_deps ( libs , extern_lib )
end
for i , extern_lib in pairs ( libs ) do
2007-04-24 22:41:54 +02:00
local def = extern_lib_defs [ extern_lib ]
2009-08-08 11:56:50 +02:00
if def.add_func then
def.add_func ( )
2007-04-24 22:41:54 +02:00
else
add_extern_lib ( extern_lib , def )
end
end
end