Configure premake script directories and libraries depending on platform toolset - premake

I'm trying to convert my visual studio project files to use premake to generate solutions for different visual studio versions.
I would like to write configuration functions for each of the libraries so that it will set different include directory, library directory, and dlls depending on the platform toolset. I have tried using the configuration or filter command but this is not working and is including all the libraries and directories to my project instead.
A simplified example of what i'm trying to do is below.
function projectconfig()
filename "MyProj"
kind "SharedLib"
language "C++"
filter "action:vs2010"
links "lib_vc100"
..etc
filter "action:vs2012"
links "lib_vc110"
..etc
filter {} <--- This had to be added to fix the issue
end
How should I go about doing something like this?
Thanks!

if this is not working you could work around it by using
if _ACTION == "vs2010" then
end
but please consider filing a bug with this !

You can use the VS macros in premake:
libdirs "libs/$(PlatformToolset)"
links "foo"
Then in your source tree:
libs/
v110/
foo.lib
v120/
foo.lib
v140/
foo.lib

Related

How to use extensions

Could someone please explain how one uses the premake extensions. I added the eclipse extension in a directory under my premake installation. And in the premake script I added recuire "eclipse".
Running the script with premake5 eclipse, I get an error module "eclipse.lua" not found.
I added the path of the modules directory to my environment variables.
I'm using premake (premake5) on Windows 8.
Thanks
addons need to reside in a folder. You need to create a "eclipse" folder, then copy all the files in it, and the "eclipse" folder should be located where premake can load it (either next the executable or some other place handled through environment variables)
I got this working by adding the full path to the require statement.
require "C:/premake/eclipse/eclipse"
and running the command as premake5 eclipse
Note: This plugin does not generate project files that one can import into Eclipse.

How to prevent absolute paths in dynamic linker

I have a solution with various projects, one of which is the main executable, and the rest are libraries the executable depends on. Each one compiles and links fine. However, trying to start the executable gives weird results. Using ldd, I see that the executable is trying to find libraries like so:
../bin/debug/libBlahBlah.so => not found
However, for each project, I'm declaring "bin/debug" (which is the output directory for these libraries) as a libdirs entry, and linking against the library by adding "BlahBlah" as a link, where "BlahBlah" is the name of the project.
I'm not even sure how to accomplish this without premake. Any help is appreciated.
The original intention was to have the library sit next to the executable then set an RPATH that searched for the library next to executable. With the way it is now, it searches for that absolute path relative to the executable... I cannot figure out how to get it off.
I'm using premake5. I've tried to use the nightly and compiling myself. Upstream is currently not compiling however.
If you are using the latest alpha or source of Premake5, you can use the "RelativeLinks" flag to use -L/-l instead of relative paths to libraries:
project "MyProject"
flags "RelativeLinks"
You will still need to set up the rpath properly though; you can do that with buildoptions() and the appropriate command line flags for your compiler. Maybe (untested):
buildoptions "-Wl,-rpath=."
That should work in Premake 4 as well.

Qt executable naming

I'm hoping this is an easy question. I have setup an Ogre3D project in QtCreator 2.6.1 using MSVC2010. I have to setup a custom build step and I noticed that the letter 'd' is appended to the name of the compiled .exe (e.g. OrgeProgramd.exe, CoolGamed.exe)
This is not critical, I was just wondering why this happens. Is it normal? The target in the .pro file is correct. I tried building with Release and I get the same thing. Any ideas?
Look through your pro/pri files and find the line, similar to this: TARGET = $$join(TARGET,,,d). If you do - that would be the reason.

Qt How to make and install plugins?

I would like to use the Qt Quick Components for Desktop mentioned here: http://labs.qt.nokia.com/2011/03/10/qml-components-for-desktop/
The author gives the following installation-instructions:
Since all of this is developed as a plugin to Qt itself, all you need to get started is the Qt 4.7.2 SDK. Just check out the http://qt.gitorious.org/qt-components/desktop and do the equivalent of a qmake && make install on your system.
I cloned the repository, executed qmake, mingw32-make and mingw32-make install on it in the command-line.
A new folder was created which includes the files libstyleplugin.a and styleplugin.dll.
I just don't know what to do with them. The sample-qml-files (using the components I try to install here) show nothing in the QML-Viewer, which means they aren't isntalled correctly.
So what am I supposed to do? (btw. I'm on Windows).
Hedge, I've done that on Linux but I believe you will be able to do the same on Windows. You already built the plugin which is good. Cause it seems "make install" doesn't really work (lets not blame the trolls - its just an experimental project), you need to do that manually. Now you need to do the following:
Create "imports" directory inside the directory whether you installed Qt.
Create "Qt/labs" directory inside that "imports" directory so overall it looks like this: YOUR_QT_DIR/imports/Qt/labs.
Copy "components" directory from the director where you built the components to "YOUR_QT_DIR/imports/Qt/labs" so it looks like this: YOUR_QT_DIR/imports/Qt/labs/components.
Go to "examples" directory in the directory where you built the components. You will find Browser.qml, Gallery.qml and Panel.qml files there. Open say Gallery.qml in a text editor and replace the following two lines on the top:
import "../components"
import "../components/plugin"
with
import Qt.labs.components 1.0
save changes and run Gallery.qml in qmlviewer. You should be able to run it.
Also you could leave the import statements from Gallery.qml as they were but that would rely on the relative directory where you built the components and won't work anywhere else.
Hope that helps
On Windows my directory ended up being C:\QtSDK\Desktop\Qt\4.7.3\mingw.
Hope this helps!

Enabling JPEG support for QImage in py2exe-compiled Python scripts?

I'm trying to use a JPEG image in a QImage object from a Python script, with PyQt4.
The script itself works perfectly, the image loads and can be manipulated and rendered and all. However, when I try to "compile" this script with py2exe, everything works but the JPEG image. Replacing it with a PNG equivalent works, but since my program downloads images from the web, they won't always be in PNG format and I can't afford converting them all with another library.
I've discovered that JPEG image support for QImage, along with other image formats, is provided by some DLLs in the \qt\plugins\imageformats directory (they're called qjpeg4.dll and qjpeg4d.dll). I think I need to use them somehow in my executable, but I don't know how. I've tried simply copying them to my exe directory, no luck. I've tried, as indicated here, to include those files as data_files in the setup.py script, but no luck (it looks like all it does is copying these files to the exe's directory, so it changes nothing from copying them manually anyway).
I'm sure there's a handful of applications out there using PyQt with JPEG images, how do they do it? It seemed like a trivial task but I'm stuck on it now.
Also, I want my app to be cross-platform (why else would I be coding in Python?), I hope I won't run into such packaging trouble (it's not the only one) when packaging for OS X or Linux. Will I?
After hours of stumbling around with the same issue, I’d like to share the solution that worked for me on windows vista:
using python2.6
copy the following directory into your dist directory generated by py2exe:
C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats
I just dropped the imageformats directory directly into my dist directory, without any further modifications to qt.conf or anything like that. I haven’t tried it, but this may work for phonon as well.
I'll have to confess I never managed to get the py2exe + pyqt combination quite right (and, py2exe doesn't help at all with cross-platform packaging). PyInstaller seems to be much better -- the docs at http://www.pyinstaller.org/ are old, but the svn trunk is much more recent. Some docs are in slides given at the recent Pycon Italia Tre conference -- http://www.pycon.it/static/stuff/slides/distribuire-programmi-python-con-pyinstaller.pdf -- and, the slides are in English, and contain the current maintainer's email, so they should help! (And, let's all lobby the current maintainer to update the docs...!-)
Try adding a qt.conf file to your exe's directory, to tell qt where to find binaries and plugins.
Something like the following works for the simple case, where you just dump all dll's in the same dir as the exe:
[Paths]
Prefix = .
Plugins = .
Update: Then copy your plugins-contents (the imageformat/sqldriver directories etc) to the exe dir. I don't think you can load plugin dlls from the same directory as the exe. See Qt plugin doc for details on plugon subdirectories. (Or, leave out the 'plugins = .' and copy the plugins dir to the exe dir, so you have /plugins/imageloaders/qjpeg4.dll).
Etienne -- Thank you for the tip. After much reading and trial-and-error, I arrived at the same conclusion: use PIL to show jpegs in a py2app-generated app.
http://www.thetoryparty.com/wp/2009/08/27/pyqt-and-py2app-seriously-i-dont-know-what-to-do-with-you-when-youre-like-this/
What I guess is that the proposed solutions for py2exe/Windows don't necessarily apply to py2app/OSX.
I'm on OSX Leopard.
Let's suppose you have an application MyApp.app.
Put the libraries libqjpeg.dylib and libqgif.dylib in
MyApp.app/Contents/plugins/imageformats/
Put this in qt.conf in MyApp.app/Contents/resources/:
[Paths]
Prefix = .
Binaries = .
On my machine (Leopard) this works.
After trying all the above solutions in vain, I just ended up using PIL to load my images. Since I wanted to convert these images to a texture in an OpenGL Qt widget, the result was the same whether I load the image using Qt or PIL. Still, I'm baffled that such a basic thing as loading JPEGs is so complicated in a GUI library as well-known and widely used as Qt.
I had the exact same problem. Fixed it using this : http://mail.python.org/pipermail/python-list/2008-June/669374.html
Copy Qt plugins to the directory: $YOUR_DIST_PATH/PyQt4/plugins;
Copy qt.conf to your dist directory;
Edit qt.conf, change Prefix to ./PyQt4
For me, the problem was solved just copying the "qt.conf" for the directory of the executable.
You can find the "qt.conf" in ...\PythonXX\Lib\site-packages\PyQt4\qt.conf.
Thanks for help.
Everything above failed for me until I realized that I was bundling the .exe (that is, I had the option "bundle_files" : 2 in my setup.py. I changed it to bundle_files = 2, and now it works great.
The above solutions are fine. Specifically, I just added the following line in my setup.py:
data = [ ("imageformats", glob.glob("C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats*.dll")) ]
(in addition to other files, of course).
Then, the image loading dlls are in MY_EXE_DIR/imageformats
I didn't need a qt.conf to make this work, though I'm sure you could use it if you want to keep your directory tree less cluttered.
It is possible to use the JPEG plugin with a py2exe'd script, even using bundle_files. You need to arrange two things to get this to work properly:
Copy PyQt4/plugins/imageformats to the output directory of py2exe (default: dist)
You only have to copy the formats you actually need.
When use the bundle_files option you need to execlude the Qt dll files from the
zipfile using the --dll-excludes option for pyexe.
You still have to copy the Qt DLLs to the output directory some other way (such as
by using the data_files option).
on windows, suggested solutions work perfectly.
however, on osx can't make it work even with instructions here above.
question is: the libqjpeg.dylib and libqgif.dylib files are located in the /Developer/Applications/Qt/plugins/imageformats/ directory, and that if you have installed Qt itself, not just PyQt. these files do not work for me.
in PyQt distribution, i see the files libqjpeg.bundle and libqgif.bundle in /opt/local/libexec/qt4-mac/plugins/imageformats/, however these are not libraries, and btw i cannot open their contents either, even if they have the .bundle extension. using these files instead does not work either.
i am curious to know what have you done to make it work on osx. i have installed PyQt following this guide.
Thanks for your helpful answers for the question! I have encountered same problem as you did and no solutions could help. Hopefully, I was using VCS and found that old version of my app loaded JPEG images correctly and new versions stopped doing it. I caught this bug using PySide v1.2.2.
To enable libraries loading, I used the same solution as #Macke did (i.e. added and edited qt.conf).
My qt.conf was next:
[Paths]
Binaries = .
Plugins = qtplugins
C:\Python27\Lib\site-packages\PySide\plugins directory was copied to qtplugins directory, so I had next directories:
qtplugins\accessible
qtplugins\codecs
qtplugins\graphicssystems
qtplugins\iconengines
qtplugins\imageformats
I had next code:
class NotesCalendar(QtGui.QCalendarWidget):
note_icon = QtGui.QImage("res/16note.png")
Moving class variable NotesCalendar.note_icon to constructor solved the problem and Qt started loading its libraries correctly. Seems that class variable constructor interrupted some internal PySide stuff.
It works with no problems on Windows. Specifying correct qt.conf and copying plugins directory is enough to enable JPEG support in py2exe + PySide build. Of course, you must have no problems in your own code.
I hope this will save someone a day! ;)

Resources