building.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. .. _building:
  2. Building open62541
  3. ==================
  4. open62541 uses CMake to build the library and binaries. The library version is automatically
  5. detected using ``git describe``. This command returns a valid version string based on the current tag.
  6. If you did not directly clone the sources, but use the tar or zip package from a release, you need
  7. to manually specify the version. In that case use e.g. ``cmake -DOPEN62541_VERSION=v1.0.3``.
  8. Building the Library
  9. --------------------
  10. Building with CMake on Ubuntu or Debian
  11. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12. .. code-block:: bash
  13. sudo apt-get install git build-essential gcc pkg-config cmake python
  14. # enable additional features
  15. sudo apt-get install cmake-curses-gui # for the ccmake graphical interface
  16. sudo apt-get install libmbedtls-dev # for encryption support
  17. sudo apt-get install check libsubunit-dev # for unit tests
  18. sudo apt-get install python-sphinx graphviz # for documentation generation
  19. sudo apt-get install python-sphinx-rtd-theme # documentation style
  20. cd open62541
  21. mkdir build
  22. cd build
  23. cmake ..
  24. make
  25. # select additional features
  26. ccmake ..
  27. make
  28. # build documentation
  29. make doc # html documentation
  30. make doc_pdf # pdf documentation (requires LaTeX)
  31. Building with CMake on Windows
  32. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  33. Here we explain the build process for Visual Studio (2013 or newer). To build
  34. with MinGW, just replace the compiler selection in the call to CMake.
  35. - Download and install
  36. - Python 2.7.x (Python 3.x works as well): https://python.org/downloads
  37. - CMake: http://www.cmake.org/cmake/resources/software.html
  38. - Microsoft Visual Studio: https://www.visualstudio.com/products/visual-studio-community-vs
  39. - Download the open62541 sources (using git or as a zipfile from github)
  40. - Open a command shell (cmd) and run
  41. .. code-block:: bat
  42. cd <path-to>\open62541
  43. mkdir build
  44. cd build
  45. <path-to>\cmake.exe .. -G "Visual Studio 14 2015"
  46. :: You can use use cmake-gui for a graphical user-interface to select features
  47. - Then open :file:`build\open62541.sln` in Visual Studio 2015 and build as usual
  48. Building on OS X
  49. ^^^^^^^^^^^^^^^^
  50. - Download and install
  51. - Xcode: https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
  52. - Homebrew: http://brew.sh/
  53. - Pip (a package manager for python, may be preinstalled): ``sudo easy_install pip``
  54. - Run the following in a shell
  55. .. code-block:: bash
  56. brew install cmake
  57. pip install sphinx # for documentation generation
  58. pip install sphinx_rtd_theme # documentation style
  59. brew install graphviz # for graphics in the documentation
  60. brew install check # for unit tests
  61. Follow Ubuntu instructions without the ``apt-get`` commands as these are taken care of by the above packages.
  62. Building on OpenBSD
  63. ^^^^^^^^^^^^^^^^^^^
  64. 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.
  65. - Install a recent gcc, python and cmake:
  66. .. code-block:: bash
  67. pkg_add gcc python cmake
  68. - Tell the system to actually use the recent gcc (it gets installed as egcc on OpenBSD):
  69. .. code-block:: bash
  70. export CC=egcc CXX=eg++
  71. - Now procede as described for Ubuntu/Debian:
  72. .. code-block:: bash
  73. cd open62541
  74. mkdir build
  75. cd build
  76. cmake ..
  77. make
  78. Building Debian Packages inside Docker Container with CMake on Ubuntu or Debian
  79. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  80. Here is an example howto build the library as Debian package inside a Docker container
  81. - Download and install
  82. - Docker Engine: https://docs.docker.com/install/linux/docker-ce/debian/
  83. - docker-deb-builder: https://github.com/tsaarni/docker-deb-builder.git
  84. - open62541: https://github.com/open62541/open62541.git
  85. Install Docker as described at https://docs.docker.com/install/linux/docker-ce/debian/ .
  86. Get the docker-deb-builder utility from github and make Docker images for the needed
  87. Debian and/or Ubuntu relases
  88. .. code-block:: bash
  89. # make and goto local development path (e.g. ~/development)
  90. mkdir ~/development
  91. cd ~/development
  92. # clone docker-deb-builder utility from github and change into builder directory
  93. git clone https://github.com/tsaarni/docker-deb-builder.git
  94. cd docker-deb-builder
  95. # make Docker builder images (e.g. Ubuntu 18.04 and 17.04)
  96. docker build -t docker-deb-builder:18.04 -f Dockerfile-ubuntu-18.04 .
  97. docker build -t docker-deb-builder:17.04 -f Dockerfile-ubuntu-17.04 .
  98. Make a local copy of the open62541 git repo and checkout a pack branch
  99. .. code-block:: bash
  100. # make a local copy of the open62541 git repo (e.g. in the home directory)
  101. # and checkout a pack branch (e.g. pack/1.0)
  102. cd ~
  103. git clone https://github.com/open62541/open62541.git
  104. cd ~/open62541
  105. git checkout pack/1.0
  106. Now it's all set to build Debian/Ubuntu open62541 packages
  107. .. code-block:: bash
  108. # goto local developmet path
  109. cd ~/development
  110. # make a local output directory for the builder where the packages can be placed after build
  111. mkdir output
  112. # build Debian/Ubuntu packages inside Docker container (e.g. Ubuntu-18.04)
  113. ./build -i docker-deb-builder:18.04 -o output ~/open62541
  114. After a successfull build the Debian/Ubuntu packages can be found at :file:`~/development/docker-deb-builder/output`
  115. CMake Build Options and Debian Packaging
  116. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  117. If the open62541 library will be build as a Debian package using a pack branch (e.g. pack/master or pack/1.0)
  118. then altering or adding CMake build options should be done inside the :file:`debian/rules` file respectively in
  119. the :file:`debian/rules-template` file if working with a development branch (e.g. master or 1.0).
  120. The section in :file:`debian/rules` where the CMake build options are defined is
  121. .. code-block:: bash
  122. ...
  123. override_dh_auto_configure:
  124. dh_auto_configure -- -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_NAMESPACE_ZERO=FULL -DUA_ENABLE_AMALGAMATION=OFF -DUA_PACK_DEBIAN=ON
  125. ...
  126. This CMake build options will be passed as command line variables to CMake during Debian packaging.
  127. .. _build_options:
  128. Build Options
  129. -------------
  130. The open62541 project uses CMake to manage the build options, for code
  131. generation and to generate build projects for the different systems and IDEs.
  132. The tools *ccmake* or *cmake-gui* can be used to graphically set the build
  133. options.
  134. Most options can be changed manually in :file:`ua_config.h` (:file:`open62541.h`
  135. for the single-file release) after the code generation. But usually there is no
  136. need to adjust them.
  137. Main Build Options
  138. ^^^^^^^^^^^^^^^^^^
  139. **CMAKE_BUILD_TYPE**
  140. - ``RelWithDebInfo`` -O2 optimization with debug symbols
  141. - ``Release`` -O2 optimization without debug symbols
  142. - ``Debug`` -O0 optimization with debug symbols
  143. - ``MinSizeRel`` -Os optimization without debug symbols
  144. **UA_LOGLEVEL**
  145. The SDK logs events of the level defined in ``UA_LOGLEVEL`` and above only.
  146. The logging event levels are as follows:
  147. - 600: Fatal
  148. - 500: Error
  149. - 400: Warning
  150. - 300: Info
  151. - 200: Debug
  152. - 100: Trace
  153. Select build artefacts
  154. ^^^^^^^^^^^^^^^^^^^^^^
  155. By default only the main library shared object libopen62541.so (open62541.dll)
  156. or static linking archive open62541.a (open62541.lib) is built. Additional
  157. artifacts can be specified by the following options:
  158. **UA_BUILD_EXAMPLES**
  159. Compile example servers and clients from :file:`examples/*.c`.
  160. **UA_BUILD_UNIT_TESTS**
  161. Compile unit tests. The tests can be executed with ``make test``
  162. **UA_BUILD_SELFSIGNED_CERTIFICATE**
  163. Generate a self-signed certificate for the server (openSSL required)
  164. Detailed SDK Features
  165. ^^^^^^^^^^^^^^^^^^^^^
  166. **UA_ENABLE_SUBSCRIPTIONS**
  167. Enable subscriptions
  168. **UA_ENABLE_SUBSCRIPTIONS_EVENTS (EXPERIMENTAL)**
  169. Enable the use of events for subscriptions. This is a new feature and currently marked as EXPERIMENTAL.
  170. **UA_ENABLE_METHODCALLS**
  171. Enable the Method service set
  172. **UA_ENABLE_NODEMANAGEMENT**
  173. Enable dynamic addition and removal of nodes at runtime
  174. **UA_ENABLE_AMALGAMATION**
  175. Compile a single-file release into the files :file:`open62541.c` and :file:`open62541.h`. Not recommended for installation.
  176. **UA_ENABLE_MULTITHREADING (EXPERIMENTAL)**
  177. Enable multi-threading support. Work is distributed to a number of worker threads.
  178. This is a new feature and currently marked as EXPERIMENTAL.
  179. **UA_ENABLE_IMMUTABLE_NODES**
  180. Nodes in the information model are not edited but copied and replaced. The
  181. replacement is done with atomic operations so that the information model is
  182. always consistent and can be accessed from an interrupt or parallel thread
  183. (depends on the node storage plugin implementation). This feature is a
  184. prerequisite for ``UA_ENABLE_MULTITHREADING``.
  185. **UA_ENABLE_COVERAGE**
  186. Measure the coverage of unit tests
  187. **UA_ENABLE_DISCOVERY**
  188. Enable Discovery Service (LDS)
  189. **UA_ENABLE_DISCOVERY_MULTICAST**
  190. Enable Discovery Service with multicast support (LDS-ME)
  191. **UA_ENABLE_DISCOVERY_SEMAPHORE**
  192. Enable Discovery Semaphore support
  193. **UA_NAMESPACE_ZERO**
  194. Namespace zero contains the standard-defined nodes. The full namespace zero
  195. may not be required for all applications. The selectable options are as follows:
  196. - ``MINIMAL``: A barebones namespace zero that is compatible with most
  197. clients. But this namespace 0 is so small that it does not pass the CTT
  198. (Conformance Testing Tools of the OPC Foundation).
  199. - ``REDUCED``: Small namespace zero that passes the CTT.
  200. - ``FULL``: Full namespace zero generated from the official XML definitions.
  201. The advanced build option ``UA_FILE_NS0`` can be used to override the XML
  202. file used for namespace zero generation.
  203. Some options are marked as advanced. The advanced options need to be toggled to
  204. be visible in the cmake GUIs.
  205. **UA_ENABLE_TYPENAMES**
  206. Add the type and member names to the UA_DataType structure. Enabled by default.
  207. **UA_ENABLE_STATUSCODE_DESCRIPTIONS**
  208. Compile the human-readable name of the StatusCodes into the binary. Enabled by default.
  209. **UA_ENABLE_FULL_NS0**
  210. Use the full NS0 instead of a minimal Namespace 0 nodeset
  211. ``UA_FILE_NS0`` is used to specify the file for NS0 generation from namespace0 folder. Default value is ``Opc.Ua.NodeSet2.xml``
  212. Debug Build Options
  213. ^^^^^^^^^^^^^^^^^^^
  214. This group contains build options mainly useful for development of the library itself.
  215. **UA_DEBUG**
  216. Enable assertions and additional definitions not intended for production builds
  217. **UA_DEBUG_DUMP_PKGS**
  218. Dump every package received by the server as hexdump format
  219. Building a shared library
  220. ^^^^^^^^^^^^^^^^^^^^^^^^^
  221. open62541 is small enough that most users will want to statically link the
  222. library into their programs. If a shared library (.dll, .so) is required, this
  223. can be enabled in CMake with the ``BUILD_SHARED_LIBS`` option. Note that this
  224. option modifies the :file:`ua_config.h` file that is also included in
  225. :file:`open62541.h` for the single-file distribution.
  226. Minimizing the binary size
  227. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  228. The size of the generated binary can be reduced considerably by adjusting the
  229. build configuration. With open2541, it is possible to configure minimal servers
  230. that require less than 100kB of RAM and ROM.
  231. The following options influence the ROM requirements:
  232. First, in CMake, the build type can be set to ``CMAKE_BUILD_TYPE=MinSizeRel``.
  233. This sets the compiler flags to minimize the binary size. The build type also
  234. strips out debug information. Second, the binary size can be reduced by removing
  235. features via the build-flags described above.
  236. Second, setting ``UA_NAMESPACE_ZERO`` to ``MINIMAL`` reduces the size of the
  237. builtin information model. Setting this option can reduce the binary size by
  238. half in some cases.
  239. Third, some features might not be needed and can be disabled to reduce the
  240. binary footprint. Examples for this are Subscriptions or encrypted
  241. communication.
  242. Last, logging messages take up a lot of space in the binary and might not be
  243. needed in embedded scenarios. Setting ``UA_LOGLEVEL`` to a value above 600
  244. (``FATAL``) disables all logging. In addition, the feature-flags
  245. ``UA_ENABLE_TYPENAMES`` and ``UA_ENABLE_STATUSCODE_DESCRIPTIONS`` add static
  246. information to the binary that is only used for human-readable logging and
  247. debugging.
  248. The RAM requirements of a server are mostly due to the following settings:
  249. - The size of the information model
  250. - The number of connected clients
  251. - The configured maximum message size that is preallocated
  252. Building the Examples
  253. ---------------------
  254. Make sure that you can build the shared library as explained in the previous steps. Even easier way
  255. to build the examples is to install open62541 in your operating system (see :ref:`installing`).
  256. Then the compiler should automatically find the includes and the shared library.
  257. .. code-block:: bash
  258. cp /path-to/examples/tutorial_server_firststeps.c . # copy the example server
  259. gcc -std=c99 -o server tutorial_server_firststeps.c -lopen62541
  260. .. include:: building_arch.rst