CMakeLists.txt 62 KB

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