CMakeLists.txt 59 KB

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