CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. cmake_minimum_required(VERSION 2.8.8)
  2. # set(CMAKE_VERBOSE_MAKEFILE ON)
  3. project(open62541 C)
  4. FIND_PACKAGE(PythonInterp REQUIRED)
  5. # Find Python-lxml
  6. execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
  7. if(NOT EXISTS "${PYTHON_SITE_PACKAGES}/lxml")
  8. execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
  9. if(NOT EXISTS "${PYTHON_SITE_PACKAGES}/lxml")
  10. message( FATAL_ERROR "Python-lxml is not installed.")
  11. endif()
  12. endif()
  13. find_package(Git)
  14. if(GIT_FOUND)
  15. execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=7 --dirty --always --tags RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_COM_ID )
  16. if( NOT ${res_var} EQUAL 0 )
  17. set( GIT_COMMIT_ID "unknown--git-commit-id-unknown")
  18. message( WARNING "Git failed (not a repo, or no tags). Build will not contain git revision info." )
  19. else()
  20. string( REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} )
  21. endif()
  22. else()
  23. set( GIT_COMMIT_ID "unknown--no-git-found")
  24. message( WARNING "Git not found. Build will not contain git revision info." )
  25. endif()
  26. add_definitions("-DVERSION=${GIT_COMMIT_ID}")
  27. MESSAGE (STATUS "Git version: " ${GIT_COMMIT_ID})
  28. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
  29. # Set default build type.
  30. if(NOT CMAKE_BUILD_TYPE)
  31. message(STATUS "CMAKE_BUILD_TYPE not given; setting to 'RelWithDebInfo'.")
  32. set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
  33. endif()
  34. # compiler flags
  35. if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  36. add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat -Wno-unused-parameter
  37. -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare -Wmultichar
  38. -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes # -Wshadow -Wconversion
  39. -Winit-self -Wuninitialized -Wformat-security -Wformat-nonliteral)
  40. # binary size reduction settings
  41. add_definitions(-ffunction-sections -fdata-sections -fno-stack-protector -fno-unwind-tables
  42. -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
  43. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  44. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  45. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  46. if(NOT WIN32)
  47. add_definitions(-fvisibility=hidden -fPIC)
  48. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  49. endif()
  50. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
  51. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  52. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  53. endif()
  54. endif()
  55. # build the main library
  56. set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
  57. ${PROJECT_SOURCE_DIR}/include/ua_statuscodes.h
  58. ${PROJECT_SOURCE_DIR}/include/ua_types.h
  59. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  60. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  61. ${PROJECT_SOURCE_DIR}/include/ua_connection.h
  62. ${PROJECT_SOURCE_DIR}/include/ua_log.h
  63. ${PROJECT_SOURCE_DIR}/include/ua_server.h
  64. ${PROJECT_SOURCE_DIR}/include/ua_client.h
  65. ${PROJECT_SOURCE_DIR}/examples/networklayer_tcp.h
  66. ${PROJECT_SOURCE_DIR}/examples/logger_stdout.h)
  67. set(internal_headers ${PROJECT_SOURCE_DIR}/src/ua_util.h
  68. ${PROJECT_SOURCE_DIR}/deps/queue.h
  69. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  70. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  71. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  72. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
  73. ${PROJECT_SOURCE_DIR}/src/ua_session.h
  74. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
  75. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  76. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  77. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  78. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h)
  79. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  80. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  81. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  82. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  83. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  84. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  85. ${PROJECT_SOURCE_DIR}/src/ua_session.c
  86. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  87. ${PROJECT_SOURCE_DIR}/src/server/ua_server_addressspace.c
  88. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  89. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
  90. ${PROJECT_SOURCE_DIR}/src/server/ua_server_worker.c
  91. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.c
  92. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.c
  93. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery.c
  94. ${PROJECT_SOURCE_DIR}/src/server/ua_services_securechannel.c
  95. ${PROJECT_SOURCE_DIR}/src/server/ua_services_session.c
  96. ${PROJECT_SOURCE_DIR}/src/server/ua_services_attribute.c
  97. ${PROJECT_SOURCE_DIR}/src/server/ua_services_nodemanagement.c
  98. ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
  99. ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
  100. ${PROJECT_SOURCE_DIR}/examples/networklayer_tcp.c
  101. ${PROJECT_SOURCE_DIR}/examples/logger_stdout.c)
  102. ##TODO: make client stuff optional
  103. ## generate code from xml definitions
  104. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  105. option(ENABLE_SUBSCRIPTIONS "Enable compilation of subscription and monitoring support." OFF)
  106. if(ENABLE_SUBSCRIPTIONS)
  107. add_definitions(-DENABLE_SUBSCRIPTIONS)
  108. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
  109. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
  110. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_manager.c)
  111. ##append subscription headers at before ua_session.
  112. list(FIND internal_headers "${PROJECT_SOURCE_DIR}/src/ua_session.h" UaSessionPos)
  113. list(INSERT internal_headers ${UaSessionPos} ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  114. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_manager.h)
  115. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  116. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  117. PRE_BUILD
  118. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py --enable-subscription-types=1 --typedescriptions ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv 0 ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_types
  119. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  120. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  121. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  122. else()
  123. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  124. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  125. PRE_BUILD
  126. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py --typedescriptions ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv 0 ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_types
  127. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  128. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  129. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  130. endif()
  131. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  132. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  133. PRE_BUILD
  134. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py --ns0-types-xml ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd 1 ${PROJECT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_transport
  135. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  136. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd)
  137. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  138. PRE_BUILD
  139. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeids.py ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids
  140. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
  141. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  142. option(ENABLE_GENERATE_NAMESPACE0 "Generate and load UA XML Namespace 0 definition" OFF)
  143. if(ENABLE_GENERATE_NAMESPACE0)
  144. add_definitions(-DENABLE_GENERATE_NAMESPACE0)
  145. set(GENERATE_NAMESPACE0_FILE "Opc.Ua.NodeSet2.xml" CACHE STRING "Namespace definition XML file")
  146. set_property(CACHE GENERATE_NAMESPACE0_FILE PROPERTY STRINGS Opc.Ua.NodeSet2.xml Opc.Ua.NodeSet2.Minimal.xml)
  147. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c
  148. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h
  149. PRE_BUILD
  150. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_AssumeExternal.txt -s description -b ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist.txt ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE} ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated
  151. DEPENDS ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  152. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  153. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
  154. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  155. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  156. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  157. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  158. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py)
  159. list(APPEND internal_headers ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h)
  160. list(APPEND lib_sources ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c)
  161. endif()
  162. ## logging
  163. set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
  164. ## multithreading
  165. option(ENABLE_MULTITHREADING "Enable multithreading (experimental)" OFF)
  166. if(ENABLE_MULTITHREADING)
  167. add_definitions(-DUA_MULTITHREADING)
  168. find_package(Threads REQUIRED)
  169. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c)
  170. else()
  171. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c)
  172. endif()
  173. option(ENABLE_EXTERNAL_NAMESPACES "Enable namespace handling by an external component (experimental)" OFF)
  174. if(ENABLE_EXTERNAL_NAMESPACES)
  175. add_definitions(-DUA_EXTERNAL_NAMESPACES)
  176. endif()
  177. ## enable dynamic nodeset
  178. option(ENABLE_ADDNODES "Enable dynamic addition of nodes" ON)
  179. if(ENABLE_ADDNODES)
  180. add_definitions(-DENABLE_ADDNODES )
  181. endif()
  182. ## set the precompiler flags
  183. configure_file("include/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  184. ## extensions
  185. option(EXTENSION_UDP "Enable udp extension" OFF)
  186. if(EXTENSION_UDP)
  187. add_definitions(-DEXTENSION_STATELESS)
  188. message(STATUS "Extensions: enabling udp")
  189. add_definitions(-DEXTENSION_UDP)
  190. add_executable(exampleServerUDP $<TARGET_OBJECTS:open62541-object> examples/networklayer_udp.c examples/server_udp.c)
  191. target_link_libraries(exampleServerUDP rt)
  192. endif()
  193. option(EXTENSION_STATELESS "Enable stateless extension" OFF)
  194. if(EXTENSION_STATELESS)
  195. message(STATUS "Extensions: enabling stateless")
  196. add_definitions(-DEXTENSION_STATELESS)
  197. endif()
  198. option(ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
  199. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  200. PRE_BUILD
  201. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
  202. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${exported_headers} ${internal_headers})
  203. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  204. PRE_BUILD
  205. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
  206. ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources}
  207. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
  208. if(ENABLE_AMALGAMATION)
  209. add_custom_target(amalgamation ALL DEPENDS ${PROJECT_BINARY_DIR}/open62541.h ${PROJECT_BINARY_DIR}/open62541.c)
  210. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  211. include_directories(${PROJECT_BINARY_DIR})
  212. else()
  213. add_definitions(-DUA_NO_AMALGAMATION)
  214. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  215. include_directories(${PROJECT_SOURCE_DIR}/include)
  216. include_directories(${PROJECT_SOURCE_DIR}/deps)
  217. include_directories(${PROJECT_SOURCE_DIR}/src)
  218. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  219. endif()
  220. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING)
  221. add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
  222. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING)
  223. if(WIN32)
  224. target_link_libraries(open62541 ws2_32) #since networklayer_tcp is linked into the amalgate
  225. endif()
  226. # build language bindings for the library
  227. option(ENABLE_BINDING_LUA "Build Lua bindings" OFF)
  228. option(ENABLE_BINDING_PYTHON "Build Python bindings" OFF)
  229. if(ENABLE_BINDING_LUA OR ENABLE_BINDING_PYTHON)
  230. add_subdirectory(bindings)
  231. endif()
  232. # coverage
  233. option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
  234. if(ENABLE_COVERAGE)
  235. message(STATUS "Enabling gcov support")
  236. set(CMAKE_BUILD_TYPE DEBUG)
  237. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  238. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  239. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  240. endif()
  241. # build example server
  242. option(BUILD_EXAMPLESERVER "Build the example server" OFF)
  243. if(BUILD_EXAMPLESERVER)
  244. set(server_source $<TARGET_OBJECTS:open62541-object>)
  245. add_executable(server_static examples/server.c ${server_source})
  246. add_executable(server_simple examples/server_simple.c ${server_source})
  247. add_executable(server examples/server.c)
  248. if(ENABLE_AMALGAMATION)
  249. ADD_DEPENDENCIES(server amalgamation)
  250. endif()
  251. target_link_libraries(server open62541)
  252. if(WIN32)
  253. target_link_libraries(server_static ws2_32)
  254. target_link_libraries(server_simple ws2_32)
  255. target_link_libraries(server ws2_32)
  256. else()
  257. target_link_libraries(server_static rt)
  258. target_link_libraries(server_simple rt)
  259. target_link_libraries(server rt)
  260. endif()
  261. if(ENABLE_MULTITHREADING)
  262. target_link_libraries(server_static urcu-cds urcu urcu-common pthread)
  263. target_link_libraries(server_simple urcu-cds urcu urcu-common pthread)
  264. target_link_libraries(server urcu-cds urcu urcu-common pthread)
  265. endif()
  266. endif()
  267. ## self-signed certificates
  268. option(GENERATE_SELFSIGNED "Generate self-signed certificates" OFF)
  269. if(GENERATE_SELFSIGNED)
  270. message(STATUS "Enabling self-signed certificates")
  271. find_package(OpenSSL REQUIRED)
  272. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/server_cert.der
  273. ${PROJECT_BINARY_DIR}/ca.crt
  274. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${PROJECT_BINARY_DIR}
  275. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/create_self-signed.py
  276. ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/localhost.cnf)
  277. add_custom_target(selfsigned ALL DEPENDS ${PROJECT_BINARY_DIR}/server_cert.der ${PROJECT_BINARY_DIR}/ca.crt)
  278. endif()
  279. # build example client
  280. option(BUILD_EXAMPLECLIENT "Build a test client" OFF)
  281. if(BUILD_EXAMPLECLIENT)
  282. add_definitions(-DBENCHMARK)
  283. set(client_source $<TARGET_OBJECTS:open62541-object>)
  284. add_executable(client_static examples/client.c ${client_source})
  285. add_executable(client examples/client.c)
  286. if(ENABLE_AMALGAMATION)
  287. ADD_DEPENDENCIES(client amalgamation)
  288. endif()
  289. target_link_libraries(client open62541)
  290. if(WIN32)
  291. target_link_libraries(client_static ws2_32)
  292. target_link_libraries(client ws2_32)
  293. else()
  294. target_link_libraries(client_static rt)
  295. target_link_libraries(client rt)
  296. endif()
  297. if(ENABLE_MULTITHREADING)
  298. target_link_libraries(client_static urcu-cds urcu urcu-common pthread)
  299. target_link_libraries(client urcu-cds urcu urcu-common pthread)
  300. endif()
  301. if(EXTENSION_STATELESS)
  302. add_executable(client_stateless examples/client_stateless.c ${client_source})
  303. if(ENABLE_MULTITHREADING)
  304. target_link_libraries(client_stateless urcu-cds urcu urcu-common pthread)
  305. endif()
  306. endif()
  307. endif()
  308. # build unit tests
  309. option(BUILD_UNIT_TESTS "Run unit tests after building" OFF)
  310. if(BUILD_UNIT_TESTS)
  311. add_definitions(-DBUILD_UNIT_TESTS)
  312. enable_testing()
  313. add_subdirectory(tests)
  314. endif()
  315. # build documentation
  316. option(BUILD_DOCUMENTATION "Generate doxygen/sphinx documentation" OFF)
  317. if(BUILD_DOCUMENTATION)
  318. find_package(Doxygen REQUIRED)
  319. find_package(Sphinx REQUIRED)
  320. configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in ${PROJECT_BINARY_DIR}/Doxyfile @ONLY)
  321. configure_file(${PROJECT_SOURCE_DIR}/doc/conf.py ${PROJECT_BINARY_DIR}/conf.py @ONLY)
  322. add_custom_target(doxygen
  323. ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  324. WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
  325. COMMENT "Generating API documentation with Doxygen")
  326. add_custom_target(doc ${SPHINX_EXECUTABLE}
  327. -b html -c "${PROJECT_BINARY_DIR}"
  328. "${PROJECT_SOURCE_DIR}/doc" "${PROJECT_BINARY_DIR}/doc/sphinx"
  329. DEPENDS doxygen
  330. COMMENT "Building HTML documentation with Sphinx")
  331. endif()