gettingstarted.txt revision 4139
4139N/A***************
4139N/AGetting Started
4139N/A***************
4139N/A
4139N/A.. highlight:: c
4139N/A
4139N/ACompiling and Installing Jansson
4139N/A================================
4139N/A
4139N/AThe Jansson source is available at
4139N/Ahttp://www.digip.org/jansson/releases/.
4139N/A
4139N/AUnix-like systems (including MinGW)
4139N/A-----------------------------------
4139N/A
4139N/AUnpack the source tarball and change to the source directory:
4139N/A
4139N/A.. parsed-literal::
4139N/A
4139N/A bunzip2 -c jansson-|release|.tar.bz2 | tar xf -
4139N/A cd jansson-|release|
4139N/A
4139N/AThe source uses GNU Autotools (autoconf_, automake_, libtool_), so
4139N/Acompiling and installing is extremely simple::
4139N/A
4139N/A ./configure
4139N/A make
4139N/A make check
4139N/A make install
4139N/A
4139N/ATo change the destination directory (``/usr/local`` by default), use
4139N/Athe ``--prefix=DIR`` argument to ``./configure``. See ``./configure
4139N/A--help`` for the list of all possible installation options. (There are
4139N/Ano options to customize the resulting Jansson binary.)
4139N/A
4139N/AThe command ``make check`` runs the test suite distributed with
4139N/AJansson. This step is not strictly necessary, but it may find possible
4139N/Aproblems that Jansson has on your platform. If any problems are found,
4139N/Aplease report them.
4139N/A
4139N/AIf you obtained the source from a Git repository (or any other source
4139N/Acontrol system), there's no ``./configure`` script as it's not kept in
4139N/Aversion control. To create the script, the build system needs to be
4139N/Abootstrapped. There are many ways to do this, but the easiest one is
4139N/Ato use ``autoreconf``::
4139N/A
4139N/A autoreconf -vi
4139N/A
4139N/AThis command creates the ``./configure`` script, which can then be
4139N/Aused as described above.
4139N/A
4139N/A.. _autoconf: http://www.gnu.org/software/autoconf/
4139N/A.. _automake: http://www.gnu.org/software/automake/
4139N/A.. _libtool: http://www.gnu.org/software/libtool/
4139N/A
4139N/A
4139N/A.. _build-cmake:
4139N/A
4139N/ACMake (various platforms, including Windows)
4139N/A--------------------------------------------
4139N/A
4139N/AJansson can be built using CMake_. Create a build directory for an
4139N/Aout-of-tree build, change to that directory, and run ``cmake`` (or ``ccmake``,
4139N/A``cmake-gui``, or similar) to configure the project.
4139N/A
4139N/ASee the examples below for more detailed information.
4139N/A
4139N/A.. note:: In the below examples ``..`` is used as an argument for ``cmake``.
4139N/A This is simply the path to the jansson project root directory.
4139N/A In the example it is assumed you've created a sub-directory ``build``
4139N/A and are using that. You could use any path you want.
4139N/A
4139N/A.. _build-cmake-unix:
4139N/A
4139N/AUnix (Make files)
4139N/A^^^^^^^^^^^^^^^^^
4139N/AGenerating make files on unix:
4139N/A
4139N/A.. parsed-literal::
4139N/A
4139N/A bunzip2 -c jansson-|release|.tar.bz2 | tar xf -
4139N/A cd jansson-|release|
4139N/A
4139N/A mkdir build
4139N/A cd build
4139N/A cmake .. # or `ccmake ..` for a GUI.
4139N/A
4139N/AThen to build::
4139N/A
4139N/A make
4139N/A make check
4139N/A make install
4139N/A
4139N/AWindows (Visual Studio)
4139N/A^^^^^^^^^^^^^^^^^^^^^^^
4139N/ACreating Visual Studio project files from the command line:
4139N/A
4139N/A.. parsed-literal::
4139N/A
4139N/A <unpack>
4139N/A cd jansson-|release|
4139N/A
4139N/A md build
4139N/A cd build
4139N/A cmake -G "Visual Studio 10" ..
4139N/A
4139N/AYou will now have a *Visual Studio Solution* in your build directory.
4139N/ATo run the unit tests build the ``RUN_TESTS`` project.
4139N/A
4139N/AIf you prefer a GUI the ``cmake`` line in the above example can
4139N/Abe replaced with::
4139N/A
4139N/A cmake-gui ..
4139N/A
4139N/AFor command line help (including a list of available generators)
4139N/Afor CMake_ simply run::
4139N/A
4139N/A cmake
4139N/A
4139N/ATo list available CMake_ settings (and what they are currently set to)
4139N/Afor the project, run::
4139N/A
4139N/A cmake -LH ..
4139N/A
4139N/AMac OSX (Xcode)
4139N/A^^^^^^^^^^^^^^^
4139N/AIf you prefer using Xcode instead of make files on OSX,
4139N/Ado the following. (Use the same steps as
4139N/Afor :ref:`Unix <build-cmake-unix>`)::
4139N/A
4139N/A ...
4139N/A cmake -G "Xcode" ..
4139N/A
4139N/AAdditional CMake settings
4139N/A^^^^^^^^^^^^^^^^^^^^^^^^^
4139N/A
4139N/AShared library
4139N/A""""""""""""""
4139N/ABy default the CMake_ project will generate build files for building the
4139N/Astatic library. To build the shared version use::
4139N/A
4139N/A ...
4139N/A cmake -DJANSSON_BUILD_SHARED_LIBS=1 ..
4139N/A
4139N/AChanging install directory (same as autoconf --prefix)
4139N/A""""""""""""""""""""""""""""""""""""""""""""""""""""""
4139N/AJust as with the autoconf_ project you can change the destination directory
4139N/Afor ``make install``. The equivalent for autoconfs ``./configure --prefix``
4139N/Ain CMake_ is::
4139N/A
4139N/A ...
4139N/A cmake -DCMAKE_INSTALL_PREFIX:PATH=/some/other/path ..
4139N/A make install
4139N/A
4139N/A.. _CMake: http://www.cmake.org
4139N/A
4139N/A
4139N/AAndroid
4139N/A-------
4139N/A
4139N/AJansson can be built for Android platforms. Android.mk is in the
4139N/Asource root directory. The configuration header file is located in the
4139N/A``android`` directory in the source distribution.
4139N/A
4139N/A
4139N/AOther Systems
4139N/A-------------
4139N/A
4139N/AOn non Unix-like systems, you may be unable to run the ``./configure``
4139N/Ascript. In this case, follow these steps. All the files mentioned can
4139N/Abe found in the ``src/`` directory.
4139N/A
4139N/A1. Create ``jansson_config.h`` (which has some platform-specific
4139N/A parameters that are normally filled in by the ``./configure``
4139N/A script). Edit ``jansson_config.h.in``, replacing all ``@variable@``
4139N/A placeholders, and rename the file to ``jansson_config.h``.
4139N/A
4139N/A2. Make ``jansson.h`` and ``jansson_config.h`` available to the
4139N/A compiler, so that they can be found when compiling programs that
4139N/A use Jansson.
4139N/A
4139N/A3. Compile all the ``.c`` files (in the ``src/`` directory) into a
4139N/A library file. Make the library available to the compiler, as in
4139N/A step 2.
4139N/A
4139N/A
4139N/ABuilding the Documentation
4139N/A--------------------------
4139N/A
4139N/A(This subsection describes how to build the HTML documentation you are
4139N/Acurrently reading, so it can be safely skipped.)
4139N/A
4139N/ADocumentation is in the ``doc/`` subdirectory. It's written in
4139N/AreStructuredText_ with Sphinx_ annotations. To generate the HTML
4139N/Adocumentation, invoke::
4139N/A
4139N/A make html
4139N/A
4139N/Aand point your browser to ``doc/_build/html/index.html``. Sphinx_ 1.0
4139N/Aor newer is required to generate the documentation.
4139N/A
4139N/A.. _reStructuredText: http://docutils.sourceforge.net/rst.html
4139N/A.. _Sphinx: http://sphinx.pocoo.org/
4139N/A
4139N/A
4139N/ACompiling Programs that Use Jansson
4139N/A===================================
4139N/A
4139N/AJansson involves one C header file, :file:`jansson.h`, so it's enough
4139N/Ato put the line
4139N/A
4139N/A::
4139N/A
4139N/A #include <jansson.h>
4139N/A
4139N/Ain the beginning of every source file that uses Jansson.
4139N/A
4139N/AThere's also just one library to link with, ``libjansson``. Compile and
4139N/Alink the program as follows::
4139N/A
4139N/A cc -I /usr/include/jansson -o prog prog.c -ljansson
4139N/A
4139N/AStarting from version 1.2, there's also support for pkg-config_::
4139N/A
4139N/A cc -o prog prog.c `pkg-config --cflags --libs jansson`
4139N/A
4139N/A.. _pkg-config: http://pkg-config.freedesktop.org/