Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Building JSFML

pdinklag edited this page Dec 28, 2012 · 4 revisions

This is a guideline to building JSFML (especially its native C++ part) from its source.

If you are having problems building JSFML, please discuss them in the How to build JSFML forum thread.

Ant targets

JSFML is built using Apache Ant and defines the following targets:

  • compile — Compiles the Java sources to out/classes.
  • headers — Generates JNI headers in include/JSFML/JNI. This is only needed if any native method signature was changed in the Java sources.
  • javadoc — Generates the Javadoc in the javadoc directory..
  • win32 — Compiles and links the C++ sources for Windows 32-bit. See below for details.
  • win64 — Compiles and links the C++ sources for Windows 64-bit. See below for details.
  • linux32 — Compiles and links the C++ sources for Linux 32-bit. See below for details.
  • linux64 — Compiles and links the C++ sources for Linux 64-bit. See below for details.
  • macosx — Compiles and links the C++ sources for Mac OS X (both 32- and 64-bit). See below for details.
  • jar — Generates the jsfml.jar file in out.
  • signjar — Signs the generated JAR file. If you know why you're going to do this, you will know how to go at it.
  • clean — Deletes the out and javadoc directories entirely.

Building the C++ sources

There are certain requirements that the building environment needs to fulfill in order for the C++ sources to be built correctly.

For all systems, you need to define the JAVA_HOME environment variable, which should point to a JDK on your system. To ensure maximum compatibility, a JDK 6 is recommended at the moment.

Building JSFML does not involve having to build SFML itself. Instead, JSFML provides the supported libraries and binaries in pre-compiled form and also keeps a matching copy of the SFML headers. All this is located in the sfml subdirectory. The advantage of this is that you don't need to bother compiling SFML. That would be a bad idea anyway, because a simple API change in SFML might break JSFML's compatibility to it.

Windows

To build on Windows (Ant targets win32 and win64), you will require the Windows SDK (latest possible, currently I recommend version 7) as well as the Microsoft Visual C++ compiler (2010 or later). Note that the compiler can be installed along with the Windows SDK, so you don't necessarily need the Microsoft Visual Studio.

The path of the Windows SDK and the MS Visual C++ compiler is retrieved automatically using the provided batch scripts. Given the weirdly high amount of possible registry keys VC++ can be located with, this might not always work. If your VC++ does not get found by the batch, please report that problem with the necessary info for me, or make a pull request that fixes it.

Note that end users will have to install the Microsoft Visual C++ 2010 Redistributable Package in order to run JSFML.

Linux

To build on Linux, you require g++, that's about it.

Mac OS X

For Mac OS X, the same requirements as for Linux apply. However, you need the "Java for Developers" tools.

To set the JAVA_HOME variable, use this command:

export JAVA_HOME=`/usr/libexec/java_home`

For running a JSFML application, you must pass -XstartOnFirstThread to your application if it is going to open a window. Unfortunately, there is no way to avoid this and your application will crash if this parameter was not provided. It is Apple who is to blame for this...

Please follow the guide below (kindly provided by mantognini) in case you wish to compile SFML and/or libsndfile yourself.

If you want to use your custom version of SFML with JSFML you need to build SFML the usual way. However, when everything is built, you have to run some shell commands to make everything work as expected.

For each custom SFML module rename the libsfml-MODULE.2.0.dylib into libsfml-MODULE.dylib and do :

install_name_tool -id libsfml-MODULE.dylib libsfml-MODULE.dylib
-change @executable_path/../Frameworks/libsfml-MODULE_REFERENCE_X.2.dylib @loader_path/libsfml-MODULE_REFERENCE_X.dylib
[-change @executable_path/../Frameworks/libsfml-MODULE_REFERENCE_Y.2.dylib @loader_path/libsfml-MODULE_REFERENCE_Y.dylib \ ] ... libsfml-MODULE.dylib

e.g. if you want to use your custom graphics module you need to run :
```shell

install_name_tool -id libsfml-graphics.dylib
-change @executable_path/../Frameworks/libsfml-window.2.dylib @loader_path/libsfml-window.dylib
-change @executable_path/../Frameworks/libsfml-system.2.dylib @loader_path/libsfml-system.dylib
libsfml-graphics.dylib

For the audio module you have to run this command in addition to the previous ones :
```shell

install_name_tool -change @executable_path/../Frameworks/sndfile.framework/Versions/A/sndfile @loader_path/libsndfile.dylib
libsfml-audio.dylib

If you want to use your custom sndfile library you must have it as a dylib and run :
```shell

install_name_tool -id libsndfile.dylib libsndfile.dylib

You can use `sfml/bin/macosx_universal/updateBinaires.sh` script to do most of this job automatically. See comment at the beginning of the script.
Clone this wiki locally