CMakeLists.txt 56 KB

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