gettingstarted.rst 6.4 KB

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