CMakeLists.txt 60 KB

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