CMakeLists.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. cmake_minimum_required(VERSION 3.0)
  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_BINARY_DIR}/bin)
  11. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  12. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_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_EXAMPLES_NODESET_COMPILER "Generate an OPC UA information model from a nodeset XML (experimental)" OFF)
  86. # Advanced Build Targets
  87. option(UA_BUILD_SELFSIGNED_CERTIFICATE "Generate self-signed certificate" OFF)
  88. mark_as_advanced(UA_BUILD_SELFSIGNED_CERTIFICATE)
  89. # Building shared libs (dll, so). This option is written into ua_config.h.
  90. set(UA_DYNAMIC_LINKING OFF)
  91. if(BUILD_SHARED_LIBS)
  92. set(UA_DYNAMIC_LINKING ON)
  93. endif()
  94. # Force compilation with as C++
  95. option(UA_COMPILE_AS_CXX "Force compilation with a C++ compiler" OFF)
  96. mark_as_advanced(UA_COMPILE_AS_CXX)
  97. #####################
  98. # Compiler Settings #
  99. #####################
  100. list(APPEND open62541_LIBRARIES "") # Collect libraries
  101. if(NOT UA_COMPILE_AS_CXX AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang"))
  102. # Compiler
  103. add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat -Wno-unused-parameter
  104. -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare
  105. -Wmultichar -Wstrict-overflow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes
  106. -Winit-self -Wuninitialized -Wformat-security -Wformat-nonliteral)
  107. if(NOT WIN32 AND NOT CYGWIN)
  108. add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
  109. endif()
  110. # Linker
  111. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  112. # Debug
  113. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  114. # add_definitions(-fsanitize=address)
  115. # list(APPEND open62541_LIBRARIES asan)
  116. # add_definitions(-fsanitize=undefined)
  117. # list(APPEND open62541_LIBRARIES ubsan)
  118. endif()
  119. # Strip release builds
  120. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
  121. add_definitions(-ffunction-sections -fdata-sections -fno-stack-protector -fno-unwind-tables
  122. -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
  123. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  124. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  125. if(APPLE)
  126. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
  127. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
  128. else()
  129. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  130. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  131. endif()
  132. if(NOT WIN32 AND NOT CYGWIN AND NOT APPLE)
  133. # these settings reduce the binary size by ~2kb
  134. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  135. endif()
  136. endif()
  137. endif()
  138. if(APPLE)
  139. set(CMAKE_MACOSX_RPATH 1)
  140. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
  141. endif()
  142. if(MSVC)
  143. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") # Compiler warnings, error on warning
  144. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  145. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  146. endif()
  147. #########################
  148. # Generate Main Library #
  149. #########################
  150. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  151. configure_file("include/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  152. include_directories(${PROJECT_BINARY_DIR}/src_generated
  153. ${PROJECT_SOURCE_DIR}/include
  154. ${PROJECT_SOURCE_DIR}/deps)
  155. set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
  156. ${PROJECT_SOURCE_DIR}/deps/ms_stdint.h
  157. ${PROJECT_SOURCE_DIR}/include/ua_constants.h
  158. ${PROJECT_SOURCE_DIR}/include/ua_types.h
  159. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  160. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  161. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
  162. ${PROJECT_SOURCE_DIR}/include/ua_connection.h
  163. ${PROJECT_SOURCE_DIR}/include/ua_job.h
  164. ${PROJECT_SOURCE_DIR}/include/ua_log.h
  165. ${PROJECT_SOURCE_DIR}/include/ua_server.h
  166. ${PROJECT_SOURCE_DIR}/include/ua_client.h
  167. ${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
  168. ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.h
  169. ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.h
  170. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.h
  171. ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h
  172. )
  173. set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
  174. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
  175. ${PROJECT_SOURCE_DIR}/deps/libc_time.h
  176. ${PROJECT_SOURCE_DIR}/src/ua_util.h
  177. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  178. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  179. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  180. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_handling.h
  181. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  182. ${PROJECT_SOURCE_DIR}/src/ua_connection_internal.h
  183. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  184. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
  185. ${PROJECT_SOURCE_DIR}/src/ua_session.h
  186. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  187. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
  188. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  189. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  190. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  191. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
  192. ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h
  193. )
  194. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  195. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  196. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  197. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  198. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  199. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  200. ${PROJECT_SOURCE_DIR}/src/ua_session.c
  201. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  202. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  203. ${PROJECT_SOURCE_DIR}/src/server/ua_server_utils.c
  204. ${PROJECT_SOURCE_DIR}/src/server/ua_server_worker.c
  205. ${PROJECT_SOURCE_DIR}/src/server/ua_server_timer.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. # always include, builds with make doc
  379. add_subdirectory(doc)
  380. if(UA_BUILD_EXAMPLES)
  381. add_subdirectory(examples)
  382. endif()
  383. if(UA_BUILD_UNIT_TESTS)
  384. target_compile_definitions(open62541-object PRIVATE UA_BUILD_UNIT_TESTS) # Export some internal functions
  385. enable_testing()
  386. add_subdirectory(tests)
  387. endif()
  388. if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
  389. add_custom_target(generate_informationmodel ALL
  390. DEPENDS ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c)
  391. endif()
  392. ############################
  393. # Linting run (clang-tidy) #
  394. ############################
  395. find_package(ClangTools)
  396. add_custom_target(lint ${CLANG_TIDY_PROGRAM}
  397. ${lib_sources}
  398. -checks=cert-*,performance-*,readability-*,-readability-braces-around-statements
  399. -warnings-as-errors=cert-*,performance-*,readability-*,-readability-braces-around-statements
  400. --
  401. -std=c99
  402. -I${PROJECT_SOURCE_DIR}/include
  403. -I${PROJECT_SOURCE_DIR}/plugins
  404. -I${PROJECT_SOURCE_DIR}/deps
  405. -I${PROJECT_SOURCE_DIR}/src
  406. -I${PROJECT_SOURCE_DIR}/src/server
  407. -I${PROJECT_SOURCE_DIR}/src/client
  408. -I${PROJECT_BINARY_DIR}/src_generated
  409. DEPENDS ${lib_sources}
  410. COMMENT "Run clang-tidy on the library")
  411. add_dependencies(lint open62541)
  412. ##########################
  413. # Installation #
  414. ##########################
  415. # invoke via `make install`
  416. # specify install location with `-DCMAKE_INSTALL_PREFIX=xyz`
  417. # Enable shared library with `-DBUILD_SHARED_LIBS=ON`
  418. set(cmake_configfile_install lib/cmake)
  419. set(target_install_dest_name "${cmake_configfile_install}/open62541Targets.cmake")
  420. set(open62541_tools_dir share/open62541/tools)
  421. set(open62541_deps_dir include/open62541/deps)
  422. # export library (either static or shared depending on BUILD_SHARED_LIBS)
  423. install(TARGETS open62541
  424. EXPORT open62541Targets
  425. LIBRARY DESTINATION lib
  426. ARCHIVE DESTINATION lib
  427. INCLUDES DESTINATION include/open62541 ${open62541_deps_dir})
  428. include(CMakePackageConfigHelpers)
  429. configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/open62541-config.cmake.in"
  430. "${CMAKE_CURRENT_BINARY_DIR}/cmake/open62541-config.cmake"
  431. INSTALL_DESTINATION "${cmake_configfile_install}"
  432. PATH_VARS target_install_dest_name open62541_tools_dir)
  433. set(open62541_VERSION)
  434. get_target_property(open62541_VERSION open62541 VERSION)
  435. write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/open62541ConfigVersion.cmake"
  436. VERSION ${open62541_VERSION}
  437. COMPATIBILITY AnyNewerVersion)
  438. install(EXPORT open62541Targets
  439. FILE open62541Targets.cmake
  440. DESTINATION "${cmake_configfile_install}")
  441. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/open62541-config.cmake"
  442. "${CMAKE_CURRENT_BINARY_DIR}/open62541ConfigVersion.cmake"
  443. DESTINATION "${cmake_configfile_install}")
  444. # export amalgamated header open62541.h which is generated due to build of open62541-object
  445. install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include/open62541)
  446. install(DIRECTORY deps/ DESTINATION ${open62541_deps_dir})
  447. install(DIRECTORY tools/ DESTINATION ${open62541_tools_dir} USE_SOURCE_PERMISSIONS)
  448. ##########################
  449. # Packaging (DEB/RPM) #
  450. ##########################
  451. # invoke via `make package`
  452. set(CPACK_GENERATOR "TGZ;DEB;RPM")
  453. set(CPACK_PACKAGE_VENDOR "open62541 team")
  454. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OPC UA implementation")
  455. 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.")
  456. set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  457. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  458. set(CPACK_PACKAGE_VERSION_MAJOR "0")
  459. set(CPACK_PACKAGE_VERSION_MINOR "2")
  460. set(CPACK_PACKAGE_VERSION_PATCH "0")
  461. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "open62541 team") #required
  462. include(CPack)
  463. ##################################
  464. # Visual studio solution folders #
  465. ##################################
  466. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  467. set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_CmakePredifinedTargets")
  468. set_target_properties(open62541 PROPERTIES FOLDER "open62541/lib")
  469. set_target_properties(open62541-object PROPERTIES FOLDER "open62541/lib")
  470. set_target_properties(lint PROPERTIES FOLDER "CodeAnalysis")