CMakeLists.txt 23 KB

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