gettingstarted.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ***************
  2. Getting Started
  3. ***************
  4. .. highlight:: c
  5. Compiling and Installing Jansson
  6. ================================
  7. The Jansson source is available at
  8. http://www.digip.org/jansson/releases/.
  9. Unix-like systems (including MinGW)
  10. -----------------------------------
  11. Unpack the source tarball and change to the source directory:
  12. .. parsed-literal::
  13. bunzip2 -c jansson-|release|.tar.bz2 | tar xf -
  14. cd jansson-|release|
  15. The source uses GNU Autotools (autoconf_, automake_, libtool_), so
  16. compiling and installing is extremely simple::
  17. ./configure
  18. make
  19. make check
  20. make install
  21. To change the destination directory (``/usr/local`` by default), use
  22. the ``--prefix=DIR`` argument to ``./configure``. See ``./configure
  23. --help`` for the list of all possible configuration options.
  24. The command ``make check`` runs the test suite distributed with
  25. Jansson. This step is not strictly necessary, but it may find possible
  26. problems that Jansson has on your platform. If any problems are found,
  27. please report them.
  28. If you obtained the source from a Git repository (or any other source
  29. control system), there's no ``./configure`` script as it's not kept in
  30. version control. To create the script, the build system needs to be
  31. bootstrapped. There are many ways to do this, but the easiest one is
  32. to use ``autoreconf``::
  33. autoreconf -fi
  34. This command creates the ``./configure`` script, which can then be
  35. used as described above.
  36. .. _autoconf: http://www.gnu.org/software/autoconf/
  37. .. _automake: http://www.gnu.org/software/automake/
  38. .. _libtool: http://www.gnu.org/software/libtool/
  39. .. _build-cmake:
  40. CMake (various platforms, including Windows)
  41. --------------------------------------------
  42. Jansson can be built using CMake_. Create a build directory for an
  43. out-of-tree build, change to that directory, and run ``cmake`` (or ``ccmake``,
  44. ``cmake-gui``, or similar) to configure the project.
  45. See the examples below for more detailed information.
  46. .. note:: In the below examples ``..`` is used as an argument for ``cmake``.
  47. This is simply the path to the jansson project root directory.
  48. In the example it is assumed you've created a sub-directory ``build``
  49. and are using that. You could use any path you want.
  50. .. _build-cmake-unix:
  51. Unix (Make files)
  52. ^^^^^^^^^^^^^^^^^
  53. Generating make files on unix:
  54. .. parsed-literal::
  55. bunzip2 -c jansson-|release|.tar.bz2 | tar xf -
  56. cd jansson-|release|
  57. mkdir build
  58. cd build
  59. cmake .. # or ccmake .. for a GUI.
  60. Then to build::
  61. make
  62. make check
  63. make install
  64. Windows (Visual Studio)
  65. ^^^^^^^^^^^^^^^^^^^^^^^
  66. Creating Visual Studio project files from the command line:
  67. .. parsed-literal::
  68. <unpack>
  69. cd jansson-|release|
  70. md build
  71. cd build
  72. cmake -G "Visual Studio 10" ..
  73. You will now have a *Visual Studio Solution* in your build directory.
  74. To run the unit tests build the ``RUN_TESTS`` project.
  75. If you prefer a GUI the ``cmake`` line in the above example can
  76. be replaced with::
  77. cmake-gui ..
  78. For command line help (including a list of available generators)
  79. for CMake_ simply run::
  80. cmake
  81. To list available CMake_ settings (and what they are currently set to)
  82. for the project, run::
  83. cmake -LH ..
  84. Mac OSX (Xcode)
  85. ^^^^^^^^^^^^^^^
  86. If you prefer using Xcode instead of make files on OSX,
  87. do the following. (Use the same steps as
  88. for :ref:`Unix <build-cmake-unix>`)::
  89. ...
  90. cmake -G "Xcode" ..
  91. Additional CMake settings
  92. ^^^^^^^^^^^^^^^^^^^^^^^^^
  93. Shared library
  94. """"""""""""""
  95. By default the CMake_ project will generate build files for building the
  96. static library. To build the shared version use::
  97. ...
  98. cmake -DJANSSON_BUILD_SHARED_LIBS=1 ..
  99. Changing install directory (same as autoconf --prefix)
  100. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  101. Just as with the autoconf_ project you can change the destination directory
  102. for ``make install``. The equivalent for autoconfs ``./configure --prefix``
  103. in CMake_ is::
  104. ...
  105. cmake -DCMAKE_INSTALL_PREFIX:PATH=/some/other/path ..
  106. make install
  107. .. _CMake: http://www.cmake.org
  108. Android
  109. -------
  110. Jansson can be built for Android platforms. Android.mk is in the
  111. source root directory. The configuration header file is located in the
  112. ``android`` directory in the source distribution.
  113. Other Systems
  114. -------------
  115. On non Unix-like systems, you may be unable to run the ``./configure``
  116. script. In this case, follow these steps. All the files mentioned can
  117. be found in the ``src/`` directory.
  118. 1. Create ``jansson_config.h`` (which has some platform-specific
  119. parameters that are normally filled in by the ``./configure``
  120. script). Edit ``jansson_config.h.in``, replacing all ``@variable@``
  121. placeholders, and rename the file to ``jansson_config.h``.
  122. 2. Make ``jansson.h`` and ``jansson_config.h`` available to the
  123. compiler, so that they can be found when compiling programs that
  124. use Jansson.
  125. 3. Compile all the ``.c`` files (in the ``src/`` directory) into a
  126. library file. Make the library available to the compiler, as in
  127. step 2.
  128. Building the Documentation
  129. --------------------------
  130. (This subsection describes how to build the HTML documentation you are
  131. currently reading, so it can be safely skipped.)
  132. Documentation is in the ``doc/`` subdirectory. It's written in
  133. reStructuredText_ with Sphinx_ annotations. To generate the HTML
  134. documentation, invoke::
  135. make html
  136. and point your browser to ``doc/_build/html/index.html``. Sphinx_ 1.0
  137. or newer is required to generate the documentation.
  138. .. _reStructuredText: http://docutils.sourceforge.net/rst.html
  139. .. _Sphinx: http://sphinx.pocoo.org/
  140. Compiling Programs that Use Jansson
  141. ===================================
  142. Jansson involves one C header file, :file:`jansson.h`, so it's enough
  143. to put the line
  144. ::
  145. #include <jansson.h>
  146. in the beginning of every source file that uses Jansson.
  147. There's also just one library to link with, ``libjansson``. Compile and
  148. link the program as follows::
  149. cc -o prog prog.c -ljansson
  150. Starting from version 1.2, there's also support for pkg-config_:
  151. .. code-block:: shell
  152. cc -o prog prog.c `pkg-config --cflags --libs jansson`
  153. .. _pkg-config: http://pkg-config.freedesktop.org/