CMakeLists.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. #########################
  223. # Generate source files #
  224. #########################
  225. # standard data types
  226. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  227. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  228. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
  229. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_encoding_binary.h
  230. PRE_BUILD
  231. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  232. --typedescriptions ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv
  233. --selected_types=${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt
  234. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_types
  235. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  236. ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt
  237. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  238. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  239. # transport data types
  240. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.c
  241. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated.h
  242. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_handling.h
  243. ${PROJECT_BINARY_DIR}/src_generated/ua_transport_generated_encoding_binary.h
  244. PRE_BUILD
  245. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  246. --namespace=1 --selected_types=${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt
  247. ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd
  248. ${PROJECT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd
  249. ${PROJECT_BINARY_DIR}/src_generated/ua_transport
  250. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_datatypes.py
  251. ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt
  252. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd)
  253. # nodeids
  254. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
  255. PRE_BUILD
  256. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeids.py
  257. ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids
  258. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_nodeids.py
  259. ${CMAKE_CURRENT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  260. # generated namespace 0
  261. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.c
  262. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated.h
  263. PRE_BUILD
  264. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  265. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_AssumeExternal.txt
  266. -s description -b ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist.txt
  267. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  268. ${PROJECT_BINARY_DIR}/src_generated/ua_namespaceinit_generated
  269. DEPENDS ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/${GENERATE_NAMESPACE0_FILE}
  270. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  271. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  272. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  273. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  274. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  275. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py)
  276. # single-file release
  277. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  278. PRE_BUILD
  279. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  280. ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
  281. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  282. ${exported_headers}
  283. ${internal_headers})
  284. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  285. PRE_BUILD
  286. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  287. ${GIT_COMMIT_ID} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c ${internal_headers}
  288. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources}
  289. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers}
  290. ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_hash.inc ${lib_sources})
  291. # example information model from nodeset xml
  292. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
  293. PRE_BUILD
  294. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  295. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  296. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml
  297. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml
  298. ${PROJECT_BINARY_DIR}/src_generated/nodeset
  299. DEPENDS ${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. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  306. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
  307. #####################
  308. # Build the Library #
  309. #####################
  310. if(UA_ENABLE_AMALGAMATION)
  311. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  312. target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
  313. else()
  314. add_definitions(-DUA_NO_AMALGAMATION)
  315. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  316. target_include_directories(open62541-object PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src
  317. ${PROJECT_SOURCE_DIR}/plugins ${PROJECT_SOURCE_DIR}/deps)
  318. endif()
  319. add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
  320. target_link_libraries(open62541 ${open62541_LIBRARIES})
  321. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  322. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  323. if(WIN32)
  324. target_link_libraries(open62541 ws2_32)
  325. endif()
  326. ##########################
  327. # Build Selected Targets #
  328. ##########################
  329. if(UA_BUILD_EXAMPLES)
  330. add_subdirectory(examples)
  331. endif()
  332. if(UA_BUILD_UNIT_TESTS)
  333. target_compile_definitions(open62541-object PRIVATE UA_BUILD_UNIT_TESTS) # Export some internal functions
  334. enable_testing()
  335. add_subdirectory(tests)
  336. endif()
  337. if(UA_BUILD_DOCUMENTATION)
  338. add_subdirectory(doc)
  339. endif()
  340. if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
  341. add_custom_target(generate_informationmodel ALL
  342. DEPENDS ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c)
  343. endif()
  344. ##########################
  345. # Installation #
  346. ##########################
  347. # invoke via `make install`
  348. # specify install location with `-DCMAKE_INSTALL_PREFIX=xyz`
  349. # Enable shared library with `-DBUILD_SHARED_LIBS=ON`
  350. # export library (either static or shared depending on BUILD_SHARED_LIBS)
  351. install(TARGETS open62541
  352. LIBRARY DESTINATION lib
  353. ARCHIVE DESTINATION lib
  354. )
  355. # export amalgamated header open62541.h which is generated due to build of open62541-object
  356. install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include)
  357. ##########################
  358. # Packaging (DEB/RPM) #
  359. ##########################
  360. # invoke via `make package`
  361. SET(CPACK_GENERATOR "TGZ;DEB;RPM")
  362. SET(CPACK_PACKAGE_VENDOR "open62541 team")
  363. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OPC UA implementation")
  364. 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.")
  365. SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  366. SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  367. SET(CPACK_PACKAGE_VERSION_MAJOR "0")
  368. SET(CPACK_PACKAGE_VERSION_MINOR "2")
  369. SET(CPACK_PACKAGE_VERSION_PATCH "0")
  370. SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "open62541 team") #required
  371. INCLUDE(CPack)