CMakeLists.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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( STATUS "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( STATUS "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. if (APPLE)
  44. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
  45. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
  46. else()
  47. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  48. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  49. endif()
  50. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  51. if(NOT WIN32)
  52. if(NOT CYGWIN)
  53. add_definitions(-fvisibility=hidden -fPIC)
  54. if (NOT APPLE)
  55. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  56. endif()
  57. endif()
  58. endif()
  59. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
  60. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  61. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  62. endif()
  63. if (APPLE)
  64. set(CMAKE_MACOSX_RPATH 1)
  65. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
  66. endif()
  67. elseif(MSVC)
  68. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  69. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  70. endif()
  71. # build the main library
  72. set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
  73. ${PROJECT_SOURCE_DIR}/include/ua_statuscodes.h
  74. ${PROJECT_SOURCE_DIR}/include/ua_types.h
  75. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  76. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  77. ${PROJECT_SOURCE_DIR}/include/ua_connection.h
  78. ${PROJECT_SOURCE_DIR}/include/ua_log.h
  79. ${PROJECT_SOURCE_DIR}/include/ua_server.h
  80. ${PROJECT_SOURCE_DIR}/include/ua_client.h
  81. ${PROJECT_SOURCE_DIR}/examples/networklayer_tcp.h
  82. ${PROJECT_SOURCE_DIR}/examples/logger_stdout.h)
  83. set(internal_headers ${PROJECT_SOURCE_DIR}/src/ua_util.h
  84. ${PROJECT_SOURCE_DIR}/deps/queue.h
  85. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  86. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  87. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  88. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
  89. ${PROJECT_SOURCE_DIR}/src/ua_session.h
  90. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
  91. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  92. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  93. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  94. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
  95. ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h)
  96. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  97. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  98. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  99. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  100. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  101. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  102. ${PROJECT_SOURCE_DIR}/src/ua_session.c
  103. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  104. ${PROJECT_SOURCE_DIR}/src/server/ua_server_addressspace.c
  105. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  106. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
  107. ${PROJECT_SOURCE_DIR}/src/server/ua_server_worker.c
  108. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.c
  109. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.c
  110. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery.c
  111. ${PROJECT_SOURCE_DIR}/src/server/ua_services_securechannel.c
  112. ${PROJECT_SOURCE_DIR}/src/server/ua_services_session.c
  113. ${PROJECT_SOURCE_DIR}/src/server/ua_services_attribute.c
  114. ${PROJECT_SOURCE_DIR}/src/server/ua_services_nodemanagement.c
  115. ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
  116. ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
  117. ${PROJECT_SOURCE_DIR}/examples/networklayer_tcp.c
  118. ${PROJECT_SOURCE_DIR}/examples/logger_stdout.c)
  119. ##TODO: make client stuff optional
  120. ## generate code from xml definitions
  121. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  122. option(ENABLE_SUBSCRIPTIONS "Enable compilation of subscription and monitoring support." OFF)
  123. if(ENABLE_SUBSCRIPTIONS)
  124. set(ENABLE_SUBSCRIPTIONS ON) #to propagate it to the config file
  125. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
  126. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
  127. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_manager.c)
  128. ##append subscription headers at before ua_session.
  129. list(FIND internal_headers "${PROJECT_SOURCE_DIR}/src/ua_session.h" UaSessionPos)
  130. list(INSERT internal_headers ${UaSessionPos} ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  131. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_manager.h)
  132. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  133. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  134. PRE_BUILD
  135. 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
  136. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  137. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  138. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  139. else()
  140. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  141. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  142. PRE_BUILD
  143. 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
  144. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  145. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  146. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  147. endif()
  148. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  149. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  150. PRE_BUILD
  151. 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
  152. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  153. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd)
  154. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  155. PRE_BUILD
  156. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeids.py ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids
  157. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
  158. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  159. option(ENABLE_GENERATE_NAMESPACE0 "Generate and load UA XML Namespace 0 definition" OFF)
  160. if(ENABLE_GENERATE_NAMESPACE0)
  161. add_definitions(-DENABLE_GENERATE_NAMESPACE0)
  162. set(GENERATE_NAMESPACE0_FILE "Opc.Ua.NodeSet2.xml" CACHE STRING "Namespace definition XML file")
  163. set_property(CACHE GENERATE_NAMESPACE0_FILE PROPERTY STRINGS Opc.Ua.NodeSet2.xml Opc.Ua.NodeSet2.Minimal.xml)
  164. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c
  165. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h
  166. PRE_BUILD
  167. 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
  168. DEPENDS ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  169. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  170. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
  171. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  172. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  173. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  174. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  175. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py)
  176. list(APPEND internal_headers ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h)
  177. list(APPEND lib_sources ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c)
  178. endif()
  179. ## logging
  180. set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
  181. # Enable Methodcall service
  182. option(ENABLE_METHODCALLS "Enable CallMethod/MethodCall service set" OFF)
  183. if(ENABLE_METHODCALLS)
  184. set(ENABLE_METHODCALLS ON) #to propagate it to the config file
  185. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c)
  186. endif()
  187. ## multithreading
  188. option(ENABLE_MULTITHREADING "Enable multithreading (experimental)" OFF)
  189. if(ENABLE_MULTITHREADING)
  190. set(UA_MULTITHREADING ON) #to propagate it to the config file
  191. find_package(Threads REQUIRED)
  192. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c)
  193. else()
  194. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c)
  195. endif()
  196. option(ENABLE_EXTERNAL_NAMESPACES "Enable namespace handling by an external component (experimental)" OFF)
  197. if(ENABLE_EXTERNAL_NAMESPACES)
  198. add_definitions(-DUA_EXTERNAL_NAMESPACES)
  199. endif()
  200. ## enable dynamic nodeset
  201. option(ENABLE_ADDNODES "Enable dynamic addition of nodes" ON)
  202. if(ENABLE_ADDNODES)
  203. add_definitions(-DENABLE_ADDNODES )
  204. endif()
  205. ## set the precompiler flags
  206. configure_file("include/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  207. ## extensions
  208. option(EXTENSION_UDP "Enable udp extension" OFF)
  209. if(EXTENSION_UDP)
  210. add_definitions(-DEXTENSION_STATELESS)
  211. message(STATUS "Extensions: enabling udp")
  212. add_definitions(-DEXTENSION_UDP)
  213. add_executable(exampleServerUDP $<TARGET_OBJECTS:open62541-object> examples/networklayer_udp.c examples/server_udp.c)
  214. target_link_libraries(exampleServerUDP urcu-cds urcu urcu-common)
  215. if (NOT APPLE)
  216. target_link_libraries(exampleServerUDP rt)
  217. endif()
  218. endif()
  219. option(EXTENSION_STATELESS "Enable stateless extension" OFF)
  220. if(EXTENSION_STATELESS)
  221. message(STATUS "Extensions: enabling stateless")
  222. add_definitions(-DEXTENSION_STATELESS)
  223. endif()
  224. option(ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
  225. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  226. PRE_BUILD
  227. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
  228. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${exported_headers} ${internal_headers})
  229. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  230. PRE_BUILD
  231. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
  232. ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources}
  233. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers} ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
  234. if(ENABLE_AMALGAMATION)
  235. add_custom_target(amalgamation ALL DEPENDS ${PROJECT_BINARY_DIR}/open62541.h ${PROJECT_BINARY_DIR}/open62541.c)
  236. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  237. include_directories(${PROJECT_BINARY_DIR})
  238. else()
  239. add_definitions(-DUA_NO_AMALGAMATION)
  240. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  241. include_directories(${PROJECT_SOURCE_DIR}/include)
  242. include_directories(${PROJECT_SOURCE_DIR}/deps)
  243. include_directories(${PROJECT_SOURCE_DIR}/src)
  244. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  245. endif()
  246. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING)
  247. add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
  248. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING)
  249. if(WIN32)
  250. target_link_libraries(open62541 ws2_32) #since networklayer_tcp is linked into the amalgate
  251. endif()
  252. if(ENABLE_MULTITHREADING)
  253. target_link_libraries(open62541 urcu-cds urcu urcu-common pthread)
  254. endif()
  255. # build language bindings for the library
  256. option(ENABLE_BINDING_LUA "Build Lua bindings" OFF)
  257. option(ENABLE_BINDING_PYTHON "Build Python bindings" OFF)
  258. if(ENABLE_BINDING_LUA OR ENABLE_BINDING_PYTHON)
  259. add_subdirectory(bindings)
  260. endif()
  261. # coverage
  262. option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
  263. if(ENABLE_COVERAGE)
  264. message(STATUS "Enabling gcov support")
  265. set(CMAKE_BUILD_TYPE DEBUG)
  266. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  267. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  268. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  269. endif()
  270. # build example server
  271. option(BUILD_EXAMPLESERVER "Build the example server" OFF)
  272. if(BUILD_EXAMPLESERVER)
  273. set(server_source $<TARGET_OBJECTS:open62541-object>)
  274. add_executable(server_static examples/server.c ${server_source})
  275. add_executable(server examples/server.c)
  276. if(ENABLE_AMALGAMATION)
  277. ADD_DEPENDENCIES(server amalgamation)
  278. endif()
  279. target_link_libraries(server open62541)
  280. if(WIN32)
  281. target_link_libraries(server_static ws2_32)
  282. target_link_libraries(server ws2_32)
  283. elseif(NOT APPLE)
  284. target_link_libraries(server_static rt)
  285. target_link_libraries(server rt)
  286. endif()
  287. if(ENABLE_MULTITHREADING)
  288. target_link_libraries(server_static urcu-cds urcu urcu-common pthread)
  289. target_link_libraries(server urcu-cds urcu urcu-common pthread)
  290. endif()
  291. endif()
  292. ## self-signed certificates
  293. option(GENERATE_SELFSIGNED "Generate self-signed certificates" OFF)
  294. if(GENERATE_SELFSIGNED)
  295. message(STATUS "Enabling self-signed certificates")
  296. find_package(OpenSSL REQUIRED)
  297. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/server_cert.der
  298. ${PROJECT_BINARY_DIR}/ca.crt
  299. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${PROJECT_BINARY_DIR}
  300. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/create_self-signed.py
  301. ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/localhost.cnf)
  302. add_custom_target(selfsigned ALL DEPENDS ${PROJECT_BINARY_DIR}/server_cert.der ${PROJECT_BINARY_DIR}/ca.crt)
  303. endif()
  304. # build example client
  305. option(BUILD_EXAMPLECLIENT "Build a test client" OFF)
  306. if(BUILD_EXAMPLECLIENT)
  307. add_definitions(-DBENCHMARK)
  308. set(client_source $<TARGET_OBJECTS:open62541-object>)
  309. add_executable(client_static examples/client.c ${client_source})
  310. add_executable(client examples/client.c)
  311. if(ENABLE_AMALGAMATION)
  312. ADD_DEPENDENCIES(client amalgamation)
  313. endif()
  314. target_link_libraries(client open62541)
  315. if(WIN32)
  316. target_link_libraries(client_static ws2_32)
  317. target_link_libraries(client ws2_32)
  318. elseif(NOT APPLE)
  319. target_link_libraries(client_static rt)
  320. target_link_libraries(client rt)
  321. endif()
  322. if(ENABLE_MULTITHREADING)
  323. target_link_libraries(client_static urcu-cds urcu urcu-common pthread)
  324. target_link_libraries(client urcu-cds urcu urcu-common pthread)
  325. endif()
  326. if(EXTENSION_STATELESS)
  327. add_executable(client_stateless examples/client_stateless.c ${client_source})
  328. if(ENABLE_MULTITHREADING)
  329. target_link_libraries(client_stateless urcu-cds urcu urcu-common pthread)
  330. endif()
  331. endif()
  332. endif()
  333. # build unit tests
  334. option(BUILD_UNIT_TESTS "Run unit tests after building" OFF)
  335. if(BUILD_UNIT_TESTS)
  336. add_definitions(-DBUILD_UNIT_TESTS)
  337. enable_testing()
  338. add_subdirectory(tests)
  339. endif()
  340. option(BUILD_EXAMPLES "Build example servers and clients" OFF)
  341. if(BUILD_EXAMPLES)
  342. add_subdirectory(examples)
  343. endif()
  344. # build documentation
  345. option(BUILD_DOCUMENTATION "Generate doxygen/sphinx documentation" OFF)
  346. if(BUILD_DOCUMENTATION)
  347. find_package(Doxygen REQUIRED)
  348. find_package(Sphinx REQUIRED)
  349. configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in ${PROJECT_BINARY_DIR}/Doxyfile @ONLY)
  350. configure_file(${PROJECT_SOURCE_DIR}/doc/conf.py ${PROJECT_BINARY_DIR}/conf.py @ONLY)
  351. add_custom_target(doxygen
  352. ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  353. WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
  354. COMMENT "Generating API documentation with Doxygen")
  355. add_custom_target(doc ${SPHINX_EXECUTABLE}
  356. -b html -c "${PROJECT_BINARY_DIR}"
  357. "${PROJECT_SOURCE_DIR}/doc" "${PROJECT_BINARY_DIR}/doc/sphinx"
  358. DEPENDS doxygen
  359. COMMENT "Building HTML documentation with Sphinx")
  360. endif()