CMakeLists.txt 25 KB

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