WARNING

THIS IS A WORK IN PROGRESS. Nothing is included in the main tree yet.

JSBSIM

JSBSIM is an open source flight dynamics model (FDM) written in C++.

It is free software distributed according to the terms of the GPL 3.0.

CMake in JSBSIM

JSBSIM use autotools under unices and visual project under Windows. The maintenance of both system can be made easier thanks to CMake.

Since initial writting of this page (december 2012), CMake support have been introduced in JSBSim. The patches previously presented on this page are now obsolete.

Plugins in JSBSIM

JSBSIM doesn't allow (yet) to write custom code that could be dynamically loaded at runtime. For instance, i would like to write my own output model without recompiling JSBSIM executable. Moreover, it could allow the projects that use JSBSIM (like flighgear) to maintain their interface easier (or at least outside of the jsbsim sources).

This is an experimental feature which is currently submitted for inclusion in JSBSIM. Comments for improvement are welcome.

This work is mainly developed and tested under Linux, but some basic tests have been done under Windows (MinGW).

For licencing problems, we can refer to the GPL FAQ.

Current status

The following table summarize the supported features.

Feature Autotools options(1) CMake Options(2) Linux Mac OSX Windows
GCC GCC Mingw MSVC Cygwin
default options (legacy static code) Yes Yes Yes Yes Yes
Shared JSBSim library --enable-libraries -DBUILD_SHARED_LIBS=TRUE Yes Yes Yes No No
Plugins feature Not supported -DJSBSIM_ENABLE_PLUGINS=TRUE Yes Yes(3) Yes(3) No(4) No(4)

(1) : see build with autotools.
(2) : see build with cmake.
(3) : only works with shared JSBSim.
(4) : will probably work when the plugins with static lib will work.

Prerequisite

Get CMake

Under Windows, you can get cmake from here. Under Linux, a package should exists for your distribution. The tests have been done with cmake >= 2.8.8.

Get a tool chain

Under Windows, we recommend to use MINGW compiler to try the plugin feature. However, you could also try alternative solutions.

Under Linux, you should already have a toolchain installed (tested with GCC, no clang).

Get the JSBSIM source code

You can get my branch with plugin feature on gitorious.

git clone https://gitorious.org/jsbsim/polch-jsbsim.git jsbsim
cd jsbsim

Build JSBSim

Build with autotools

The legacy JSBSIM build system is based on autotools. Only building in source tree is supported (TBC). Moreover, the plugin feature isn't supported for this configuration system yet.

cd jsbsim
./autogen.sh --enable-libraries
make
make install DESTDIR=${PWD}/_install

You are ready to run sample code.

Build with cmake

We have 3 build options :

The usage of cmake consist in :

The following examples use the CLI interface, but cmake also provide a GUI interface. One example of usage will be given.

The ".." (double dot) means parent directory, it shouldn't be omitted.

Linux

Run the following commands :

mkdir build_linux
cd build_linux 
cmake -DBUILD_SHARED_LIBS=TRUE -DJSBSIM_ENABLE_PLUGINS=TRUE ..
make
make check-local
make install DESTDIR=${PWD}/_install

To uninstall you can call :

xargs rm < install_manifest.txt

Build the customIO plugin example, from the top of the JSBSim source directory :

make -C exemples/plugins JSBSIM_PREFIX=${PWD}/_install/usr/local

You are ready to run sample code.

Mac OSX

See Linux, that is the same procedure.

You are ready to run sample code.

Windows MinGW

Tested with the MinGW bundled in Code::Blocks 13.12.

mkdir build_mingw
cd build_mingw
"c:\Program Files\CodeBlocks\MinGW\mingwvars.bat"
cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=TRUE -DJSBSIM_ENABLE_PLUGINS=TRUE -DCMAKE_INSTALL_PREFIX="c:/JSBSim" ..
mingw32-make
mingw32-make install DESTDIR=%CD%\_install

Instead of cmake -G "MinGW Makefiles" .., you can call cmake -G "CodeBlocks - MinGW Makefiles" ... It will generate a .cbp project file that can be opened in Code::Blocks.

Build the customIO plugin example, from the top of the JSBSim source directory :

mingw32-make -C exemples/plugins JSBSIM_PREFIX=%CD%\_install\JSBSim RM=del MOD_SUFFIX=.dll

You are ready to run sample code.

Cygwin

WARNING : options "-DBUILD_SHARED_LIBS=TRUE -DJSBSIM_ENABLE_PLUGINS=TRUE" won't work.

Run the following commands :

mkdir build_cygwin
cd build_cygwin
cmake -G "Unix Makefiles"..
make
make install DESTDIR=${PWD}/_install

To uninstall you can call :

xargs rm < install_manifest.txt

You are ready to run sample code.

Windows MSVC

WARNING : options "-DBUILD_SHARED_LIBS=TRUE -DJSBSIM_ENABLE_PLUGINS=TRUE" not tested.

Tested with MSVC 2012 express.

mkdir build_msvc_nmake
cd build_msvc_nmake
"c:\Program Files\Microsoft Visual Studio 11.0\VC\bin\vcvars32.bat"
cmake -G "NMake Makefiles" ..
nmake
nmake install DESTDIR=%CD%\_install

You are ready to run sample code.

Windows MSVC command line interface

WARNING : options "-DBUILD_SHARED_LIBS=TRUE -DJSBSIM_ENABLE_PLUGINS=TRUE" not tested.

Tested with MSVC 2010 express SP1.

mkdir build_msvc_10
cd build_msvc_10
"c:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
cmake -G "Visual Studio 10" ..
msbuild jsbsim.sln

Tested with MSVC 2012 express.

mkdir build_msvc_11
cd build_msvc_11
"c:\Program Files\Microsoft Visual Studio 11.0\VC\bin\vcvars32.bat"
cmake -G "Visual Studio 11" ..
msbuild jsbsim.sln

You can also open jsbsim.sln with visual studio IDE.

Note : I'm not able to launch the installation from CLI. The code hereunder doesn't work. But you can build the INSTALL project in the Visual Studio IDE and it works (if you have admin privileges).

msbuild /target:INSTALL jsbsim.sln
cmake --build . --target install --config Debug

Windows MSVC graphical user interface

  1. Launch cmake-gui
    Select the source dir.
    Select the build dir.
    Click "configure".
  2. Confirm the build directory creation.
  3. Select your generator.
    Don't change the "Use default native compilers".
  4. When the configuration is done, you can click "Generate".
  5. In the build directory, you can double click on "jsbsim.sln" to open Visual Studio.

Run JSBSim

You can run the sample code from the build tree.

You can set the JSBSIM_DEBUG env var to have more traces.

Run under Linux

Set the path to the shared library, LD_LIBRARY_PATH, environment variable, for the JSBSIm library and for the plugin library, from the top of the JSBSim source directory :

export LD_LIBRARY_PATH=${PWD}/exemples/plugins:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${PWD}/_install/usr/local/lib:$LD_LIBRARY_PATH
export PATH=${PWD}/_install/usr/local/bin:$PATH

Run the JSBSim program :

JSBSim --root=${PWD}/exemples/plugins --aircraft=ball --initfile=reset00_v2 --end-time=100

Run under Mac OSX

Set the path to the shared library, DYLD_LIBRARY_PATH, environment variable, for the JSBSIm library and for the plugin library, from the top of the JSBSim source directory :

export DYLD_LIBRARY_PATH=${PWD}/exemples/plugins:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=${PWD}/_install/usr/local/lib:$DYLD_LIBRARY_PATH
export PATH=${PWD}/_install/usr/local/bin:$PATH

Run the JSBSim program :

JSBSim --root=${PWD}/exemples/plugins --aircraft=ball --initfile=reset00_v2 --end-time=100

Run under Windows

Set the path to the shared library, PATH, environment variable, for the JSBSIm library and for the plugin library, from the top of the JSBSim source directory :

set PATH=%CD%\exemples\plugins;%PATH%
set PATH=%CD%\_install\JSBSim\lib;%PATH%
set PATH=%CD%\_install\JSBSim\bin;%PATH%

Run the JSBSim program :

JSBSim --root=${PWD}/exemples/plugins --aircraft=ball --initfile=reset00_v2 --end-time=100

Run under Cygwin

Set the path to the shared library, PATH, environment variable, for the JSBSIm library and for the plugin library, from the top of the JSBSim source directory :

export LD_LIBRARY_PATH=${PWD}/exemples/plugins:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${PWD}/_install/Program\ Files/jsbsim/lib:$LD_LIBRARY_PATH
export PATH=${PWD}/_install/Program\ Files/jsbsim/bin:$PATH

Run the JSBSim program :

JSBSim --root=${PWD}/exemples/plugins --aircraft=ball --initfile=reset00_v2 --end-time=100

Build your own modules

Naming convention

Plugins (or modules) can have any name since the library containing the IO models will be named in the XML file with the library attribute.

Depending on the platform, modules have specific naming convention (they can be prefixed with lib under unices, they can end with so, dll, ...). You will only provide the common part of the name of the library.

A library can contains one or more IO models. The only interface that JSBSim needs is a factory for your model with the following signature :

extern "C"
JSBSim::FGModel * new_Namespace_Model(JSBSim::FGFDMExec* fdmex);

For instance, the following code will look for a module named "CustomIO".

<output library="CustomIO" type="CustomOutput" name="stdout" rate="1">
    <position> ON </position>
</output>
<input library="CustomIO" type="CustomInput" name="stdin" rate="1"/>

This module should provide an outpout model factory :

JSBSim::FGModel * new_CustomIO_CustomOutput(JSBSim::FGFDMExec* fdmex)

and an input model factory :

JSBSim::FGModel * new_CustomIO_CustomInput(JSBSim::FGFDMExec* fdmex)

Sample code

Sample code is available in the jsbsim source tree (examples/plugins). The compilion is done thanks to a simple makefile.

Plugins feature without external modules

We sometimes use JSBSim as an extarnal library linked to our programs. In such a case, we could avoid making separate shared modules and simply provides our custom IO models in our main code base. JSBSim will look for the model factory in the current executable before searching in external libraries.

Points to be discussed

Build, run and test the Bertrand's code

This is a note for personal use in order to test the Bertrand's code.

Build the code :

cd jsbsim
./autogen.sh --enable-libraries
make
make install DESTDIR=${PWD}/_install

Run the plugin test code :

export LD_LIBRARY_PATH=${PWD}/_install/usr/local/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${PWD}/_install/usr/local/lib/JSBSim/:$LD_LIBRARY_PATH
./src/.libs/JSBSim --root=${PWD} --aircraft=ball --initfile=reset00 --end-time=100