CMakeLists.txt 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. cmake_minimum_required(VERSION 3.0...3.12)
  2. project(open62541)
  3. # set(CMAKE_VERBOSE_MAKEFILE ON)
  4. if(${CMAKE_VERSION} VERSION_LESS 3.12)
  5. cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
  6. endif()
  7. string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE_LOWER_CASE)
  8. set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/tools/cmake")
  9. find_package(PythonInterp REQUIRED)
  10. find_package(Git)
  11. include(AssignSourceGroup)
  12. include(GNUInstallDirs)
  13. # Set when installed via make install
  14. set(open62541_TOOLS_DIR ${PROJECT_SOURCE_DIR}/tools)
  15. set(open62541_NODESET_DIR ${PROJECT_SOURCE_DIR}/deps/ua-nodeset)
  16. include(macros_internal)
  17. include(macros_public)
  18. #############################
  19. # Compiled binaries folders #
  20. #############################
  21. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  22. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  23. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  24. ###########
  25. # Version #
  26. ###########
  27. include(SetGitBasedVersion)
  28. # The version string will be automatically set based on the git describe output.
  29. # This will automate the version strings. Just create a new tag, and the version will be set correctly.
  30. set_open62541_version()
  31. MESSAGE(STATUS "open62541 Version: ${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}${OPEN62541_VER_LABEL}")
  32. #################
  33. # Build Options #
  34. #################
  35. # Set default build type.
  36. if(NOT CMAKE_BUILD_TYPE)
  37. message(STATUS "CMAKE_BUILD_TYPE not given; setting to 'Debug'")
  38. set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build" FORCE)
  39. endif()
  40. option(UA_ENABLE_AMALGAMATION "Concatenate the library to a single file open62541.h/.c" OFF)
  41. set(UA_AMALGAMATION_ARCHITECTURES "" CACHE STRING "List of architectures to include in amalgamation")
  42. mark_as_advanced(UA_AMALGAMATION_ARCHITECTURES)
  43. # Platform. This is at the beginning in case the architecture changes some UA options
  44. set(UA_ARCHITECTURE "None" CACHE STRING "Architecture to build open62541 on")
  45. if(UA_ENABLE_AMALGAMATION)
  46. if("${UA_AMALGAMATION_ARCHITECTURES}" STREQUAL "")
  47. if(NOT "${UA_ARCHITECTURE}" STREQUAL "None")
  48. set(UA_AMALGAMATION_ARCHITECTURES "${UA_ARCHITECTURE}")
  49. else()
  50. # select some default architectures which should be included
  51. set(UA_AMALGAMATION_ARCHITECTURES "win32;posix")
  52. endif()
  53. endif()
  54. message(STATUS "Architectures included in amalgamation: ${UA_AMALGAMATION_ARCHITECTURES}")
  55. endif()
  56. if("${UA_ARCHITECTURE}" STREQUAL "None")
  57. if(UNIX)
  58. set(UA_ARCHITECTURE "posix" CACHE STRING "" FORCE)
  59. elseif(WIN32)
  60. set(UA_ARCHITECTURE "win32" CACHE STRING "" FORCE)
  61. endif(UNIX)
  62. endif()
  63. message(STATUS "The selected architecture is: ${UA_ARCHITECTURE}")
  64. string(TOUPPER ${UA_ARCHITECTURE} UA_ARCHITECTURE_UPPER)
  65. add_definitions(-DUA_ARCHITECTURE_${UA_ARCHITECTURE_UPPER})
  66. add_subdirectory(arch)
  67. GET_PROPERTY(architectures GLOBAL PROPERTY UA_ARCHITECTURES)
  68. list(SORT architectures)
  69. set_property(CACHE UA_ARCHITECTURE PROPERTY STRINGS None ${architectures})
  70. GET_PROPERTY(ua_architecture_directories_to_include GLOBAL PROPERTY UA_INCLUDE_DIRECTORIES)
  71. GET_PROPERTY(ua_architecture_headers GLOBAL PROPERTY UA_ARCHITECTURE_HEADERS)
  72. GET_PROPERTY(ua_architecture_headers_beginning GLOBAL PROPERTY UA_ARCHITECTURE_HEADERS_BEGINNING)
  73. GET_PROPERTY(ua_architecture_sources GLOBAL PROPERTY UA_ARCHITECTURE_SOURCES)
  74. set(ua_architecture_sources ${ua_architecture_sources}
  75. ${PROJECT_SOURCE_DIR}/arch/network_tcp.c
  76. )
  77. set(ua_architecture_headers ${ua_architecture_headers}
  78. ${PROJECT_SOURCE_DIR}/include/open62541/network_tcp.h
  79. ${PROJECT_SOURCE_DIR}/include/open62541/architecture_functions.h
  80. )
  81. if(UA_ENABLE_WEBSOCKET_SERVER)
  82. set(ua_architecture_sources ${ua_architecture_sources}
  83. ${PROJECT_SOURCE_DIR}/arch/network_ws.c)
  84. set(ua_architecture_headers ${ua_architecture_headers}
  85. ${PROJECT_SOURCE_DIR}/include/open62541/network_ws.h)
  86. endif()
  87. if(${UA_ARCHITECTURE} STREQUAL "None")
  88. message(FATAL_ERROR "No architecture was selected. Please select the architecture of your target platform")
  89. endif(${UA_ARCHITECTURE} STREQUAL "None")
  90. # Create a list of ifdefs for all the architectures.
  91. # This is needed to enable a default architecture if none is selected through gcc compiler def.
  92. # Especially if someone is using the amalgamated file on Linux/Windows he should not need to define an architecture.
  93. set(UA_ARCHITECTURES_NODEF "1 ") #to make it easier to append later the && symbol
  94. foreach(arch_ ${architectures})
  95. string(TOUPPER ${arch_} UA_ARCHITECTURE_UPPER_)
  96. set(UA_ARCHITECTURES_NODEF "${UA_ARCHITECTURES_NODEF} && !defined(UA_ARCHITECTURE_${UA_ARCHITECTURE_UPPER_})")
  97. endforeach(arch_ ${architectures})
  98. # Options
  99. set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
  100. option(UA_ENABLE_HISTORIZING "Enable server and client to provide historical access." OFF)
  101. option(UA_ENABLE_METHODCALLS "Enable the Method service set" ON)
  102. option(UA_ENABLE_NODEMANAGEMENT "Enable dynamic addition and removal of nodes at runtime" ON)
  103. option(UA_ENABLE_SUBSCRIPTIONS "Enable subscriptions support." ON)
  104. option(UA_ENABLE_SUBSCRIPTIONS_EVENTS "Enable the use of event subscriptions" OFF)
  105. option(UA_ENABLE_DISCOVERY "Enable Discovery Service (LDS)" ON)
  106. option(UA_ENABLE_DISCOVERY_MULTICAST "Enable Discovery Service with multicast support (LDS-ME)" OFF)
  107. option(UA_ENABLE_ENCRYPTION "Enable encryption support (uses mbedTLS)" OFF)
  108. option(UA_ENABLE_MICRO_EMB_DEV_PROFILE "Builds CTT Compliant Micro Embedded Device Server Profile" OFF)
  109. option(BUILD_SHARED_LIBS "Enable building of shared libraries (dll/so)" OFF)
  110. option(UA_ENABLE_WEBSOCKET_SERVER "Enable websocket support (uses libwebsockets)" OFF)
  111. # Namespace Zero
  112. set(UA_NAMESPACE_ZERO "REDUCED" CACHE STRING "Completeness of the generated namespace zero (minimal/reduced/full)")
  113. SET_PROPERTY(CACHE UA_NAMESPACE_ZERO PROPERTY STRINGS "MINIMAL" "REDUCED" "FULL")
  114. if(UA_NAMESPACE_ZERO STREQUAL "MINIMAL")
  115. set(UA_GENERATED_NAMESPACE_ZERO OFF)
  116. else()
  117. set(UA_GENERATED_NAMESPACE_ZERO ON)
  118. endif()
  119. if(MSVC AND UA_NAMESPACE_ZERO STREQUAL "FULL")
  120. # For the full NS0 we need a stack size of 8MB (as it is default on linux)
  121. # See https://github.com/open62541/open62541/issues/1326
  122. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:8000000")
  123. endif()
  124. if(UA_ENABLE_MICRO_EMB_DEV_PROFILE)
  125. if(NOT (UA_NAMESPACE_ZERO STREQUAL "FULL"))
  126. message(FATAL_ERROR "CTT Compliant Micro Embedded Device Server Profile needs full namespace zero")
  127. endif()
  128. endif()
  129. if(UA_BUILD_FUZZING OR UA_BUILD_OSS_FUZZ OR UA_BUILD_FUZZING_CORPUS)
  130. # Force enable options not passed in the build script, to also fuzzy-test this code
  131. set(UA_ENABLE_DISCOVERY ON CACHE STRING "" FORCE)
  132. set(UA_ENABLE_DISCOVERY_MULTICAST ON CACHE STRING "" FORCE)
  133. set(UA_ENABLE_ENCRYPTION ON CACHE STRING "" FORCE)
  134. set(UA_ENABLE_HISTORIZING ON CACHE STRING "" FORCE)
  135. set(UA_ENABLE_JSON_ENCODING ON CACHE STRING "" FORCE)
  136. set(UA_ENABLE_SUBSCRIPTIONS ON CACHE STRING "" FORCE)
  137. set(UA_ENABLE_SUBSCRIPTIONS_EVENTS ON CACHE STRING "" FORCE)
  138. endif()
  139. # It should not be possible to enable events without enabling subscriptions and full ns0
  140. #if((UA_ENABLE_SUBSCRIPTIONS_EVENTS) AND (NOT (UA_ENABLE_SUBSCRIPTIONS AND UA_NAMESPACE_ZERO STREQUAL "FULL")))
  141. # message(FATAL_ERROR "Unable to enable events without UA_ENABLE_SUBSCRIPTIONS and full namespace 0")
  142. #endif()
  143. if(UA_ENABLE_COVERAGE)
  144. set(CMAKE_BUILD_TYPE DEBUG)
  145. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
  146. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
  147. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  148. endif()
  149. if(UA_ENABLE_DISCOVERY_MULTICAST AND NOT UA_ENABLE_DISCOVERY)
  150. MESSAGE(WARNING "UA_ENABLE_DISCOVERY_MULTICAST is enabled, but not UA_ENABLE_DISCOVERY. UA_ENABLE_DISCOVERY_MULTICAST will be set to OFF")
  151. SET(UA_ENABLE_DISCOVERY_MULTICAST OFF CACHE BOOL "Enable Discovery Service with multicast support (LDS-ME)" FORCE)
  152. endif()
  153. # Advanced options
  154. option(UA_ENABLE_COVERAGE "Enable gcov coverage" OFF)
  155. mark_as_advanced(UA_ENABLE_COVERAGE)
  156. option(UA_ENABLE_QUERY "Enable query support in the client (most servers don't support it)" OFF)
  157. mark_as_advanced(UA_ENABLE_QUERY)
  158. option(UA_ENABLE_IMMUTABLE_NODES "Nodes in the information model are not edited but copied and replaced" OFF)
  159. mark_as_advanced(UA_ENABLE_IMMUTABLE_NODES)
  160. option(UA_ENABLE_EXPERIMENTAL_HISTORIZING "Enable client experimental historical access features" OFF)
  161. mark_as_advanced(UA_ENABLE_EXPERIMENTAL_HISTORIZING)
  162. set(UA_MULTITHREADING 0 CACHE STRING "Level of multithreading")
  163. mark_as_advanced(UA_MULTITHREADING)
  164. if (UA_MULTITHREADING GREATER 100)
  165. set(UA_ENABLE_IMMUTABLE_NODES ON)
  166. endif()
  167. option(UA_ENABLE_PUBSUB "Enable publish/subscribe" OFF)
  168. mark_as_advanced(UA_ENABLE_PUBSUB)
  169. option(UA_ENABLE_DA "Enable data access" ON)
  170. mark_as_advanced(UA_ENABLE_DA)
  171. option(UA_ENABLE_PUBSUB_ETH_UADP "Enable publish/subscribe UADP over Ethernet" OFF)
  172. mark_as_advanced(UA_ENABLE_PUBSUB_ETH_UADP)
  173. if(UA_ENABLE_PUBSUB_ETH_UADP)
  174. if (NOT CMAKE_SYSTEM MATCHES "Linux")
  175. message(FATAL_ERROR "UADP over Ethernet is only available on Linux.")
  176. endif()
  177. endif()
  178. option(UA_ENABLE_PUBSUB_DELTAFRAMES "Enable sending of delta frames with only the changes" OFF)
  179. mark_as_advanced(UA_ENABLE_PUBSUB_DELTAFRAMES)
  180. option(UA_ENABLE_PUBSUB_INFORMATIONMODEL "Enable PubSub information model twin" OFF)
  181. mark_as_advanced(UA_ENABLE_PUBSUB_INFORMATIONMODEL)
  182. option(UA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS "Enable PubSub informationmodel methods" OFF)
  183. mark_as_advanced(UA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS)
  184. if(UA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS)
  185. if(NOT UA_ENABLE_PUBSUB_INFORMATIONMODEL)
  186. message(FATAL_ERROR "PubSub information model methods cannot be used with disabled PubSub information model.")
  187. endif()
  188. endif()
  189. if(UA_ENABLE_PUBSUB_INFORMATIONMODEL)
  190. if(NOT UA_ENABLE_PUBSUB)
  191. message(FATAL_ERROR "PubSub information model representation cannot be used with disabled PubSub function.")
  192. endif()
  193. if(UA_NAMESPACE_ZERO STREQUAL "MINIMAL")
  194. message(FATAL_ERROR "PubSub information model representation cannot be used with MINIMAL namespace zero.")
  195. endif()
  196. endif()
  197. option(UA_ENABLE_PUBSUB_CUSTOM_PUBLISH_HANDLING
  198. "Use a custom implementation for the publish callback handling" OFF)
  199. mark_as_advanced(UA_ENABLE_PUBSUB_CUSTOM_PUBLISH_HANDLING)
  200. if(UA_ENABLE_PUBSUB_CUSTOM_PUBLISH_INTERRUPT)
  201. if(NOT UA_ENABLE_PUBSUB)
  202. message(FATAL_ERROR "Custom publish callback handling cannot be used with PubSub function disabled")
  203. endif()
  204. endif()
  205. option(UA_ENABLE_JSON_ENCODING "Enable Json encoding (EXPERIMENTAL)" OFF)
  206. mark_as_advanced(UA_ENABLE_JSON_ENCODING)
  207. option(UA_ENABLE_PUBSUB_MQTT "Enable publish/subscribe with mqtt (experimental)" OFF)
  208. mark_as_advanced(UA_ENABLE_PUBSUB_MQTT)
  209. if(UA_ENABLE_PUBSUB_MQTT)
  210. # Warn if run in Windows
  211. if(WIN32)
  212. MESSAGE(WARNING "Multithreading is enabled in MQTT plugin. This feature is under development and marked as EXPERIMENTAL")
  213. endif()
  214. if(NOT UA_ENABLE_PUBSUB)
  215. message(FATAL_ERROR "Mqtt cannot be used with disabled PubSub function.")
  216. endif()
  217. endif()
  218. option(UA_ENABLE_STATUSCODE_DESCRIPTIONS "Enable conversion of StatusCode to human-readable error message" ON)
  219. mark_as_advanced(UA_ENABLE_STATUSCODE_DESCRIPTIONS)
  220. option(UA_ENABLE_TYPEDESCRIPTION "Add the type and member names to the UA_DataType structure" ON)
  221. mark_as_advanced(UA_ENABLE_TYPEDESCRIPTION)
  222. option(UA_ENABLE_NODESET_COMPILER_DESCRIPTIONS "Set node description attribute for nodeset compiler generated nodes" ON)
  223. mark_as_advanced(UA_ENABLE_NODESET_COMPILER_DESCRIPTIONS)
  224. option(UA_ENABLE_DETERMINISTIC_RNG "Do not seed the random number generator (e.g. for unit tests)." OFF)
  225. mark_as_advanced(UA_ENABLE_DETERMINISTIC_RNG)
  226. option(UA_ENABLE_MALLOC_SINGLETON
  227. "Use a global variable pointer for malloc (and free, ...) that can be switched at runtime" OFF)
  228. mark_as_advanced(UA_ENABLE_MALLOC_SINGLETON)
  229. if(UA_ENABLE_MALLOC_SINGLETON)
  230. if(NOT "${UA_ARCHITECTURE}" MATCHES "posix")
  231. message(FATAL_ERROR "The singleton malloc is available only for the posix architecture")
  232. endif()
  233. endif()
  234. option(UA_ENABLE_VALGRIND_INTERACTIVE "Enable dumping valgrind every iteration. CAUTION! SLOWDOWN!" OFF)
  235. mark_as_advanced(UA_ENABLE_VALGRIND_INTERACTIVE)
  236. option(UA_MSVC_FORCE_STATIC_CRT "Force linking with the static C-runtime library when compiling to static library with MSVC" ON)
  237. mark_as_advanced(UA_MSVC_FORCE_STATIC_CRT)
  238. option(UA_FILE_NS0 "Override the NodeSet xml file used to generate namespace zero")
  239. mark_as_advanced(UA_FILE_NS0)
  240. # Semaphores/file system may not be available on embedded devices. It can be
  241. # disabled with the following option
  242. option(UA_ENABLE_DISCOVERY_SEMAPHORE "Enable Discovery Semaphore support" ON)
  243. mark_as_advanced(UA_ENABLE_DISCOVERY_SEMAPHORE)
  244. option(UA_ENABLE_UNIT_TESTS_MEMCHECK "Use Valgrind (Linux) or DrMemory (Windows) to detect memory leaks when running the unit tests" OFF)
  245. mark_as_advanced(UA_ENABLE_UNIT_TESTS_MEMCHECK)
  246. option(UA_ENABLE_UNIT_TEST_FAILURE_HOOKS
  247. "Add hooks to force failure modes for additional unit tests. Not for production use!" OFF)
  248. mark_as_advanced(UA_ENABLE_UNIT_TEST_FAILURE_HOOKS)
  249. set(UA_VALGRIND_INTERACTIVE_INTERVAL 1000 CACHE STRING "The number of iterations to wait before creating the next dump")
  250. mark_as_advanced(UA_VALGRIND_INTERACTIVE_INTERVAL)
  251. # Build options for debugging
  252. option(UA_DEBUG "Enable assertions and additional functionality that should not be included in release builds" OFF)
  253. mark_as_advanced(UA_DEBUG)
  254. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  255. set(UA_DEBUG ON)
  256. endif()
  257. option(UA_DEBUG_DUMP_PKGS "Dump every package received by the server as hexdump format" OFF)
  258. mark_as_advanced(UA_DEBUG_DUMP_PKGS)
  259. option(UA_ENABLE_HARDENING "Enable Hardening measures (e.g. Stack-Protectors and Fortify)" ON)
  260. mark_as_advanced(UA_ENABLE_HARDENING)
  261. if(CMAKE_VERSION VERSION_GREATER 3.6)
  262. set(UA_ENABLE_STATIC_ANALYZER "OFF" CACHE STRING "Enable installed static analyzer during build process (off/minimal/reduced/full)")
  263. mark_as_advanced(UA_ENABLE_STATIC_ANALYZER)
  264. SET_PROPERTY(CACHE UA_ENABLE_STATIC_ANALYZER PROPERTY STRINGS "OFF" "MINIMAL" "REDUCED" "FULL")
  265. endif()
  266. # Build Targets
  267. option(UA_BUILD_EXAMPLES "Build example servers and clients" OFF)
  268. option(UA_BUILD_TOOLS "Build OPC UA shell tools" OFF)
  269. option(UA_BUILD_UNIT_TESTS "Build the unit tests" OFF)
  270. option(UA_BUILD_FUZZING "Build the fuzzing executables" OFF)
  271. mark_as_advanced(UA_BUILD_FUZZING)
  272. if(UA_BUILD_FUZZING)
  273. # oss-fuzz already defines this by default
  274. add_definitions(-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  275. endif()
  276. if(UA_ENABLE_EXPERIMENTAL_HISTORIZING)
  277. if(NOT UA_ENABLE_HISTORIZING)
  278. message(FATAL_ERROR "UA_ENABLE_EXPERIMENTAL_HISTORIZING cannot be used with disabled UA_ENABLE_HISTORIZING.")
  279. endif()
  280. endif()
  281. option(UA_BUILD_FUZZING_CORPUS "Build the fuzzing corpus" OFF)
  282. mark_as_advanced(UA_BUILD_FUZZING_CORPUS)
  283. if(UA_BUILD_FUZZING_CORPUS)
  284. add_definitions(-DUA_DEBUG_DUMP_PKGS_FILE)
  285. set(UA_ENABLE_TYPEDESCRIPTION ON CACHE STRING "" FORCE)
  286. #set(UA_DEBUG_DUMP_PKGS ON CACHE STRING "" FORCE)
  287. endif()
  288. option(UA_BUILD_OSS_FUZZ "Special build switch used in oss-fuzz" OFF)
  289. mark_as_advanced(UA_BUILD_OSS_FUZZ)
  290. # Advanced Build Targets
  291. option(UA_PACK_DEBIAN "Special build switch used in .deb packaging" OFF)
  292. mark_as_advanced(UA_PACK_DEBIAN)
  293. # Building shared libs (dll, so). This option is written into ua_config.h.
  294. set(UA_DYNAMIC_LINKING OFF)
  295. if(BUILD_SHARED_LIBS)
  296. set(UA_DYNAMIC_LINKING ON)
  297. if (UA_ENABLE_DISCOVERY_MULTICAST)
  298. set(MDNSD_DYNAMIC_LINKING ON)
  299. endif()
  300. endif()
  301. # Warn if experimental features are enabled
  302. if(UA_MULTITHREADING)
  303. MESSAGE(WARNING "UA_MULTITHREADING is enabled. The feature is under development and marked as EXPERIMENTAL")
  304. endif()
  305. ########################
  306. # Linting during build #
  307. ########################
  308. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  309. include(linting_build)
  310. ######################
  311. # External Libraries #
  312. ######################
  313. list(APPEND open62541_LIBRARIES "")
  314. # Force compilation with as C++
  315. option(UA_COMPILE_AS_CXX "Force compilation with a C++ compiler" OFF)
  316. mark_as_advanced(UA_COMPILE_AS_CXX)
  317. if (UA_COMPILE_AS_CXX)
  318. # We need the UINT32_C define
  319. add_definitions(-D__STDC_CONSTANT_MACROS)
  320. endif()
  321. if(UA_ENABLE_ENCRYPTION)
  322. # The recommended way is to install mbedtls via the OS package manager. If
  323. # that is not possible, manually compile mbedTLS and set the cmake variables
  324. # defined in /tools/cmake/FindMbedTLS.cmake.
  325. find_package(MbedTLS REQUIRED)
  326. list(APPEND open62541_LIBRARIES ${MBEDTLS_LIBRARIES})
  327. endif()
  328. if(UA_ENABLE_WEBSOCKET_SERVER)
  329. # The recommended way is to install libwebsockets via the OS package manager. If
  330. # that is not possible, manually compile libwebsockets and set the cmake variables
  331. # defined in /tools/cmake/Findlibwebsockets.cmake
  332. find_package(libwebsockets REQUIRED)
  333. list(APPEND open62541_LIBRARIES ${LIBWEBSOCKETS_LIBRARIES})
  334. endif()
  335. #####################
  336. # Compiler Settings #
  337. #####################
  338. include(CompilerFlags)
  339. if(NOT UA_COMPILE_AS_CXX AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang"))
  340. # Compiler
  341. add_definitions(-std=c99 -pipe
  342. -Wall -Wextra -Wpedantic
  343. -Wno-static-in-inline # clang doesn't like the use of static inline methods inside static inline methods
  344. -Wno-overlength-strings # may happen in the nodeset compiler when complex values are directly encoded
  345. -Wno-unused-parameter # some methods may require unused arguments to cast to a method pointer
  346. -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls
  347. -Wformat -Wformat-security -Wformat-nonliteral
  348. -Wuninitialized -Winit-self
  349. -Wcast-qual
  350. -Wstrict-overflow
  351. -Wnested-externs
  352. -Wmultichar
  353. -Wundef
  354. -Wc++-compat
  355. -fno-strict-aliasing # fewer compiler assumptions about pointer types
  356. -fexceptions # recommended for multi-threaded C code, also in combination with C++ code
  357. )
  358. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror")
  359. if (NOT MINGW)
  360. if(UA_ENABLE_HARDENING)
  361. check_cc_flag("-fstack-protector-strong") # more performant stack protector, available since gcc 4.9
  362. check_cc_flag("-fstack-clash-protection") # increased reliability of stack overflow detection, available since gcc 8
  363. check_cc_flag_untested("-mcet -fcf-protection") # future use (control flow integrity protection)
  364. endif()
  365. # IPO requires too much memory for unit tests
  366. # GCC docu recommends to compile all files with the same options, therefore ignore it completely
  367. if(NOT UA_BUILD_UNIT_TESTS)
  368. # needed to check if IPO is supported (check needs cmake > 3.9)
  369. if("${CMAKE_VERSION}" VERSION_GREATER 3.9)
  370. cmake_policy(SET CMP0069 NEW) # needed as long as required cmake < 3.9
  371. include(CheckIPOSupported)
  372. check_ipo_supported(RESULT CC_HAS_IPO) # Inter Procedural Optimization / Link Time Optimization (should be same as -flto)
  373. if(CC_HAS_IPO)
  374. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
  375. endif()
  376. endif()
  377. endif()
  378. endif()
  379. if(UA_ENABLE_AMALGAMATION)
  380. add_definitions(-Wno-unused-function)
  381. endif()
  382. if(UA_PACK_DEBIAN)
  383. remove_definitions(-Wno-static-in-inline)
  384. endif()
  385. # Linker
  386. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
  387. # Debug
  388. if(BUILD_TYPE_LOWER_CASE STREQUAL "debug" AND UNIX)
  389. if("x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang" AND NOT UA_ENABLE_UNIT_TESTS_MEMCHECK)
  390. # Add default sanitizer settings when using clang and Debug build.
  391. # This allows e.g. CLion to find memory locations for SegFaults
  392. message(STATUS "Sanitizer enabled")
  393. set(SANITIZER_FLAGS "-g -fno-omit-frame-pointer -gline-tables-only -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp -fsanitize=leak -fsanitize=undefined")
  394. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
  395. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
  396. endif()
  397. endif()
  398. if(UA_ENABLE_HARDENING AND ((CMAKE_BUILD_TYPE STREQUAL "Release") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")))
  399. check_cc_flag("-D_FORTIFY_SOURCE=2") # run-time buffer overflow detection (needs at least -O1)
  400. endif()
  401. # Strip release builds
  402. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release")
  403. add_definitions(-ffunction-sections -fdata-sections -fno-unwind-tables
  404. -fno-asynchronous-unwind-tables -fno-math-errno -fno-ident)
  405. # remove stack-protector with MinSizeRel
  406. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
  407. add_definitions(-fno-stack-protector)
  408. endif()
  409. if(NOT OS9)
  410. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -s")
  411. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
  412. endif()
  413. if(APPLE)
  414. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-dead_strip")
  415. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
  416. else()
  417. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--gc-sections")
  418. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
  419. endif()
  420. if(NOT WIN32 AND NOT CYGWIN AND NOT APPLE)
  421. # these settings reduce the binary size by ~2kb
  422. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
  423. endif()
  424. endif()
  425. endif()
  426. if(APPLE)
  427. set(CMAKE_MACOSX_RPATH 1)
  428. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
  429. endif()
  430. if(MSVC)
  431. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX /w44996") # Compiler warnings, error on warning
  432. if(UA_MSVC_FORCE_STATIC_CRT AND NOT BUILD_SHARED_LIBS)
  433. set(CompilerFlags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS
  434. CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE)
  435. foreach(CompilerFlag ${CompilerFlags})
  436. string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
  437. endforeach()
  438. endif()
  439. endif()
  440. if(UA_BUILD_FUZZING OR UA_BUILD_OSS_FUZZ)
  441. add_definitions(-DUA_malloc=UA_memoryManager_malloc)
  442. add_definitions(-DUA_free=UA_memoryManager_free)
  443. add_definitions(-DUA_calloc=UA_memoryManager_calloc)
  444. add_definitions(-DUA_realloc=UA_memoryManager_realloc)
  445. endif()
  446. #########################
  447. # Generate Main Library #
  448. #########################
  449. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  450. configure_file(include/open62541/config.h.in ${PROJECT_BINARY_DIR}/src_generated/open62541/config.h)
  451. configure_file(open62541.pc.in ${PROJECT_BINARY_DIR}/src_generated/open62541.pc @ONLY)
  452. if(UA_ENABLE_DISCOVERY_MULTICAST)
  453. set(MDNSD_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported" FORCE)
  454. configure_file("deps/mdnsd/libmdnsd/mdnsd_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/mdnsd_config.h")
  455. endif()
  456. set(exported_headers ${exported_headers}
  457. ${PROJECT_BINARY_DIR}/src_generated/open62541/config.h
  458. ${PROJECT_SOURCE_DIR}/include/open62541/architecture_base.h
  459. ${ua_architecture_headers_beginning}
  460. )
  461. if(NOT "${UA_AMALGAMATION_ARCHITECTURES}" STREQUAL "")
  462. foreach(arch ${UA_AMALGAMATION_ARCHITECTURES})
  463. list(APPEND exported_headers ${PROJECT_SOURCE_DIR}/arch/${arch}/ua_architecture.h)
  464. endforeach()
  465. else()
  466. list(APPEND exported_headers ${PROJECT_SOURCE_DIR}/arch/${UA_ARCHITECTURE}/ua_architecture.h)
  467. endif()
  468. if(UA_ENABLE_HISTORIZING)
  469. # Historizing needs to be included before server_config.h
  470. set(historizing_exported_headers
  471. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/historydatabase.h)
  472. endif()
  473. set(exported_headers ${exported_headers}
  474. ${PROJECT_SOURCE_DIR}/deps/ms_stdint.h
  475. ${PROJECT_SOURCE_DIR}/include/open62541/architecture_definitions.h
  476. ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.h
  477. ${PROJECT_BINARY_DIR}/src_generated/open62541/nodeids.h
  478. ${PROJECT_SOURCE_DIR}/include/open62541/constants.h
  479. ${PROJECT_SOURCE_DIR}/include/open62541/types.h
  480. ${PROJECT_BINARY_DIR}/src_generated/open62541/types_generated.h
  481. ${PROJECT_BINARY_DIR}/src_generated/open62541/types_generated_handling.h
  482. ${PROJECT_SOURCE_DIR}/include/open62541/util.h
  483. ${PROJECT_SOURCE_DIR}/include/open62541/server.h
  484. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/log.h
  485. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/network.h
  486. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/accesscontrol.h
  487. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/pki.h
  488. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/securitypolicy.h
  489. ${PROJECT_SOURCE_DIR}/include/open62541/server_pubsub.h
  490. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/pubsub.h
  491. ${PROJECT_SOURCE_DIR}/deps/ziptree.h
  492. ${PROJECT_SOURCE_DIR}/include/open62541/plugin/nodestore.h
  493. ${historizing_exported_headers}
  494. ${PROJECT_SOURCE_DIR}/include/open62541/server_config.h
  495. ${PROJECT_SOURCE_DIR}/include/open62541/client_config.h
  496. ${PROJECT_SOURCE_DIR}/include/open62541/client.h
  497. ${PROJECT_SOURCE_DIR}/include/open62541/client_highlevel.h
  498. ${PROJECT_SOURCE_DIR}/include/open62541/client_subscriptions.h
  499. ${PROJECT_SOURCE_DIR}/include/open62541/client_highlevel_async.h)
  500. set(internal_headers ${PROJECT_SOURCE_DIR}/deps/open62541_queue.h
  501. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
  502. ${PROJECT_SOURCE_DIR}/deps/libc_time.h
  503. ${PROJECT_SOURCE_DIR}/deps/base64.h
  504. ${PROJECT_SOURCE_DIR}/src/ua_util_internal.h
  505. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.h
  506. ${PROJECT_BINARY_DIR}/src_generated/open62541/types_generated_encoding_binary.h
  507. ${PROJECT_BINARY_DIR}/src_generated/open62541/transport_generated.h
  508. ${PROJECT_BINARY_DIR}/src_generated/open62541/transport_generated_handling.h
  509. ${PROJECT_BINARY_DIR}/src_generated/open62541/transport_generated_encoding_binary.h
  510. ${PROJECT_SOURCE_DIR}/src/ua_connection_internal.h
  511. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
  512. ${PROJECT_SOURCE_DIR}/src/ua_workqueue.h
  513. ${PROJECT_SOURCE_DIR}/src/ua_timer.h
  514. ${PROJECT_SOURCE_DIR}/src/server/ua_session.h
  515. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
  516. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
  517. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
  518. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_networkmessage.h
  519. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub.h
  520. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_manager.h
  521. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_ns0.h
  522. ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
  523. ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
  524. ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h
  525. ${PROJECT_SOURCE_DIR}/src/server/ua_server_methodqueue.h
  526. ${PROJECT_SOURCE_DIR}/src/server/ua_asyncmethod_manager.h)
  527. # TODO: make client optional
  528. set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
  529. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
  530. ${PROJECT_BINARY_DIR}/src_generated/open62541/types_generated.c
  531. ${PROJECT_BINARY_DIR}/src_generated/open62541/transport_generated.c
  532. ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.c
  533. ${PROJECT_SOURCE_DIR}/src/ua_util.c
  534. ${PROJECT_SOURCE_DIR}/src/ua_workqueue.c
  535. ${PROJECT_SOURCE_DIR}/src/ua_timer.c
  536. ${PROJECT_SOURCE_DIR}/src/ua_connection.c
  537. ${PROJECT_SOURCE_DIR}/src/ua_securechannel.c
  538. ${PROJECT_SOURCE_DIR}/src/server/ua_session.c
  539. ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
  540. ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
  541. ${PROJECT_SOURCE_DIR}/src/server/ua_server_ns0.c
  542. ${PROJECT_SOURCE_DIR}/src/server/ua_server_config.c
  543. ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
  544. ${PROJECT_SOURCE_DIR}/src/server/ua_server_utils.c
  545. ${PROJECT_SOURCE_DIR}/src/server/ua_server_discovery.c
  546. ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.c
  547. ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.c
  548. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_networkmessage.c
  549. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_writer.c
  550. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_reader.c
  551. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_manager.c
  552. ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_ns0.c
  553. ${PROJECT_SOURCE_DIR}/src/server/ua_server_methodqueue.c
  554. ${PROJECT_SOURCE_DIR}/src/server/ua_asyncmethod_manager.c
  555. # services
  556. ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
  557. ${PROJECT_SOURCE_DIR}/src/server/ua_services_method.c
  558. ${PROJECT_SOURCE_DIR}/src/server/ua_services_session.c
  559. ${PROJECT_SOURCE_DIR}/src/server/ua_services_attribute.c
  560. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery.c
  561. ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
  562. ${PROJECT_SOURCE_DIR}/src/server/ua_services_monitoreditem.c
  563. ${PROJECT_SOURCE_DIR}/src/server/ua_services_securechannel.c
  564. ${PROJECT_SOURCE_DIR}/src/server/ua_services_nodemanagement.c
  565. ${PROJECT_SOURCE_DIR}/src/server/ua_services_discovery_multicast.c
  566. # client
  567. ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
  568. ${PROJECT_SOURCE_DIR}/src/client/ua_client_connect.c
  569. ${PROJECT_SOURCE_DIR}/src/client/ua_client_connect_async.c
  570. ${PROJECT_SOURCE_DIR}/src/client/ua_client_discovery.c
  571. ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
  572. ${PROJECT_SOURCE_DIR}/src/client/ua_client_subscriptions.c
  573. ${PROJECT_SOURCE_DIR}/src/client/ua_client_worker.c
  574. # dependencies
  575. ${PROJECT_SOURCE_DIR}/deps/libc_time.c
  576. ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c
  577. ${PROJECT_SOURCE_DIR}/deps/base64.c)
  578. set(default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/accesscontrol_default.h
  579. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/pki_default.h
  580. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/log_stdout.h
  581. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/nodestore_default.h
  582. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/server_config_default.h
  583. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/client_config_default.h
  584. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/securitypolicy_default.h
  585. )
  586. set(default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
  587. ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
  588. ${PROJECT_SOURCE_DIR}/plugins/ua_pki_default.c
  589. ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_ziptree.c
  590. ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_hashmap.c
  591. ${PROJECT_SOURCE_DIR}/plugins/ua_config_default.c
  592. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_none.c
  593. )
  594. if(UA_GENERATED_NAMESPACE_ZERO)
  595. list(APPEND internal_headers ${PROJECT_BINARY_DIR}/src_generated/open62541/namespace0_generated.h)
  596. list(APPEND lib_sources ${PROJECT_BINARY_DIR}/src_generated/open62541/namespace0_generated.c)
  597. endif()
  598. list(APPEND default_plugin_headers
  599. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/securitypolicy_mbedtls_common.h)
  600. list(APPEND default_plugin_sources
  601. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/securitypolicy_mbedtls_common.c
  602. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_basic128rsa15.c
  603. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_basic256.c
  604. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_basic256sha256.c)
  605. if(UA_ENABLE_HISTORIZING)
  606. list(APPEND default_plugin_headers
  607. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/historydata/history_data_backend.h
  608. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/historydata/history_data_gathering.h
  609. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/historydata/history_database_default.h
  610. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/historydata/history_data_gathering_default.h
  611. ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/historydata/history_data_backend_memory.h
  612. )
  613. list(APPEND default_plugin_sources
  614. ${PROJECT_SOURCE_DIR}/plugins/historydata/ua_history_data_backend_memory.c
  615. ${PROJECT_SOURCE_DIR}/plugins/historydata/ua_history_data_gathering_default.c
  616. ${PROJECT_SOURCE_DIR}/plugins/historydata/ua_history_database_default.c
  617. )
  618. endif()
  619. if(UA_ENABLE_DISCOVERY)
  620. list(INSERT internal_headers 13 ${PROJECT_SOURCE_DIR}/src/server/ua_discovery_manager.h)
  621. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_discovery_manager.c)
  622. endif()
  623. if(UA_ENABLE_PUBSUB)
  624. list(APPEND default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/pubsub_udp.h)
  625. list(APPEND default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_pubsub_udp.c)
  626. if(UA_ENABLE_PUBSUB_ETH_UADP)
  627. list(APPEND default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/pubsub_ethernet.h)
  628. list(APPEND default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_pubsub_ethernet.c)
  629. endif()
  630. if(UA_ENABLE_PUBSUB_MQTT)
  631. if(WIN32)
  632. MESSAGE(WARNING "Multithreading is enabled in MQTT plugin. This feature is under development and marked as EXPERIMENTAL")
  633. else()
  634. list(APPEND default_plugin_headers ${PROJECT_SOURCE_DIR}/deps/mqtt-c/mqtt_pal.h)
  635. list(APPEND default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/mqtt/ua_mqtt_pal.c)
  636. list(APPEND default_plugin_headers ${PROJECT_SOURCE_DIR}/deps/mqtt-c/mqtt.h)
  637. list(APPEND default_plugin_sources ${PROJECT_SOURCE_DIR}/deps/mqtt-c/mqtt.c)
  638. list(APPEND default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/ua_network_pubsub_mqtt.h)
  639. list(APPEND default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_pubsub_mqtt.c)
  640. list(APPEND default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/mqtt/ua_mqtt_adapter.h)
  641. list(APPEND default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/mqtt/ua_mqtt_adapter.c)
  642. endif()
  643. endif()
  644. endif()
  645. if(UA_ENABLE_JSON_ENCODING)
  646. if(UA_ENABLE_PUBSUB)
  647. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/pubsub/ua_pubsub_networkmessage_json.c)
  648. endif()
  649. list(APPEND internal_headers ${PROJECT_SOURCE_DIR}/deps/jsmn/jsmn.h
  650. ${PROJECT_SOURCE_DIR}/deps/string_escape.h
  651. ${PROJECT_SOURCE_DIR}/deps/itoa.h
  652. ${PROJECT_SOURCE_DIR}/deps/atoi.h
  653. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_json.h)
  654. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/jsmn/jsmn.c
  655. ${PROJECT_SOURCE_DIR}/deps/string_escape.c
  656. ${PROJECT_SOURCE_DIR}/deps/itoa.c
  657. ${PROJECT_SOURCE_DIR}/deps/atoi.c
  658. ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_json.c)
  659. endif()
  660. if(UA_ENABLE_CUSTOM_LIBC)
  661. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/musl/floatscan.c
  662. ${PROJECT_SOURCE_DIR}/deps/musl/vfprintf.c)
  663. endif()
  664. if(UA_ENABLE_SUBSCRIPTIONS)
  665. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
  666. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_monitoreditem.c
  667. ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_datachange.c)
  668. if(UA_ENABLE_SUBSCRIPTIONS_EVENTS)
  669. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_subscription_events.c)
  670. endif()
  671. endif()
  672. if(UA_DEBUG_DUMP_PKGS)
  673. list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/plugins/ua_debug_dump_pkgs.c)
  674. endif()
  675. if(UA_ENABLE_DISCOVERY_MULTICAST)
  676. # prepend in list, otherwise it complains that winsock2.h has to be included before windows.h
  677. set(internal_headers ${PROJECT_BINARY_DIR}/src_generated/mdnsd_config.h
  678. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/1035.h
  679. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/xht.h
  680. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/sdtxt.h
  681. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/mdnsd.h
  682. ${internal_headers} )
  683. set(lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_server_discovery_mdns.c
  684. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/1035.c
  685. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/xht.c
  686. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/sdtxt.c
  687. ${PROJECT_SOURCE_DIR}/deps/mdnsd/libmdnsd/mdnsd.c
  688. ${lib_sources})
  689. endif()
  690. if(UA_BUILD_FUZZING OR UA_BUILD_OSS_FUZZ)
  691. set(lib_sources
  692. ${lib_sources}
  693. ${PROJECT_SOURCE_DIR}/tests/fuzz/custom_memory_manager.c)
  694. endif()
  695. #########################
  696. # Generate source files #
  697. #########################
  698. # List of nodeset files combined into NS0 generated file
  699. set(UA_FILE_NODESETS)
  700. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  701. if(NOT UA_FILE_NS0)
  702. set(UA_FILE_NS0 ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml)
  703. endif()
  704. set(UA_FILE_NODESETS "${UA_FILE_NS0}")
  705. if(NOT EXISTS "${UA_FILE_NS0}")
  706. message(FATAL_ERROR "File ${UA_FILE_NS0} not found. You probably need to initialize the git submodule for deps/ua-nodeset.")
  707. endif()
  708. set(UA_FILE_NODEIDS ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/NodeIds.csv)
  709. set(UA_FILE_STATUSCODES ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/StatusCode.csv)
  710. set(UA_FILE_TYPES_BSD ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.Types.bsd)
  711. else()
  712. if(NOT UA_FILE_NS0)
  713. set(UA_FILE_NS0 ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.NodeSet2.Minimal.xml)
  714. endif()
  715. set(UA_FILE_NODESETS "${UA_FILE_NS0}")
  716. set(UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_minimal.txt)
  717. set(UA_FILE_NODEIDS ${PROJECT_SOURCE_DIR}/tools/schema/NodeIds.csv)
  718. set(UA_FILE_STATUSCODES ${PROJECT_SOURCE_DIR}/tools/schema/StatusCode.csv)
  719. set(UA_FILE_TYPES_BSD ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.Types.bsd)
  720. if(UA_ENABLE_METHODCALLS)
  721. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_method.txt)
  722. endif()
  723. if(UA_ENABLE_SUBSCRIPTIONS)
  724. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_subscriptions.txt)
  725. endif()
  726. if(UA_ENABLE_SUBSCRIPTIONS_EVENTS)
  727. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_events.txt)
  728. list(APPEND UA_FILE_NODESETS ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.NodeSet2.EventsMinimal.xml)
  729. endif()
  730. if(UA_ENABLE_HISTORIZING)
  731. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_historizing.txt)
  732. list(APPEND UA_FILE_NODESETS ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.NodeSet2.HistorizingMinimal.xml)
  733. endif()
  734. if(UA_ENABLE_DISCOVERY)
  735. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_discovery.txt)
  736. endif()
  737. if(UA_ENABLE_QUERY)
  738. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_query.txt)
  739. endif()
  740. if(UA_ENABLE_PUBSUB)
  741. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_pubsub.txt)
  742. if(UA_ENABLE_PUBSUB_INFORMATIONMODEL)
  743. list(APPEND UA_FILE_NODESETS ${PROJECT_SOURCE_DIR}/tools/schema/Opc.Ua.NodeSet2.PubSubMinimal.xml)
  744. endif()
  745. endif()
  746. if(UA_ENABLE_DA)
  747. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_dataaccess.txt)
  748. endif()
  749. if(UA_ENABLE_TYPEDESCRIPTION)
  750. list(APPEND UA_FILE_DATATYPES ${PROJECT_SOURCE_DIR}/tools/schema/datatypes_typedescription.txt)
  751. endif()
  752. endif()
  753. # standard-defined data types
  754. ua_generate_datatypes(
  755. BUILTIN
  756. NAME "types"
  757. TARGET_SUFFIX "types"
  758. NAMESPACE_IDX 0
  759. FILE_CSV "${UA_FILE_NODEIDS}"
  760. FILES_BSD "${UA_FILE_TYPES_BSD}"
  761. FILES_SELECTED ${UA_FILE_DATATYPES}
  762. )
  763. # transport data types
  764. ua_generate_datatypes(
  765. INTERNAL
  766. NAME "transport"
  767. TARGET_SUFFIX "transport"
  768. NAMESPACE_IDX 1
  769. FILE_CSV "${UA_FILE_NODEIDS}"
  770. FILES_BSD "${UA_FILE_TYPES_BSD}" "${PROJECT_SOURCE_DIR}/tools/schema/Custom.Opc.Ua.Transport.bsd"
  771. FILES_SELECTED "${PROJECT_SOURCE_DIR}/tools/schema/datatypes_transport.txt"
  772. )
  773. # statuscode explanation
  774. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.h
  775. ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.c
  776. PRE_BUILD
  777. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_statuscode_descriptions.py
  778. ${UA_FILE_STATUSCODES} ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes
  779. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_statuscode_descriptions.py
  780. ${UA_FILE_STATUSCODES})
  781. # Header containing defines for all NodeIds
  782. ua_generate_nodeid_header(
  783. NAME "nodeids"
  784. ID_PREFIX "NS0"
  785. TARGET_SUFFIX "ids-ns0"
  786. FILE_CSV "${UA_FILE_NODEIDS}"
  787. )
  788. # we need a custom target to avoid that the generator is called concurrently and
  789. # thus overwriting files while the other thread is compiling
  790. add_custom_target(open62541-generator-statuscode DEPENDS
  791. ${PROJECT_BINARY_DIR}/src_generated/open62541/nodeids.h
  792. ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.h
  793. ${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.c)
  794. if (UA_ENABLE_AMALGAMATION)
  795. # single-file release
  796. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
  797. PRE_BUILD
  798. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  799. ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h
  800. ${exported_headers} ${default_plugin_headers} ${ua_architecture_headers}
  801. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  802. ${exported_headers} ${default_plugin_headers} ${ua_architecture_headers})
  803. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
  804. PRE_BUILD
  805. COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
  806. ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
  807. ${internal_headers} ${lib_sources} ${default_plugin_sources} ${ua_architecture_sources}
  808. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers}
  809. ${lib_sources} ${default_plugin_sources} ${ua_architecture_sources} )
  810. add_custom_target(open62541-amalgamation-source DEPENDS ${PROJECT_BINARY_DIR}/open62541.c)
  811. add_custom_target(open62541-amalgamation-header DEPENDS ${PROJECT_BINARY_DIR}/open62541.h)
  812. add_dependencies(open62541-amalgamation-header open62541-generator-types)
  813. add_dependencies(open62541-amalgamation-source open62541-generator-types
  814. open62541-generator-transport open62541-generator-statuscode)
  815. endif()
  816. ua_generate_nodeset(
  817. NAME "ns0"
  818. FILE ${UA_FILE_NODESETS}
  819. INTERNAL
  820. IGNORE "${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/NodeID_NS0_Base.txt"
  821. DEPENDS_TARGET "open62541-generator-types"
  822. )
  823. # stack protector and optimization needs to be disabled for the huge ns0 file, otherwise debian packaging fails due to long build times.
  824. # We also disable optimization on Appveyor builds, since they take almost an hour otherwise
  825. if(UA_PACK_DEBIAN OR (NOT "$ENV{APPVEYOR}" STREQUAL "") OR (
  826. (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") AND (
  827. # List of compilers which have problems with the huge ns0 optimization
  828. (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0))
  829. )
  830. ))
  831. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/open62541/namespace0_generated.c PROPERTIES COMPILE_FLAGS "-fno-stack-protector -O0")
  832. endif()
  833. #####################
  834. # Build the Library #
  835. #####################
  836. assign_source_group(${lib_sources})
  837. assign_source_group(${internal_headers})
  838. assign_source_group(${exported_headers})
  839. assign_source_group(${default_plugin_sources})
  840. assign_source_group(${ua_architecture_sources})
  841. if(UA_ENABLE_AMALGAMATION)
  842. add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
  843. target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
  844. target_include_directories(open62541-object PRIVATE "${ua_architecture_directories_to_include}")
  845. if(UA_ENABLE_ENCRYPTION)
  846. target_include_directories(open62541-object PRIVATE ${MBEDTLS_INCLUDE_DIRS})
  847. endif()
  848. # make sure the open62541_amalgamation target builds before so that amalgamation is finished and it is not executed again for open62541-object
  849. # and thus may overwrite the amalgamation result during multiprocessor compilation
  850. # the header is already a dependency of open62541 target itself
  851. add_custom_target(open62541-code-generation DEPENDS
  852. open62541-amalgamation-header
  853. open62541-generator-types
  854. open62541-generator-transport
  855. open62541-generator-statuscode
  856. open62541-amalgamation-source
  857. )
  858. add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
  859. # the only directory that needs to be included if open62541 (amalgameted) target from
  860. # the build directory is ${PROJECT_BINARY_DIR}, that contains the generated open62541.h
  861. target_include_directories(open62541 PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
  862. if(UA_COMPILE_AS_CXX)
  863. set_source_files_properties(${PROJECT_BINARY_DIR}/open62541.c PROPERTIES LANGUAGE CXX)
  864. endif()
  865. add_dependencies(open62541-amalgamation-source open62541-generator-namespace)
  866. add_dependencies(open62541-amalgamation-header open62541-generator-namespace)
  867. else()
  868. add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
  869. add_custom_target(open62541-code-generation DEPENDS
  870. open62541-generator-types
  871. open62541-generator-transport
  872. open62541-generator-statuscode
  873. open62541-generator-namespace
  874. )
  875. target_include_directories(open62541-object PRIVATE ${PROJECT_SOURCE_DIR}/src)
  876. add_library(open62541-plugins OBJECT ${default_plugin_sources} ${ua_architecture_sources} ${exported_headers})
  877. add_dependencies(open62541-plugins open62541-generator-types open62541-generator-transport open62541-generator-namespace)
  878. target_include_directories(open62541-plugins PRIVATE ${PROJECT_SOURCE_DIR}/plugins)
  879. target_include_directories(open62541-plugins PRIVATE ${PROJECT_BINARY_DIR}/src_generated)
  880. target_compile_definitions(open62541-plugins PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  881. set_target_properties(open62541-plugins PROPERTIES FOLDER "open62541/lib")
  882. add_library(open62541 $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  883. if(UA_COMPILE_AS_CXX)
  884. set_source_files_properties(${lib_sources} PROPERTIES LANGUAGE CXX)
  885. set_source_files_properties(${default_plugin_sources} ${ua_architecture_sources} PROPERTIES LANGUAGE CXX)
  886. endif()
  887. # Declare include directories
  888. function(include_directories_private)
  889. foreach(_include_dir IN ITEMS ${ARGN})
  890. target_include_directories(open62541-object PRIVATE ${_include_dir})
  891. target_include_directories(open62541-plugins PRIVATE ${_include_dir})
  892. endforeach()
  893. endfunction()
  894. function(include_directories_public)
  895. include_directories_private(${ARGN})
  896. foreach(_include_dir IN ITEMS ${ARGN})
  897. target_include_directories(open62541 PUBLIC $<BUILD_INTERFACE:${_include_dir}>)
  898. endforeach()
  899. endfunction()
  900. # Public includes
  901. include_directories_public(${ua_architecture_directories_to_include}
  902. "${PROJECT_SOURCE_DIR}/include"
  903. "${PROJECT_SOURCE_DIR}/plugins/include"
  904. "${PROJECT_SOURCE_DIR}/deps"
  905. "${PROJECT_SOURCE_DIR}/src/pubsub"
  906. "${PROJECT_BINARY_DIR}/src_generated")
  907. # Private includes
  908. include_directories_private("${PROJECT_BINARY_DIR}")
  909. if(UA_ENABLE_ENCRYPTION)
  910. include_directories_private(${MBEDTLS_INCLUDE_DIRS})
  911. endif()
  912. # Option-specific includes
  913. if(UA_ENABLE_DISCOVERY)
  914. include_directories_private("${PROJECT_SOURCE_DIR}/src/client")
  915. endif()
  916. endif()
  917. add_dependencies(open62541-object open62541-code-generation)
  918. # Ensure that the open62541::open62541 alias can be used inside open62541's build
  919. add_library(open62541::open62541 ALIAS open62541)
  920. # Export Symbols
  921. target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  922. target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  923. if (UA_ENABLE_DISCOVERY_MULTICAST)
  924. target_compile_definitions(open62541-object PRIVATE -DMDNSD_DYNAMIC_LINKING_EXPORT)
  925. target_compile_definitions(open62541 PRIVATE -DMDNSD_DYNAMIC_LINKING_EXPORT)
  926. endif()
  927. # Generate properly versioned shared library links on Linux
  928. SET_TARGET_PROPERTIES(open62541 PROPERTIES SOVERSION "${OPEN62541_VER_MAJOR}" VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")
  929. ##################################
  930. # Architectures changes #
  931. ##################################
  932. GET_PROPERTY(ua_architecture_add_definitions GLOBAL PROPERTY UA_ARCHITECTURE_ADD_DEFINITIONS)
  933. add_definitions(${ua_architecture_add_definitions})
  934. GET_PROPERTY(ua_architecture_remove_definitions GLOBAL PROPERTY UA_ARCHITECTURE_REMOVE_DEFINITIONS)
  935. if (NOT "${ua_architecture_remove_definitions}" STREQUAL "")
  936. string(REPLACE " " ";" ua_architecture_remove_definitions_list ${ua_architecture_remove_definitions})
  937. remove_definitions(${ua_architecture_remove_definitions_list})
  938. endif(NOT "${ua_architecture_remove_definitions}" STREQUAL "")
  939. GET_PROPERTY(ua_architecture_append_to_library GLOBAL PROPERTY UA_ARCHITECTURE_APPEND_TO_LIBRARY)
  940. list(APPEND open62541_LIBRARIES ${ua_architecture_append_to_library})
  941. target_compile_definitions(open62541 PUBLIC UA_ARCHITECTURE_${UA_ARCHITECTURE_UPPER})
  942. # DLL requires linking to dependencies
  943. target_link_libraries(open62541 ${open62541_LIBRARIES})
  944. ##########################
  945. # Build Selected Targets #
  946. ##########################
  947. # always include, builds with make doc
  948. add_subdirectory(doc)
  949. if(UA_BUILD_EXAMPLES)
  950. if(UA_ENABLE_AMALGAMATION)
  951. # Cannot compile tests with amalgamation. Not prepared for single header include
  952. message(FATAL_ERROR "Examples cannot be built with source amalgamation enabled")
  953. endif()
  954. add_subdirectory(examples)
  955. endif()
  956. if(UA_BUILD_UNIT_TESTS)
  957. if(UA_ENABLE_AMALGAMATION)
  958. # Cannot compile tests with amalgamation. Amalgamation uses the default plugins, not the testing plugins
  959. message(FATAL_ERROR "Unit tests cannot be generated with source amalgamation enabled")
  960. endif()
  961. enable_testing()
  962. add_subdirectory(tests)
  963. endif()
  964. if(UA_BUILD_FUZZING OR UA_BUILD_OSS_FUZZ OR UA_BUILD_FUZZING_CORPUS)
  965. add_subdirectory(tests/fuzz)
  966. endif()
  967. if(UA_BUILD_TOOLS)
  968. if(UA_ENABLE_JSON_ENCODING)
  969. add_subdirectory(tools/ua2json)
  970. endif()
  971. endif()
  972. ########################
  973. # Linting as target #
  974. ########################
  975. include(linting_target)
  976. ##########################
  977. # Installation #
  978. ##########################
  979. # invoke via `make install`
  980. # specify install location with `-DCMAKE_INSTALL_PREFIX=xyz`
  981. # Enable shared library with `-DBUILD_SHARED_LIBS=ON`
  982. set(cmake_configfile_install ${CMAKE_INSTALL_LIBDIR}/cmake/open62541)
  983. set(open62541_install_tools_dir share/open62541/tools)
  984. set(open62541_install_nodeset_dir share/open62541/tools/ua-nodeset)
  985. # This list of components allows to define a find_package requirement.
  986. # E.g.:
  987. # find_package(open62541 1.0.0 REQUIRED COMPONENTS Events Methods FullNamespace)
  988. set(open62541_enabled_components "")
  989. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  990. list(APPEND open62541_enabled_components "FullNamespace")
  991. endif()
  992. if(UA_ENABLE_METHODCALLS)
  993. list(APPEND open62541_enabled_components "Methods")
  994. endif()
  995. if(UA_ENABLE_SUBSCRIPTIONS)
  996. list(APPEND open62541_enabled_components "Subscriptions")
  997. endif()
  998. if(UA_ENABLE_PUBSUB)
  999. list(APPEND open62541_enabled_components "PubSub")
  1000. endif()
  1001. if(UA_ENABLE_ENCRYPTION)
  1002. list(APPEND open62541_enabled_components "Encryption")
  1003. endif()
  1004. if(UA_ENABLE_AMALGAMATION)
  1005. list(APPEND open62541_enabled_components "Amalgamation")
  1006. endif()
  1007. if(UA_ENABLE_HISTORIZING)
  1008. list(APPEND open62541_enabled_components "Historizing")
  1009. endif()
  1010. if(UA_ENABLE_EXPERIMENTAL_HISTORIZING)
  1011. list(APPEND open62541_enabled_components "ExperimentalHistorizing")
  1012. endif()
  1013. if(UA_ENABLE_SUBSCRIPTIONS_EVENTS)
  1014. list(APPEND open62541_enabled_components "Events")
  1015. endif()
  1016. if(UA_MULTITHREADING)
  1017. list(APPEND open62541_enabled_components "Multithreading")
  1018. endif()
  1019. if(UA_ENABLE_DISCOVERY)
  1020. list(APPEND open62541_enabled_components "Discovery")
  1021. endif()
  1022. if(UA_ENABLE_DISCOVERY_MULTICAST)
  1023. list(APPEND open62541_enabled_components "DiscoveryMulticast")
  1024. endif()
  1025. # export library (either static or shared depending on BUILD_SHARED_LIBS)
  1026. install(TARGETS open62541
  1027. EXPORT open62541Targets
  1028. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1029. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  1030. RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}
  1031. INCLUDES DESTINATION include)
  1032. if(UA_ENABLE_AMALGAMATION)
  1033. # Our default way of installation is the non-amalgamated version.
  1034. # See also https://github.com/open62541/open62541/pull/2292#discussion_r241106424
  1035. install(CODE "MESSAGE(WARNING \"Installation with UA_ENABLE_AMALGAMATION=ON is not recommended.\")")
  1036. endif()
  1037. include(CMakePackageConfigHelpers)
  1038. configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/open62541Config.cmake.in"
  1039. "${CMAKE_CURRENT_BINARY_DIR}/open62541Config.cmake"
  1040. INSTALL_DESTINATION "${cmake_configfile_install}"
  1041. PATH_VARS open62541_install_tools_dir
  1042. open62541_install_nodeset_dir
  1043. open62541_enabled_components
  1044. )
  1045. set(open62541_VERSION)
  1046. get_target_property(open62541_VERSION open62541 VERSION)
  1047. write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/open62541ConfigVersion.cmake"
  1048. VERSION ${open62541_VERSION}
  1049. COMPATIBILITY AnyNewerVersion)
  1050. install(EXPORT open62541Targets
  1051. FILE open62541Targets.cmake
  1052. DESTINATION "${cmake_configfile_install}"
  1053. NAMESPACE open62541::)
  1054. export(
  1055. TARGETS open62541
  1056. NAMESPACE open62541::
  1057. FILE ${CMAKE_CURRENT_BINARY_DIR}/open62541Targets.cmake
  1058. )
  1059. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/macros_public.cmake" "${CMAKE_CURRENT_BINARY_DIR}/open62541Macros.cmake" COPYONLY)
  1060. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/open62541Config.cmake"
  1061. "${CMAKE_CURRENT_BINARY_DIR}/open62541ConfigVersion.cmake"
  1062. "${CMAKE_CURRENT_BINARY_DIR}/open62541Macros.cmake"
  1063. DESTINATION "${cmake_configfile_install}")
  1064. if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  1065. install(FILES "${PROJECT_BINARY_DIR}/src_generated/open62541.pc"
  1066. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1067. endif()
  1068. set(UA_install_tools_dirs "tools/certs"
  1069. "tools/nodeset_compiler"
  1070. "tools/schema"
  1071. "deps/ua-nodeset")
  1072. set(UA_install_tools_files "tools/generate_datatypes.py"
  1073. "tools/generate_nodeid_header.py"
  1074. "tools/generate_statuscode_descriptions.py")
  1075. install(DIRECTORY ${UA_install_tools_dirs}
  1076. DESTINATION ${open62541_install_tools_dir}
  1077. USE_SOURCE_PERMISSIONS
  1078. FILES_MATCHING
  1079. PATTERN "*"
  1080. PATTERN "*.pyc" EXCLUDE
  1081. )
  1082. install(FILES ${UA_install_tools_files} DESTINATION ${open62541_install_tools_dir})
  1083. if(NOT UA_ENABLE_AMALGAMATION)
  1084. # Recreate the include folder structure from the source also in /usr/lib/include/open62541
  1085. set(FILES_TO_INSTALL
  1086. ${exported_headers}
  1087. ${default_plugin_headers}
  1088. ${ua_architecture_headers})
  1089. set(BASE_PATH_MAIN "${PROJECT_SOURCE_DIR}/include/open62541")
  1090. set(BASE_PATH_PLUGINS "${PROJECT_SOURCE_DIR}/plugins/include/open62541")
  1091. set(BASE_PATH_ARCH "${PROJECT_SOURCE_DIR}/arch")
  1092. set(BASE_PATH_GENERATED "${PROJECT_BINARY_DIR}/src_generated/open62541")
  1093. set(BASE_PATH_DEPS "${PROJECT_SOURCE_DIR}/deps")
  1094. foreach ( file ${FILES_TO_INSTALL} )
  1095. # Construct a relative path by replacing any occurence of the absolute path
  1096. set(full_path ${file})
  1097. string(REPLACE ${BASE_PATH_MAIN} "" file ${file})
  1098. string(REPLACE ${BASE_PATH_PLUGINS} "" file ${file})
  1099. string(REPLACE ${BASE_PATH_ARCH} "" file ${file})
  1100. string(REPLACE ${BASE_PATH_GENERATED} "" file ${file})
  1101. string(REPLACE ${BASE_PATH_DEPS} "" file ${file})
  1102. get_filename_component( dir ${file} DIRECTORY )
  1103. if(${full_path} MATCHES "deps")
  1104. install( FILES ${full_path} DESTINATION include${dir} )
  1105. else()
  1106. install( FILES ${full_path} DESTINATION include/open62541${dir} )
  1107. endif()
  1108. endforeach()
  1109. else()
  1110. # Export amalgamated header open62541.h which is generated due to build of
  1111. # open62541-object
  1112. install(FILES ${PROJECT_BINARY_DIR}/open62541.h DESTINATION include)
  1113. endif()
  1114. add_subdirectory(tools/packaging)
  1115. ##################################
  1116. # Visual studio solution folders #
  1117. ##################################
  1118. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  1119. set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_CmakePredifinedTargets")
  1120. set_target_properties(open62541 PROPERTIES FOLDER "open62541/lib")
  1121. set_target_properties(open62541-object PROPERTIES FOLDER "open62541/lib")
  1122. if (UA_ENABLE_AMALGAMATION)
  1123. set_target_properties(open62541-amalgamation-header PROPERTIES FOLDER "open62541/lib")
  1124. set_target_properties(open62541-amalgamation-source PROPERTIES FOLDER "open62541/lib")
  1125. endif()
  1126. set_target_properties(open62541-generator-namespace PROPERTIES FOLDER "open62541/generators")
  1127. set_target_properties(open62541-generator-statuscode PROPERTIES FOLDER "open62541/generators")
  1128. set_target_properties(open62541-generator-transport PROPERTIES FOLDER "open62541/generators")
  1129. set_target_properties(open62541-generator-types PROPERTIES FOLDER "open62541/generators")