building.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. .. _building:
  2. Building open62541
  3. ==================
  4. Building the Examples
  5. ---------------------
  6. Using the GCC compiler, the following calls build the examples on Linux.
  7. .. code-block:: bash
  8. cp /path-to/open62541.* . # copy single-file distribution to the local directory
  9. cp /path-to/examples/server_variable.c . # copy the example server
  10. gcc -std=c99 open62541.c server_variable.c -o server
  11. Building the Library
  12. --------------------
  13. Building with CMake on Ubuntu or Debian
  14. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  15. .. code-block:: bash
  16. sudo apt-get install git build-essential gcc pkg-config cmake python python-six
  17. # enable additional features
  18. sudo apt-get install cmake-curses-gui # for the ccmake graphical interface
  19. sudo apt-get install libmbedtls-dev # for encryption support
  20. sudo apt-get install liburcu-dev # for multithreading
  21. sudo apt-get install check # for unit tests
  22. sudo apt-get install python-sphinx graphviz # for documentation generation
  23. sudo apt-get install python-sphinx-rtd-theme # documentation style
  24. cd open62541
  25. mkdir build
  26. cd build
  27. cmake ..
  28. make
  29. # select additional features
  30. ccmake ..
  31. make
  32. # build documentation
  33. make doc # html documentation
  34. make doc_pdf # pdf documentation (requires LaTeX)
  35. Building with CMake on Windows
  36. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  37. Here we explain the build process for Visual Studio (2013 or newer). To build
  38. with MinGW, just replace the compiler selection in the call to CMake.
  39. - Download and install
  40. - Python 2.7.x (Python 3.x works as well): https://python.org/downloads
  41. - Install python-six with the pip package manager (``pip install six``)
  42. - CMake: http://www.cmake.org/cmake/resources/software.html
  43. - Microsoft Visual Studio: https://www.visualstudio.com/products/visual-studio-community-vs
  44. - Download the open62541 sources (using git or as a zipfile from github)
  45. - Open a command shell (cmd) and run
  46. .. code-block:: bat
  47. cd <path-to>\open62541
  48. mkdir build
  49. cd build
  50. <path-to>\cmake.exe .. -G "Visual Studio 14 2015"
  51. :: You can use use cmake-gui for a graphical user-interface to select features
  52. - Then open :file:`build\open62541.sln` in Visual Studio 2015 and build as usual
  53. Building on OS X
  54. ^^^^^^^^^^^^^^^^
  55. - Download and install
  56. - Xcode: https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
  57. - Homebrew: http://brew.sh/
  58. - Pip (a package manager for python, may be preinstalled): ``sudo easy_install pip``
  59. - Run the following in a shell
  60. .. code-block:: bash
  61. brew install cmake
  62. pip install six # python 2/3 compatibility workarounds
  63. pip install sphinx # for documentation generation
  64. pip install sphinx_rtd_theme # documentation style
  65. brew install graphviz # for graphics in the documentation
  66. brew install check # for unit tests
  67. brew install userspace-rcu # for multi-threading support
  68. Follow Ubuntu instructions without the ``apt-get`` commands as these are taken care of by the above packages.
  69. Building on OpenBSD
  70. ^^^^^^^^^^^^^^^^^^^
  71. The procedure below works on OpenBSD 5.8 with gcc version 4.8.4, cmake version 3.2.3 and Python version 2.7.10.
  72. - Install a recent gcc, python and cmake:
  73. .. code-block:: bash
  74. pkg_add gcc python cmake
  75. - Tell the system to actually use the recent gcc (it gets installed as egcc on OpenBSD):
  76. .. code-block:: bash
  77. export CC=egcc CXX=eg++
  78. - Now procede as described for Ubuntu/Debian:
  79. .. code-block:: bash
  80. cd open62541
  81. mkdir build
  82. cd build
  83. cmake ..
  84. make
  85. Build Options
  86. -------------
  87. The open62541 project uses CMake to manage the build options, for code
  88. generation and to generate build projects for the different systems and IDEs.
  89. The tools *ccmake* or *cmake-gui* can be used to graphically set the build
  90. options.
  91. Most options can be changed manually in :file:`ua_config.h` (:file:`open62541.h`
  92. for the single-file release) after the code generation. But usually there is no
  93. need to adjust them.
  94. Build Type and Logging
  95. ^^^^^^^^^^^^^^^^^^^^^^
  96. **CMAKE_BUILD_TYPE**
  97. - ``RelWithDebInfo`` -O2 optimization with debug symbols
  98. - ``Release`` -O2 optimization without debug symbols
  99. - ``Debug`` -O0 optimization with debug symbols
  100. - ``MinSizeRel`` -Os optimization without debug symbols
  101. **UA_LOGLEVEL**
  102. The SDK logs events of the level defined in ``UA_LOGLEVEL`` and above only.
  103. The logging event levels are as follows:
  104. - 600: Fatal
  105. - 500: Error
  106. - 400: Warning
  107. - 300: Info
  108. - 200: Debug
  109. - 100: Trace
  110. UA_BUILD_* group
  111. ^^^^^^^^^^^^^^^^
  112. By default only the shared object libopen62541.so or the library open62541.dll
  113. and open62541.dll.a resp. open62541.lib are build. Additional artifacts can be
  114. specified by the following options:
  115. **UA_BUILD_EXAMPLES**
  116. Compile example servers and clients from :file:`examples/{xyz}.c`. A static and a dynamic binary is linked, respectively.
  117. **UA_BUILD_UNIT_TESTS**
  118. Compile unit tests with Check framework. The tests can be executed with ``make test``
  119. **UA_BUILD_EXAMPLES_NODESET_COMPILER**
  120. Generate an OPC UA information model from a nodeset XML (experimental)
  121. **UA_BUILD_SELFIGNED_CERTIFICATE**
  122. Generate a self-signed certificate for the server (openSSL required)
  123. UA_ENABLE_* group
  124. ^^^^^^^^^^^^^^^^^
  125. This group contains build options related to the supported OPC UA features.
  126. **UA_ENABLE_SUBSCRIPTIONS**
  127. Enable subscriptions
  128. **UA_ENABLE_METHODCALLS**
  129. Enable the Method service set
  130. **UA_ENABLE_NODEMANAGEMENT**
  131. Enable dynamic addition and removal of nodes at runtime
  132. **UA_ENABLE_AMALGAMATION**
  133. Compile a single-file release into the files :file:`open62541.c` and :file:`open62541.h`
  134. **UA_ENABLE_MULTITHREADING**
  135. Enable multi-threading support
  136. **UA_ENABLE_COVERAGE**
  137. Measure the coverage of unit tests
  138. Some options are marked as advanced. The advanced options need to be toggled to
  139. be visible in the cmake GUIs.
  140. **UA_ENABLE_TYPENAMES**
  141. Add the type and member names to the UA_DataType structure. Enabled by default.
  142. **UA_ENABLE_STATUSCODE_DESCRIPTIONS**
  143. Compile the human-readable name of the StatusCodes into the binary. Enabled by default.
  144. **UA_ENABLE_GENERATE_NAMESPACE0**
  145. Generate and load UA XML Namespace 0 definition
  146. ``UA_GENERATE_NAMESPACE0_FILE`` is used to specify the file for NS0 generation from namespace0 folder. Default value is ``Opc.Ua.NodeSet2.xml``
  147. **UA_ENABLE_NONSTANDARD_UDP**
  148. Enable udp extension
  149. UA_DEBUG_* group
  150. ^^^^^^^^^^^^^^^^
  151. This group contains build options mainly useful for development of the library itself.
  152. **UA_DEBUG**
  153. Enable assertions and additional definitions not intended for production builds
  154. **UA_DEBUG_DUMP_PKGS**
  155. Dump every package received by the server as hexdump format
  156. Building a shared library
  157. ^^^^^^^^^^^^^^^^^^^^^^^^^
  158. open62541 is small enough that most users will want to statically link the
  159. library into their programs. If a shared library (.dll, .so) is required, this
  160. can be enabled in CMake with the ``BUILD_SHARED_LIBS`` option. Note that this
  161. option modifies the :file:`ua_config.h` file that is also included in
  162. :file:`open62541.h` for the single-file distribution.
  163. Minimizing the binary size
  164. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  165. The size of the generated binary can be reduced considerably by adjusting the
  166. build configuration. First, in CMake, the build type can be set to
  167. ``CMAKE_BUILD_TYPE=MinSizeRel``. This sets the compiler flags to minimize the
  168. binary size. The build type also strips out debug information. Second, the
  169. binary size can be reduced by removing features via the build-flags described
  170. above.
  171. Especially, logging takes up a lot of space in the binary and might not be
  172. needed in embedded scenarios. Setting ``UA_LOGLEVEL`` to a value above 600
  173. (=FATAL) disables all logging. In addition, the feature-flags
  174. ``UA_ENABLE_TYPENAMES`` and ``UA_ENABLE_STATUSCODE_DESCRIPTIONS`` add static
  175. information to the binary that is only used for human-readable logging and
  176. debugging.