Reputation: 66965
I have simple console application project for live video streaming using cross-platform libs on to some TCP server. I have it ported manually to Linux and Mac OS X from Windows. So now I have 3 projects using same code each of them created manually and tested. Now I am trying to create a premake lua projects creation file to automate process of updating project files.
I started creating a lua file
I have an array of lib links in my premake lua build file I have an array of lib links required for my project.
Some of them kind of repeat some of them do not (because for example there is "openal32" on Windows (even on Windows 7 64 bit version) and much simpler name "openal" on Linux and "OpenAL.framework" on Mac OS X (and its the only option on mac os to include openAL)
I have a linkdirs property set - one for all systems
libdirs {
"/opt/local/lib",
"/System/Libarary/Frameworks",
"/Library/Frameworks",
"/usr/lib",
"/usr/local/lib" }
That links to dirs will probably work for Mac OS X (because we use Mac Ports that installs by default into /opt/local/lib
) and Linux (where we mostly use app-get analogs that auto install all into usr/lib
, and sometimes into /usr/local/lib
). But on windows you never know where ffmpeg is or where is boost installed (probably each programmer has his own idea where to keep windows Libs and Headers...) so we need a simple thing from premake:
Action to add a user defined librarys directorys that will be included into libdirs
array and same thing for includedirs
array. It shall ba capable to add more than one directory.
How to enable such thing?
I tried to create an "option based system" like
newoption {
trigger = "libsPath",
value = "PATH",
description = "Choose a particular directory for general libs search"
}
if not _OPTIONS["libsPath"] then
_OPTIONS["libsPath"] = NULL
end
libdirs {
"/opt/local/lib",
"/System/Libarary/Frameworks",
"/Library/Frameworks",
"/usr/lib",
"/usr/local/lib",
_OPTIONS["libsPath"]
}
but it seems not to work on windows... what shall I do?
Upvotes: 1
Views: 2825
Reputation: 4276
You don't need this bit:
if not _OPTIONS["libsPath"] then
_OPTIONS["libsPath"] = NULL
end
It will already be nil (the equivalent of NULL in Lua) if it is unset. Otherwise, this looks good and works fine for me.
One possible improvement you might make: converting the argument to accept a delimited list of paths, so your users can provide more than one if necessary. So if you called your script like this, with semicolon separated paths:
C:\> premake4 /libsPath=C:\Code\Libs;C:\Code\MoreLibs vs2010
You would add it to you library search paths like this:
-- Split it up
libdirs { string.explode(_OPTIONS["libsPath"], ";") }
Untested, but should work. Hope that helps!
Upvotes: 4
Reputation: 45057
When you want the user to be able to specify include or library directories, one of the easiest methods is to use an environment variable. When your scripts run, they can look for environment variables named EXTRA_LIB_PATHS
and EXTRA_INCLUDE_PATHS
(or whatever you want to call them) and add the paths listed there into the pre-defined path lists you mentioned.
Windows, Linux, and OSX all have a notion of environment variables, but they don't use the exact same format. A list of directory paths in a Windows environment variable is typically delimited by semicolons, where Linux typically uses colons. You'll want to make sure that your code that parses the environment variables can detect the current platform and use the appropriate method to extract the data.
Another possibility is to pass in directory paths as command-line options to your premake script (using a syntax like premake.lua -L/path/to/lib -I/my/include/path -L/another/lib/path
, etc). The downside here is that the command line can get rather long, and some consoles may have a limit on the length of a CLI command. If you will be using more than a handful of extra paths, I would recommend using an environment variable over CLI arguments.
Upvotes: 0