CMakeLists.txt 25 KB

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