CMakeLists.txt 25 KB

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