CMakeLists.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. cmake_minimum_required(VERSION 2.8.11)
  2. project(open62541 C)
  3. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/tools/cmake")
  4. # set(CMAKE_VERBOSE_MAKEFILE ON)
  5. ######################
  6. # Check Dependencies #
  7. ######################
  8. find_package(PythonInterp REQUIRED)
  9. find_package(Git)
  10. if(GIT_FOUND)
  11. execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --tags
  12. RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_COM_ID WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
  13. execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --always --tags
  14. RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_REL_ID WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
  15. if(NOT ${res_var} EQUAL 0)
  16. set(GIT_COMMIT_ID "commit id unknown")
  17. set(GIT_RELEASE_ID "release unknown")
  18. message(STATUS "Git failed (not a repo, or no tags). Build will not contain git revision info." )
  19. else()
  20. string(REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COM_ID} )
  21. string(REPLACE "\n" "" GIT_RELEASE_ID ${GIT_REL_ID} )
  22. endif()
  23. else()
  24. set(GIT_COMMIT_ID "commit id unknown")
  25. set(GIT_RELEASE_ID "release unknown")
  26. message(STATUS "Git not found. Build will not contain git revision info." )
  27. endif()
  28. message(STATUS "Git version: " ${GIT_COMMIT_ID})
  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_MULTITHREADING "Enable multithreading" OFF)
  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")
  50. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  51. endif()
  52. # Advanced options
  53. option(UA_ENABLE_TYPENAMES "Add the type and member names to the UA_DataType structure" OFF)
  54. mark_as_advanced(UA_ENABLE_TYPENAMES)
  55. 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)
  56. mark_as_advanced(UA_ENABLE_EMBEDDED_LIBC)
  57. option(UA_ENABLE_GENERATE_NAMESPACE0 "Generate and load UA XML Namespace 0 definition (experimental)" OFF)
  58. mark_as_advanced(UA_ENABLE_GENERATE_NAMESPACE0)
  59. option(UA_ENABLE_EXTERNAL_NAMESPACES "Enable namespace handling by an external component (experimental)" OFF)
  60. mark_as_advanced(UA_ENABLE_EXTERNAL_NAMESPACES)
  61. option(UA_ENABLE_NONSTANDARD_STATELESS "Enable stateless extension" OFF)
  62. mark_as_advanced(UA_ENABLE_NONSTANDARD_STATELESS)
  63. option(UA_ENABLE_NONSTANDARD_UDP "Enable udp extension" OFF)
  64. mark_as_advanced(UA_ENABLE_NONSTANDARD_UDP)
  65. if(UA_ENABLE_NONSTANDARD_UDP)
  66. set(UA_ENABLE_NONSTANDARD_STATELESS ON)
  67. endif()
  68. # Build Targets
  69. option(UA_BUILD_EXAMPLES "Build example servers and clients" OFF)
  70. option(UA_BUILD_UNIT_TESTS "Build the unit tests" OFF)
  71. option(UA_BUILD_DOCUMENTATION "Generate doxygen/sphinx documentation" 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. # Building shared libs (dll, so). This option is written into ua_config.h.
  76. set(UA_DYNAMIC_LINKING OFF)
  77. if(BUILD_SHARED_LIBS)
  78. set(UA_DYNAMIC_LINKING ON)
  79. endif()
  80. #####################
  81. # Compiler Settings #
  82. #####################
  83. list(APPEND open62541_LIBRARIES "") # Collect libraries
  84. if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  85. # Compiler
  86. add_definitions(-std=c99 -pipe -Wall -Wextra -Werror -Wformat -Wno-unused-parameter
  87. -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare
  88. -Wmultichar -Wstrict-overflow -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes
  89. -Winit-self -Wuninitialized -Wformat-security -Wformat-nonliteral)
  90. if(NOT WIN32 AND NOT CYGWIN)
  91. add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
  92. endif()
  93. # Linker
  94. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  95. # Debug
  96. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  97. # add_definitions(-fsanitize=address)
  98. # list(APPEND open62541_LIBRARIES asan)
  99. # add_definitions(-fsanitize=undefined)
  100. # list(APPEND open62541_LIBRARIES ubsan)
  101. endif()
  102. # Strip release builds
  103. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
  104. add_definitions(-ffunction-sections -fdata-sections -fno-stack-protector -fno-unwind-tables
  105. -fno-asynchronous-unwind-tables -fno-math-errno -fmerge-all-constants -fno-ident)
  106. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  107. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  108. if(APPLE)
  109. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
  110. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
  111. else()
  112. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  113. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  114. endif()
  115. if(NOT WIN32 AND NOT CYGWIN AND NOT APPLE)
  116. # these settings reduce the binary size by ~2kb
  117. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  118. endif()
  119. endif()
  120. endif()
  121. if(APPLE)
  122. set(CMAKE_MACOSX_RPATH 1)
  123. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
  124. endif()
  125. if(MSVC)
  126. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX") # Compiler warnings, error on warning
  127. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
  128. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
  129. endif()
  130. #########################
  131. # Generate Main Library #
  132. #########################
  133. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  134. configure_file("include/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  135. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  136. set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
  137. ${PROJECT_SOURCE_DIR}/include/ua_constants.h
  138. ${PROJECT_SOURCE_DIR}/include/ua_types.h
  139. ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  140. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  141. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
  142. ${PROJECT_SOURCE_DIR}/include/ua_connection.h
  143. ${PROJECT_SOURCE_DIR}/include/ua_job.h
  144. ${PROJECT_SOURCE_DIR}/include/ua_log.h
  145. ${PROJECT_SOURCE_DIR}/include/ua_server.h
  146. ${PROJECT_SOURCE_DIR}/include/ua_server_external_ns.h
  147. ${PROJECT_SOURCE_DIR}/include/ua_client.h
  148. ${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
  149. ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.h
  150. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.h
  151. ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h)
  152. set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
  153. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
  154. ${PROJECT_SOURCE_DIR}/deps/libc_time.h
  155. ${PROJECT_SOURCE_DIR}/src/ua_util.h
  156. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  157. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  158. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  159. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_handling.h
  160. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  161. ${PROJECT_SOURCE_DIR}/src/ua_connection_internal.h
  162. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  163. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
  164. ${PROJECT_SOURCE_DIR}/src/ua_session.h
  165. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  166. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
  167. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  168. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  169. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  170. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
  171. ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h)
  172. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  173. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  174. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  175. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  176. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  177. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  178. ${PROJECT_SOURCE_DIR}/src/ua_session.c
  179. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  180. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  181. ${PROJECT_SOURCE_DIR}/src/server/ua_server_utils.c
  182. ${PROJECT_SOURCE_DIR}/src/server/ua_server_worker.c
  183. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.c
  184. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.c
  185. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
  186. # nodestores
  187. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c
  188. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c
  189. # services
  190. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery.c
  191. ${PROJECT_SOURCE_DIR}/src/server/ua_services_securechannel.c
  192. ${PROJECT_SOURCE_DIR}/src/server/ua_services_session.c
  193. ${PROJECT_SOURCE_DIR}/src/server/ua_services_attribute.c
  194. ${PROJECT_SOURCE_DIR}/src/server/ua_services_nodemanagement.c
  195. ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
  196. # method call
  197. ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c
  198. # subscriptions
  199. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
  200. ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
  201. # client
  202. ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
  203. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
  204. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c
  205. # plugins and dependencies
  206. ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
  207. ${PROJECT_SOURCE_DIR}/plugins/ua_clock.c
  208. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
  209. ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
  210. ${PROJECT_SOURCE_DIR}/deps/libc_time.c
  211. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
  212. ##TODO: make client stuff optional
  213. if(UA_ENABLE_EMBEDDED_LIBC)
  214. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/libc_string.c)
  215. endif()
  216. if(UA_ENABLE_GENERATE_NAMESPACE0)
  217. set(GENERATE_NAMESPACE0_FILE "Opc.Ua.NodeSet2.xml" CACHE STRING "Namespace definition XML file")
  218. set_property(CACHE GENERATE_NAMESPACE0_FILE PROPERTY STRINGS Opc.Ua.NodeSet2.xml Opc.Ua.NodeSet2.Minimal.xml)
  219. list(APPEND internal_headers ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h)
  220. list(APPEND lib_sources ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c)
  221. endif()
  222. if(UA_ENABLE_NONSTANDARD_UDP)
  223. list(APPEND exported_headers ${PROJECT_SOURCE_DIR}/plugins/ua_network_udp.h)
  224. endif()
  225. #########################
  226. # Generate source files #
  227. #########################
  228. # standard data types
  229. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  230. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  231. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
  232. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  233. PRE_BUILD
  234. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  235. --typedescriptions ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv
  236. --selected_types=${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt
  237. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_types
  238. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  239. ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt
  240. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  241. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  242. # transport data types
  243. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  244. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  245. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_handling.h
  246. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  247. PRE_BUILD
  248. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  249. --namespace=1 --selected_types=${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt
  250. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  251. ${PROJECT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd
  252. ${PROJECT_BINARY_DIR}/src_generated/ua_transport
  253. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  254. ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt
  255. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd)
  256. # nodeids
  257. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  258. PRE_BUILD
  259. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeids.py
  260. ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids
  261. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
  262. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  263. # generated namespace 0
  264. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c
  265. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h
  266. PRE_BUILD
  267. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  268. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_AssumeExternal.txt
  269. -s description -b ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist.txt
  270. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  271. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated
  272. DEPENDS ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  273. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  274. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  275. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  276. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  277. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  278. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py)
  279. # single-file release
  280. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  281. PRE_BUILD
  282. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  283. ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
  284. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  285. ${exported_headers}
  286. ${internal_headers})
  287. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  288. PRE_BUILD
  289. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  290. ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c ${internal_headers}
  291. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources}
  292. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers}
  293. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
  294. # example information model from nodeset xml
  295. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
  296. PRE_BUILD
  297. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  298. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  299. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml
  300. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml
  301. ${PROJECT_BINARY_DIR}/src_generated/nodeset
  302. DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  303. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  304. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  305. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  306. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  307. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
  308. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  309. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
  310. #####################
  311. # Build the Library #
  312. #####################
  313. if(UA_ENABLE_AMALGAMATION)
  314. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  315. target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
  316. else()
  317. add_definitions(-DUA_NO_AMALGAMATION)
  318. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  319. target_include_directories(open62541-object PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src
  320. ${PROJECT_SOURCE_DIR}/plugins ${PROJECT_SOURCE_DIR}/deps)
  321. endif()
  322. add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
  323. target_link_libraries(open62541 ${open62541_LIBRARIES})
  324. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  325. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  326. if(WIN32)
  327. target_link_libraries(open62541 ws2_32)
  328. endif()
  329. ##########################
  330. # Build Selected Targets #
  331. ##########################
  332. if(UA_BUILD_EXAMPLES)
  333. add_subdirectory(examples)
  334. endif()
  335. if(UA_BUILD_UNIT_TESTS)
  336. target_compile_definitions(open62541-object PRIVATE UA_BUILD_UNIT_TESTS) # Export some internal functions
  337. enable_testing()
  338. add_subdirectory(tests)
  339. endif()
  340. if(UA_BUILD_DOCUMENTATION)
  341. add_subdirectory(doc)
  342. endif()
  343. if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
  344. add_custom_target(generate_informationmodel ALL
  345. DEPENDS ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c)
  346. endif()
  347. ##########################
  348. # Installation #
  349. ##########################
  350. # invoke via `make install`
  351. # specify install location with `-DCMAKE_INSTALL_PREFIX=xyz`
  352. # Enable shared library with `-DBUILD_SHARED_LIBS=ON`
  353. # export library (either static or shared depending on BUILD_SHARED_LIBS)
  354. install(TARGETS open62541
  355. LIBRARY DESTINATION lib
  356. ARCHIVE DESTINATION lib
  357. )
  358. # export amalgamated header open62541.h which is generated due to build of open62541-object
  359. install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include)
  360. ##########################
  361. # Packaging (DEB/RPM) #
  362. ##########################
  363. # invoke via `make package`
  364. SET(CPACK_GENERATOR "TGZ;DEB;RPM")
  365. SET(CPACK_PACKAGE_VENDOR "open62541 team")
  366. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OPC UA implementation")
  367. 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.")
  368. SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  369. SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  370. SET(CPACK_PACKAGE_VERSION_MAJOR "0")
  371. SET(CPACK_PACKAGE_VERSION_MINOR "2")
  372. SET(CPACK_PACKAGE_VERSION_PATCH "0")
  373. SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "open62541 team") #required
  374. INCLUDE(CPack)