CMakeLists.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. cmake_minimum_required(VERSION 2.8.11)
  2. project(open62541)
  3. # set(CMAKE_VERBOSE_MAKEFILE ON)
  4. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/tools/cmake")
  5. find_package(PythonInterp REQUIRED)
  6. find_package(Git)
  7. ###########
  8. # Version #
  9. ###########
  10. set(OPEN62541_VER_MAJOR 0)
  11. set(OPEN62541_VER_MINOR 2)
  12. set(OPEN62541_VER_PATCH 0)
  13. set(OPEN62541_VER_LABEL "-rc2") # Appended to the X.Y.Z version format. For example "-rc1" or an empty string
  14. # Set OPEN62541_VER_COMMIT
  15. if(GIT_FOUND)
  16. execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --tags
  17. RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_COM_ID WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
  18. if(${res_var} EQUAL 0)
  19. string(REPLACE "\n" "" OPEN62541_VER_COMMIT ${GIT_COM_ID} )
  20. endif()
  21. endif()
  22. if(NOT ${OPEN62541_VER_COMMIT} OR ${OPEN62541_VER_COMMIT} STREQUAL "")
  23. set(OPEN62541_VER_COMMIT "undefined")
  24. endif()
  25. ############
  26. # Settings #
  27. ############
  28. # Set default build type.
  29. if(NOT CMAKE_BUILD_TYPE)
  30. message(STATUS "CMAKE_BUILD_TYPE not given; setting to 'Debug'")
  31. set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build" FORCE)
  32. endif()
  33. # Options
  34. set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
  35. option(UA_ENABLE_METHODCALLS "Enable the Method service set" ON)
  36. option(UA_ENABLE_NODEMANAGEMENT "Enable dynamic addition and removal of nodes at runtime" ON)
  37. option(UA_ENABLE_SUBSCRIPTIONS "Enable subscriptions support." ON)
  38. option(UA_ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
  39. option(UA_ENABLE_COVERAGE "Enable gcov coverage" OFF)
  40. option(BUILD_SHARED_LIBS "Enable building of shared libraries (dll/so)" OFF)
  41. if(UA_ENABLE_COVERAGE)
  42. set(CMAKE_BUILD_TYPE DEBUG)
  43. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  44. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
  45. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  46. endif()
  47. # Advanced options
  48. option(UA_ENABLE_MULTITHREADING "Enable multithreading (experimental)" OFF)
  49. mark_as_advanced(UA_ENABLE_MULTITHREADING)
  50. option(UA_ENABLE_STATUSCODE_DESCRIPTIONS "Enable conversion of StatusCode to human-readable error message" ON)
  51. mark_as_advanced(UA_ENABLE_STATUSCODE_DESCRIPTIONS)
  52. option(UA_ENABLE_TYPENAMES "Add the type and member names to the UA_DataType structure" ON)
  53. mark_as_advanced(UA_ENABLE_TYPENAMES)
  54. option(UA_ENABLE_EMBEDDED_LIBC "Use a custom implementation of some libc functions that might be missing on embedded targets (e.g. string handling)." OFF)
  55. mark_as_advanced(UA_ENABLE_EMBEDDED_LIBC)
  56. option(UA_ENABLE_DETERMINISTIC_RNG "Do not seed the random number generator (e.g. for unit tests)." OFF)
  57. mark_as_advanced(UA_ENABLE_DETERMINISTIC_RNG)
  58. option(UA_ENABLE_GENERATE_NAMESPACE0 "Generate and load UA XML Namespace 0 definition (experimental)" OFF)
  59. mark_as_advanced(UA_ENABLE_GENERATE_NAMESPACE0)
  60. option(UA_ENABLE_EXTERNAL_NAMESPACES "Enable namespace handling by an external component (experimental)" OFF)
  61. mark_as_advanced(UA_ENABLE_EXTERNAL_NAMESPACES)
  62. option(UA_ENABLE_VALGRIND_UNIT_TESTS "Use Valgrind to detect memory leaks when running the unit tests" OFF)
  63. mark_as_advanced(UA_ENABLE_VALGRIND_UNIT_TESTS)
  64. option(UA_ENABLE_NONSTANDARD_STATELESS "Enable stateless extension (non-standard)" OFF)
  65. mark_as_advanced(UA_ENABLE_NONSTANDARD_STATELESS)
  66. option(UA_ENABLE_NONSTANDARD_UDP "Enable udp extension (non-standard)" OFF)
  67. mark_as_advanced(UA_ENABLE_NONSTANDARD_UDP)
  68. if(UA_ENABLE_NONSTANDARD_UDP)
  69. set(UA_ENABLE_NONSTANDARD_STATELESS ON)
  70. endif()
  71. # Build Targets
  72. option(UA_BUILD_EXAMPLES "Build example servers and clients" OFF)
  73. option(UA_BUILD_UNIT_TESTS "Build the unit tests" OFF)
  74. option(UA_BUILD_EXAMPLES_NODESET_COMPILER "Generate an OPC UA information model from a nodeset XML (experimental)" OFF)
  75. # Advanced Build Targets
  76. option(UA_BUILD_SELFSIGNED_CERTIFICATE "Generate self-signed certificate" OFF)
  77. mark_as_advanced(UA_BUILD_SELFSIGNED_CERTIFICATE)
  78. # Building shared libs (dll, so). This option is written into ua_config.h.
  79. set(UA_DYNAMIC_LINKING OFF)
  80. if(BUILD_SHARED_LIBS)
  81. set(UA_DYNAMIC_LINKING ON)
  82. endif()
  83. # Force compilation with as C++
  84. option(UA_COMPILE_AS_CXX "Force compilation with a C++ compiler" OFF)
  85. mark_as_advanced(UA_COMPILE_AS_CXX)
  86. #####################
  87. # Compiler Settings #
  88. #####################
  89. list(APPEND open62541_LIBRARIES "") # Collect libraries
  90. if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  91. # Compiler
  92. add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat -Wno-unused-parameter
  93. -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare
  94. -Wmultichar -Wstrict-overflow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes
  95. -Winit-self -Wuninitialized -Wformat-security -Wformat-nonliteral)
  96. if(NOT WIN32 AND NOT CYGWIN)
  97. add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
  98. endif()
  99. # Linker
  100. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  101. # Debug
  102. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  103. # add_definitions(-fsanitize=address)
  104. # list(APPEND open62541_LIBRARIES asan)
  105. # add_definitions(-fsanitize=undefined)
  106. # list(APPEND open62541_LIBRARIES ubsan)
  107. endif()
  108. # Strip release builds
  109. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
  110. add_definitions(-ffunction-sections -fdata-sections -fno-stack-protector -fno-unwind-tables
  111. -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
  112. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  113. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  114. if(APPLE)
  115. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
  116. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
  117. else()
  118. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  119. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  120. endif()
  121. if(NOT WIN32 AND NOT CYGWIN AND NOT APPLE)
  122. # these settings reduce the binary size by ~2kb
  123. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  124. endif()
  125. endif()
  126. endif()
  127. if(APPLE)
  128. set(CMAKE_MACOSX_RPATH 1)
  129. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
  130. endif()
  131. if(MSVC)
  132. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") # Compiler warnings, error on warning
  133. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  134. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  135. endif()
  136. #########################
  137. # Generate Main Library #
  138. #########################
  139. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  140. configure_file("include/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  141. include_directories(${PROJECT_BINARY_DIR}/src_generated
  142. ${PROJECT_SOURCE_DIR}/include
  143. ${PROJECT_SOURCE_DIR}/deps)
  144. set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
  145. ${PROJECT_SOURCE_DIR}/deps/ms_stdint.h
  146. ${PROJECT_SOURCE_DIR}/include/ua_constants.h
  147. ${PROJECT_SOURCE_DIR}/include/ua_types.h
  148. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  149. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  150. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
  151. ${PROJECT_SOURCE_DIR}/include/ua_connection.h
  152. ${PROJECT_SOURCE_DIR}/include/ua_job.h
  153. ${PROJECT_SOURCE_DIR}/include/ua_log.h
  154. ${PROJECT_SOURCE_DIR}/include/ua_server.h
  155. ${PROJECT_SOURCE_DIR}/include/ua_server_external_ns.h
  156. ${PROJECT_SOURCE_DIR}/include/ua_client.h
  157. ${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
  158. ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.h
  159. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.h
  160. ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h)
  161. set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
  162. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
  163. ${PROJECT_SOURCE_DIR}/deps/libc_time.h
  164. ${PROJECT_SOURCE_DIR}/src/ua_util.h
  165. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  166. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  167. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  168. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_handling.h
  169. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  170. ${PROJECT_SOURCE_DIR}/src/ua_connection_internal.h
  171. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  172. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
  173. ${PROJECT_SOURCE_DIR}/src/ua_session.h
  174. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  175. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
  176. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  177. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  178. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  179. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
  180. ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h)
  181. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  182. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  183. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  184. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  185. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  186. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  187. ${PROJECT_SOURCE_DIR}/src/ua_session.c
  188. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  189. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  190. ${PROJECT_SOURCE_DIR}/src/server/ua_server_utils.c
  191. ${PROJECT_SOURCE_DIR}/src/server/ua_server_worker.c
  192. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.c
  193. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.c
  194. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
  195. # nodestores
  196. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c
  197. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c
  198. # services
  199. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery.c
  200. ${PROJECT_SOURCE_DIR}/src/server/ua_services_securechannel.c
  201. ${PROJECT_SOURCE_DIR}/src/server/ua_services_session.c
  202. ${PROJECT_SOURCE_DIR}/src/server/ua_services_attribute.c
  203. ${PROJECT_SOURCE_DIR}/src/server/ua_services_nodemanagement.c
  204. ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
  205. # method call
  206. ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c
  207. # subscriptions
  208. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
  209. ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
  210. # client
  211. ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
  212. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
  213. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c
  214. # plugins and dependencies
  215. ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
  216. ${PROJECT_SOURCE_DIR}/plugins/ua_clock.c
  217. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
  218. ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
  219. ${PROJECT_SOURCE_DIR}/deps/libc_time.c
  220. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
  221. ##TODO: make client stuff optional
  222. if(UA_ENABLE_EMBEDDED_LIBC)
  223. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/libc_string.c)
  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. if(UA_ENABLE_NONSTANDARD_UDP)
  232. list(APPEND exported_headers ${PROJECT_SOURCE_DIR}/plugins/ua_network_udp.h)
  233. endif()
  234. #########################
  235. # Generate source files #
  236. #########################
  237. # standard data types
  238. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  239. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  240. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
  241. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  242. PRE_BUILD
  243. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  244. --typedescriptions ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv
  245. --selected_types=${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt
  246. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_types
  247. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  248. ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt
  249. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  250. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  251. # transport data types
  252. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  253. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  254. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_handling.h
  255. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  256. PRE_BUILD
  257. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  258. --namespace=1 --selected_types=${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt
  259. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  260. ${PROJECT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd
  261. ${PROJECT_BINARY_DIR}/src_generated/ua_transport
  262. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  263. ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt
  264. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd)
  265. # nodeids
  266. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  267. PRE_BUILD
  268. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeids.py
  269. ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids
  270. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
  271. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  272. # statuscode explanation
  273. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_statuscode_descriptions.c
  274. PRE_BUILD
  275. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_statuscode_descriptions.py
  276. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.StatusCodes.csv ${PROJECT_BINARY_DIR}/src_generated/ua_statuscode_descriptions
  277. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_statuscode_descriptions.py
  278. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.StatusCodes.csv)
  279. list(APPEND lib_sources ${PROJECT_BINARY_DIR}/src_generated/ua_statuscode_descriptions.c)
  280. # generated namespace 0
  281. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c
  282. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h
  283. PRE_BUILD
  284. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  285. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_AssumeExternal.txt
  286. -s description -b ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist.txt
  287. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  288. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated
  289. DEPENDS ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  290. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  291. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  292. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  293. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  294. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  295. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py)
  296. # single-file release
  297. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  298. PRE_BUILD
  299. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  300. ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
  301. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  302. ${exported_headers}
  303. ${internal_headers})
  304. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  305. PRE_BUILD
  306. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  307. ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c ${internal_headers} ${lib_sources}
  308. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers} ${lib_sources})
  309. ADD_CUSTOM_TARGET(open625451_amalgamation DEPENDS ${PROJECT_BINARY_DIR}/open62541.h
  310. ${PROJECT_BINARY_DIR}/open62541.c)
  311. # example information model from nodeset xml
  312. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
  313. PRE_BUILD
  314. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  315. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  316. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml
  317. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml
  318. ${PROJECT_BINARY_DIR}/src_generated/nodeset
  319. DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  320. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  321. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  322. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  323. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  324. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
  325. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  326. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
  327. #####################
  328. # Build the Library #
  329. #####################
  330. if(UA_ENABLE_AMALGAMATION)
  331. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  332. target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
  333. if(UA_COMPILE_AS_CXX)
  334. set_source_files_properties(${PROJECT_BINARY_DIR}/open62541.c PROPERTIES LANGUAGE CXX)
  335. endif()
  336. else()
  337. add_definitions(-DUA_NO_AMALGAMATION)
  338. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  339. target_include_directories(open62541-object PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/plugins)
  340. if(UA_COMPILE_AS_CXX)
  341. set_source_files_properties(${lib_sources} PROPERTIES LANGUAGE CXX)
  342. endif()
  343. endif()
  344. add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
  345. target_link_libraries(open62541 ${open62541_LIBRARIES})
  346. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  347. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  348. # Generate properly versioned shared library links on Linux
  349. SET_TARGET_PROPERTIES(open62541 PROPERTIES SOVERSION 0 VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")
  350. if(WIN32)
  351. target_link_libraries(open62541 ws2_32)
  352. endif()
  353. ##########################
  354. # Build Selected Targets #
  355. ##########################
  356. # always include, builds with make doc
  357. add_subdirectory(doc)
  358. if(UA_BUILD_EXAMPLES)
  359. add_subdirectory(examples)
  360. endif()
  361. if(UA_BUILD_UNIT_TESTS)
  362. target_compile_definitions(open62541-object PRIVATE UA_BUILD_UNIT_TESTS) # Export some internal functions
  363. enable_testing()
  364. add_subdirectory(tests)
  365. endif()
  366. if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
  367. add_custom_target(generate_informationmodel ALL
  368. DEPENDS ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c)
  369. endif()
  370. ############################
  371. # Linting run (clang-tidy) #
  372. ############################
  373. find_package(ClangTools)
  374. add_custom_target(lint ${CLANG_TIDY_PROGRAM}
  375. ${lib_sources}
  376. -checks=cert-*,performance-*,readability-*,-readability-braces-around-statements
  377. -warnings-as-errors=cert-*,performance-*,readability-*,-readability-braces-around-statements
  378. --
  379. -std=c99
  380. -I${PROJECT_SOURCE_DIR}/include
  381. -I${PROJECT_SOURCE_DIR}/plugins
  382. -I${PROJECT_SOURCE_DIR}/deps
  383. -I${PROJECT_SOURCE_DIR}/src
  384. -I${PROJECT_SOURCE_DIR}/src/server
  385. -I${PROJECT_SOURCE_DIR}/src/client
  386. -I${PROJECT_BINARY_DIR}/src_generated
  387. DEPENDS ${lib_sources}
  388. COMMENT "Run clang-tidy on the library")
  389. add_dependencies(lint open62541)
  390. ##########################
  391. # Installation #
  392. ##########################
  393. # invoke via `make install`
  394. # specify install location with `-DCMAKE_INSTALL_PREFIX=xyz`
  395. # Enable shared library with `-DBUILD_SHARED_LIBS=ON`
  396. # export library (either static or shared depending on BUILD_SHARED_LIBS)
  397. install(TARGETS open62541
  398. LIBRARY DESTINATION lib
  399. ARCHIVE DESTINATION lib)
  400. # export amalgamated header open62541.h which is generated due to build of open62541-object
  401. install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include)
  402. ##########################
  403. # Packaging (DEB/RPM) #
  404. ##########################
  405. # invoke via `make package`
  406. set(CPACK_GENERATOR "TGZ;DEB;RPM")
  407. set(CPACK_PACKAGE_VENDOR "open62541 team")
  408. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OPC UA implementation")
  409. set(CPACK_PACKAGE_DESCRIPTION "open62541 is a C-based library (linking with C++ projects is possible) with all necessary tools to implement dedicated OPC UA clients and servers, or to integrate OPC UA-based communication into existing applications.")
  410. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  411. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  412. set(CPACK_PACKAGE_VERSION_MAJOR "0")
  413. set(CPACK_PACKAGE_VERSION_MINOR "2")
  414. set(CPACK_PACKAGE_VERSION_PATCH "0")
  415. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "open62541 team") #required
  416. include(CPack)