CMakeLists.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. cmake_minimum_required(VERSION 2.8.11)
  2. project(open62541 C)
  3. # set(CMAKE_VERBOSE_MAKEFILE ON)
  4. ######################
  5. # Check Dependencies #
  6. ######################
  7. # Find Python and Python-lxml
  8. find_package(PythonInterp REQUIRED)
  9. execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
  10. OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
  11. OUTPUT_STRIP_TRAILING_WHITESPACE)
  12. if(NOT EXISTS "${PYTHON_SITE_PACKAGES}/lxml")
  13. execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))"
  14. OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
  15. OUTPUT_STRIP_TRAILING_WHITESPACE)
  16. if(NOT EXISTS "${PYTHON_SITE_PACKAGES}/lxml")
  17. message(FATAL_ERROR "Python-lxml is not installed.")
  18. endif()
  19. endif()
  20. # Check for git
  21. find_package(Git)
  22. if(GIT_FOUND)
  23. execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=7 --dirty --always --tags
  24. RESULT_VARIABLE res_var
  25. OUTPUT_VARIABLE GIT_COM_ID )
  26. if(NOT ${res_var} EQUAL 0)
  27. set(GIT_COMMIT_ID "unknown--git-commit-id-unknown")
  28. message(STATUS "Git failed (not a repo, or no tags). Build will not contain git revision info." )
  29. else()
  30. string(REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} )
  31. endif()
  32. else()
  33. set(GIT_COMMIT_ID "unknown--no-git-found")
  34. message(STATUS "Git not found. Build will not contain git revision info." )
  35. endif()
  36. add_definitions("-DVERSION=${GIT_COMMIT_ID}")
  37. message(STATUS "Git version: " ${GIT_COMMIT_ID})
  38. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
  39. ####################################
  40. # Build Type and Compiler Settings #
  41. ####################################
  42. # Set default build type.
  43. if(NOT CMAKE_BUILD_TYPE)
  44. message(STATUS "CMAKE_BUILD_TYPE not given; setting to 'Debug'.")
  45. set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
  46. endif()
  47. # Collect libraries
  48. list(APPEND open62541_LIBRARIES "")
  49. # compiler flags
  50. if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  51. add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat -Wno-unused-parameter
  52. -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare
  53. -Wmultichar -Wstrict-overflow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes
  54. -Winit-self -Wuninitialized -Wformat-security -Wformat-nonliteral)
  55. # library linking
  56. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  57. if(NOT WIN32 AND NOT CYGWIN)
  58. add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
  59. if(NOT APPLE)
  60. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  61. endif()
  62. endif()
  63. # Debug
  64. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  65. #add_definitions(-fsanitize=address)
  66. #list(APPEND open62541_LIBRARIES asan)
  67. #add_definitions(-fsanitize=undefined)
  68. #list(APPEND open62541_LIBRARIES ubsan)
  69. elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR
  70. CMAKE_BUILD_TYPE STREQUAL "Release")
  71. add_definitions(-ffunction-sections -fdata-sections -fno-stack-protector -fno-unwind-tables
  72. -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
  73. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  74. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  75. if(APPLE)
  76. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
  77. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
  78. else()
  79. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  80. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  81. if(NOT WIN32 AND NOT CYGWIN)
  82. # these settings reduce the binary size by ~2kb
  83. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  84. endif()
  85. endif()
  86. endif()
  87. if(APPLE)
  88. set(CMAKE_MACOSX_RPATH 1)
  89. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
  90. endif()
  91. elseif(MSVC)
  92. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  93. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  94. endif()
  95. ############
  96. # Settings #
  97. ############
  98. # Options
  99. set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
  100. option(UA_ENABLE_SUBSCRIPTIONS "Enable compilation of subscription and monitoring support." OFF)
  101. option(UA_ENABLE_METHODCALLS "Enable CallMethod/MethodCall service set" OFF)
  102. option(UA_ENABLE_MULTITHREADING "Enable multithreading" OFF)
  103. option(UA_ENABLE_NODEMANAGEMENT "Enable dynamic addition and removal of nodes" ON)
  104. option(UA_ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
  105. option(UA_ENABLE_COVERAGE "Enable gcov coverage" OFF)
  106. if(UA_ENABLE_COVERAGE)
  107. set(CMAKE_BUILD_TYPE DEBUG)
  108. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  109. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  110. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  111. endif()
  112. # Advanced options
  113. option(UA_ENABLE_TYPENAMES "Add the type and member names to the UA_DataType structure" OFF)
  114. mark_as_advanced(UA_ENABLE_TYPENAMES)
  115. option(UA_ENABLE_GENERATE_NAMESPACE0 "Generate and load UA XML Namespace 0 definition" OFF)
  116. option(UA_ENABLE_EMBEDDED_LIBC "Target has no libc, use internal definitions" OFF)
  117. mark_as_advanced(UA_ENABLE_EMBEDDED_LIBC)
  118. option(UA_ENABLE_EXTERNAL_NAMESPACES "Enable namespace handling by an external component (experimental)" OFF)
  119. mark_as_advanced(UA_ENABLE_EXTERNAL_NAMESPACES)
  120. option(UA_ENABLE_NONSTANDARD_STATELESS "Enable stateless extension" OFF)
  121. mark_as_advanced(UA_ENABLE_NONSTANDARD_STATELESS)
  122. option(UA_ENABLE_NONSTANDARD_UDP "Enable udp extension" OFF)
  123. mark_as_advanced(UA_ENABLE_NONSTANDARD_UDP)
  124. if(UA_ENABLE_NONSTANDARD_UDP)
  125. set(UA_ENABLE_NONSTANDARD_STATELESS ON)
  126. endif()
  127. # Build Targets
  128. option(UA_BUILD_EXAMPLESERVER "Build the example server" OFF)
  129. option(UA_BUILD_EXAMPLECLIENT "Build a test client" OFF)
  130. option(UA_BUILD_UNIT_TESTS "Run unit tests after building" OFF)
  131. option(UA_BUILD_EXAMPLES "Build example servers and clients" OFF)
  132. option(UA_BUILD_DOCUMENTATION "Generate doxygen/sphinx documentation" OFF)
  133. # Advanced Build Targets
  134. option(UA_BUILD_SELFSIGNED_CERTIFICATE "Generate self-signed certificate" OFF)
  135. mark_as_advanced(UA_BUILD_SELFSIGNED_CERTIFICATE)
  136. #########################
  137. # Generate Main Library #
  138. #########################
  139. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  140. include_directories(${PROJECT_BINARY_DIR}/src_generated) #needed to locate an include of examples/server_nodeset.c
  141. configure_file("include/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  142. set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
  143. ${PROJECT_SOURCE_DIR}/include/ua_statuscodes.h
  144. ${PROJECT_SOURCE_DIR}/include/ua_types.h
  145. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  146. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  147. ${PROJECT_SOURCE_DIR}/include/ua_job.h
  148. ${PROJECT_SOURCE_DIR}/include/ua_connection.h
  149. ${PROJECT_SOURCE_DIR}/include/ua_log.h
  150. ${PROJECT_SOURCE_DIR}/include/ua_server.h
  151. ${PROJECT_SOURCE_DIR}/include/ua_server_external_ns.h
  152. ${PROJECT_SOURCE_DIR}/include/ua_client.h
  153. ${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
  154. ${PROJECT_SOURCE_DIR}/src_extra/networklayer_tcp.h
  155. ${PROJECT_SOURCE_DIR}/src_extra/logger_stdout.h)
  156. set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
  157. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
  158. ${PROJECT_SOURCE_DIR}/src/ua_util.h
  159. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  160. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  161. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  162. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  163. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  164. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
  165. ${PROJECT_SOURCE_DIR}/src/ua_session.h
  166. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
  167. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  168. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  169. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  170. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
  171. ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h)
  172. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  173. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  174. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  175. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  176. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  177. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  178. ${PROJECT_SOURCE_DIR}/src/ua_session.c
  179. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  180. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  181. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
  182. ${PROJECT_SOURCE_DIR}/src/server/ua_server_worker.c
  183. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.c
  184. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.c
  185. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery.c
  186. ${PROJECT_SOURCE_DIR}/src/server/ua_services_securechannel.c
  187. ${PROJECT_SOURCE_DIR}/src/server/ua_services_session.c
  188. ${PROJECT_SOURCE_DIR}/src/server/ua_services_attribute.c
  189. ${PROJECT_SOURCE_DIR}/src/server/ua_services_nodemanagement.c
  190. ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
  191. ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
  192. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
  193. ${PROJECT_SOURCE_DIR}/src_extra/networklayer_tcp.c
  194. ${PROJECT_SOURCE_DIR}/src_extra/logger_stdout.c
  195. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
  196. ##TODO: make client stuff optional
  197. if(UA_ENABLE_METHODCALLS)
  198. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c)
  199. endif()
  200. if(UA_ENABLE_EMBEDDED_LIBC)
  201. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/libc_string.c)
  202. endif()
  203. if(UA_ENABLE_MULTITHREADING)
  204. find_package(Threads REQUIRED)
  205. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c)
  206. else()
  207. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c)
  208. endif()
  209. set(generate_typeintrospection "")
  210. if(UA_ENABLE_TYPENAMES)
  211. set(generate_typeintrospection "--typeintrospection")
  212. endif()
  213. set(generate_subscriptiontypes "")
  214. if(UA_ENABLE_SUBSCRIPTIONS)
  215. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
  216. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
  217. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_manager.c
  218. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c)
  219. #append subscription headers at before ua_session
  220. list(FIND internal_headers "${PROJECT_SOURCE_DIR}/src/ua_session.h" UaSessionPos)
  221. list(INSERT internal_headers ${UaSessionPos} ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  222. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_manager.h)
  223. set(generate_subscriptiontypes "--enable-subscription-types=1")
  224. endif()
  225. if(UA_ENABLE_GENERATE_NAMESPACE0)
  226. set(GENERATE_NAMESPACE0_FILE "Opc.Ua.NodeSet2.xml" CACHE STRING "Namespace definition XML file")
  227. set_property(CACHE GENERATE_NAMESPACE0_FILE PROPERTY STRINGS Opc.Ua.NodeSet2.xml Opc.Ua.NodeSet2.Minimal.xml)
  228. list(APPEND internal_headers ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h)
  229. list(APPEND lib_sources ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c)
  230. endif()
  231. #########################
  232. # Generate source files #
  233. #########################
  234. # standard data types
  235. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  236. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  237. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  238. PRE_BUILD
  239. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  240. ${generate_subscriptiontypes}
  241. ${generate_typeintrospection}
  242. --typedescriptions ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv
  243. 0
  244. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  245. ${PROJECT_BINARY_DIR}/src_generated/ua_types
  246. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  247. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  248. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  249. # transport data types
  250. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  251. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  252. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  253. PRE_BUILD
  254. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  255. ${generate_typeintrospection}
  256. --ns0-types-xml ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  257. 1
  258. ${PROJECT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd
  259. ${PROJECT_BINARY_DIR}/src_generated/ua_transport
  260. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  261. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd)
  262. # nodeids
  263. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  264. PRE_BUILD
  265. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeids.py
  266. ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv
  267. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids
  268. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
  269. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  270. # generated namespace 0
  271. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c
  272. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h
  273. PRE_BUILD
  274. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  275. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_AssumeExternal.txt
  276. -s description -b ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist.txt
  277. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  278. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated
  279. DEPENDS ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  280. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  281. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
  282. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  283. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  284. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  285. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  286. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py)
  287. # single-file release
  288. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  289. PRE_BUILD
  290. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  291. ${GIT_COMMIT_ID}
  292. ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
  293. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  294. ${exported_headers}
  295. ${internal_headers})
  296. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  297. PRE_BUILD
  298. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  299. ${GIT_COMMIT_ID}
  300. ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
  301. ${internal_headers}
  302. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc
  303. ${lib_sources}
  304. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  305. ${internal_headers}
  306. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc
  307. ${lib_sources})
  308. #################
  309. # Build Targets #
  310. #################
  311. # build shared library
  312. if(UA_ENABLE_AMALGAMATION)
  313. add_custom_target(amalgamation ALL DEPENDS ${PROJECT_BINARY_DIR}/open62541.h ${PROJECT_BINARY_DIR}/open62541.c)
  314. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  315. include_directories(${PROJECT_BINARY_DIR})
  316. else()
  317. add_definitions(-DUA_NO_AMALGAMATION)
  318. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  319. include_directories(${PROJECT_SOURCE_DIR}/include)
  320. include_directories(${PROJECT_SOURCE_DIR}/src)
  321. include_directories(${PROJECT_SOURCE_DIR}/src_extra)
  322. include_directories(${PROJECT_SOURCE_DIR}/deps)
  323. endif()
  324. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING)
  325. add_library(open62541 SHARED $<TARGET_OBJECTS:open62541-object>)
  326. add_library(open62541-static STATIC $<TARGET_OBJECTS:open62541-object>)
  327. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING)
  328. target_compile_definitions(open62541-static PRIVATE -DUA_DYNAMIC_LINKING)
  329. target_link_libraries(open62541-static ${open62541_LIBRARIES})
  330. if(WIN32)
  331. target_link_libraries(open62541 ws2_32)
  332. target_link_libraries(open62541-static ws2_32)
  333. endif()
  334. if(UA_BUILD_EXAMPLESERVER)
  335. set(server_source $<TARGET_OBJECTS:open62541-object>)
  336. add_executable(server_static examples/server.c ${server_source})
  337. add_executable(server examples/server.c)
  338. if(UA_ENABLE_AMALGAMATION)
  339. ADD_DEPENDENCIES(server amalgamation)
  340. endif()
  341. target_link_libraries(server ${open62541_LIBRARIES} open62541)
  342. target_link_libraries(server_static ${open62541_LIBRARIES})
  343. if(WIN32)
  344. target_link_libraries(server_static ws2_32)
  345. target_link_libraries(server ws2_32)
  346. elseif(NOT APPLE)
  347. target_link_libraries(server_static rt)
  348. target_link_libraries(server rt)
  349. endif()
  350. if(UA_ENABLE_MULTITHREADING)
  351. target_link_libraries(server_static urcu-cds urcu urcu-common pthread)
  352. target_link_libraries(server urcu-cds urcu urcu-common pthread)
  353. endif()
  354. if(UA_ENABLE_NONSTANDARD_UDP)
  355. add_executable(exampleServerUDP $<TARGET_OBJECTS:open62541-object> examples/networklayer_udp.c examples/server_udp.c)
  356. target_link_libraries(exampleServerUDP ${open62541_LIBRARIES} open62541)
  357. if(UA_ENABLE_MULTITHREADING)
  358. target_link_libraries(exampleServerUDP urcu-cds urcu urcu-common)
  359. endif()
  360. if (NOT APPLE)
  361. target_link_libraries(exampleServerUDP rt)
  362. endif()
  363. endif()
  364. endif()
  365. if(UA_BUILD_SELFSIGNED_CERTIFICATE)
  366. message(STATUS "Enabling self-signed certificates")
  367. find_package(OpenSSL REQUIRED)
  368. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/server_cert.der
  369. ${PROJECT_BINARY_DIR}/ca.crt
  370. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${PROJECT_BINARY_DIR}
  371. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/create_self-signed.py
  372. ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/localhost.cnf)
  373. add_custom_target(selfsigned ALL DEPENDS ${PROJECT_BINARY_DIR}/server_cert.der ${PROJECT_BINARY_DIR}/ca.crt)
  374. endif()
  375. if(UA_BUILD_EXAMPLECLIENT)
  376. add_definitions(-DBENCHMARK)
  377. set(client_source $<TARGET_OBJECTS:open62541-object>)
  378. add_executable(client_static examples/client.c ${client_source})
  379. add_executable(client examples/client.c)
  380. if(UA_ENABLE_AMALGAMATION)
  381. ADD_DEPENDENCIES(client_static amalgamation)
  382. ADD_DEPENDENCIES(client amalgamation)
  383. endif()
  384. target_link_libraries(client_static ${open62541_LIBRARIES})
  385. target_link_libraries(client open62541 ${open62541_LIBRARIES})
  386. if(WIN32)
  387. target_link_libraries(client_static ws2_32)
  388. target_link_libraries(client ws2_32)
  389. elseif(NOT APPLE)
  390. target_link_libraries(client_static rt)
  391. target_link_libraries(client rt)
  392. endif()
  393. if(UA_ENABLE_MULTITHREADING)
  394. target_link_libraries(client_static urcu-cds urcu urcu-common pthread)
  395. target_link_libraries(client urcu-cds urcu urcu-common pthread)
  396. endif()
  397. if(UA_ENABLE_NONSTANDARD_STATELESS AND NOT UA_ENABLE_AMALGAMATION)
  398. add_executable(client_stateless examples/client_stateless.c ${client_source})
  399. target_link_libraries(client_stateless open62541 ${open62541_LIBRARIES})
  400. if(UA_ENABLE_MULTITHREADING)
  401. target_link_libraries(client_stateless urcu-cds urcu urcu-common pthread)
  402. endif()
  403. endif()
  404. endif()
  405. if(UA_BUILD_UNIT_TESTS)
  406. add_definitions(-DUA_BUILD_UNIT_TESTS)
  407. enable_testing()
  408. add_subdirectory(tests)
  409. endif()
  410. if(UA_BUILD_EXAMPLES)
  411. #add_subdirectory(examples)
  412. #FIXME: we had problem with static linking for msvs, here a quick and dirty workaround
  413. #http://stackoverflow.com/questions/3704374/linking-error-lnk2019-in-msvc-unresolved-symbols-with-imp-prefix-but-shoul
  414. #http://stackoverflow.com/questions/1089828/same-header-file-for-both-dll-and-static-library
  415. list(APPEND LIBS ${open62541_LIBRARIES})
  416. if(NOT WIN32)
  417. list(APPEND LIBS pthread)
  418. if (NOT APPLE)
  419. list(APPEND LIBS rt)
  420. endif()
  421. else()
  422. list(APPEND LIBS ws2_32)
  423. endif()
  424. if(UA_ENABLE_MULTITHREADING)
  425. list(APPEND LIBS urcu-cds urcu urcu-common)
  426. endif(UA_ENABLE_MULTITHREADING)
  427. add_executable(server_variable ${PROJECT_SOURCE_DIR}/examples/server_variable.c $<TARGET_OBJECTS:open62541-object>)
  428. target_link_libraries(server_variable ${LIBS})
  429. add_executable(server_datasource ${PROJECT_SOURCE_DIR}/examples/server_datasource.c $<TARGET_OBJECTS:open62541-object>)
  430. target_link_libraries(server_datasource ${LIBS})
  431. # add_executable(server_readspeed ${PROJECT_SOURCE_DIR}/examples/server_readspeed.c $<TARGET_OBJECTS:open62541-object>)
  432. # target_link_libraries(server_readspeed ${LIBS})
  433. add_executable(server_firstSteps ${PROJECT_SOURCE_DIR}/examples/server_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
  434. target_link_libraries(server_firstSteps ${LIBS})
  435. add_executable(client_firstSteps ${PROJECT_SOURCE_DIR}/examples/client_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
  436. target_link_libraries(client_firstSteps ${LIBS})
  437. add_executable(server_repeated_job ${PROJECT_SOURCE_DIR}/examples/server_repeated_job.c $<TARGET_OBJECTS:open62541-object>)
  438. target_link_libraries(server_repeated_job ${LIBS})
  439. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
  440. PRE_BUILD
  441. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  442. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  443. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml
  444. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml
  445. ${PROJECT_BINARY_DIR}/src_generated/nodeset
  446. DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  447. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
  448. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  449. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  450. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  451. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  452. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
  453. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  454. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
  455. add_executable(server_nodeset ${PROJECT_SOURCE_DIR}/examples/server_nodeset.c
  456. ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
  457. $<TARGET_OBJECTS:open62541-object>)
  458. target_link_libraries(server_nodeset ${LIBS})
  459. if(UA_ENABLE_METHODCALLS)
  460. add_executable(server_method ${PROJECT_SOURCE_DIR}/examples/server_method.c $<TARGET_OBJECTS:open62541-object>)
  461. target_link_libraries(server_method ${LIBS})
  462. endif()
  463. endif()
  464. # build documentation
  465. if(UA_BUILD_DOCUMENTATION)
  466. find_package(Sphinx REQUIRED)
  467. add_custom_target(doc_latex ${SPHINX_EXECUTABLE}
  468. -b latex -c "${PROJECT_SOURCE_DIR}/doc" "${PROJECT_SOURCE_DIR}/doc" "${PROJECT_BINARY_DIR}/doc_latex"
  469. COMMENT "Building LaTeX sources for documentation with Sphinx")
  470. add_custom_target(doc ${SPHINX_EXECUTABLE}
  471. -b html -c "${PROJECT_SOURCE_DIR}/doc" "${PROJECT_SOURCE_DIR}/doc" "${PROJECT_BINARY_DIR}/doc"
  472. COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/doc/open62541_html.png" "${PROJECT_BINARY_DIR}/doc/_static/"
  473. COMMENT "Building HTML documentation with Sphinx")
  474. endif()