macros.cmake 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. #Add a new architecture to to the lists of available architectures
  2. FUNCTION(ua_add_architecture)
  3. FOREACH(ARG ${ARGV})
  4. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURES ${ARG})
  5. ENDFOREACH(ARG)
  6. ENDFUNCTION(ua_add_architecture)
  7. #Include folders to the compilation
  8. FUNCTION(ua_include_directories)
  9. FOREACH(ARG ${ARGV})
  10. set_property(GLOBAL APPEND PROPERTY UA_INCLUDE_DIRECTORIES ${ARG})
  11. ENDFOREACH(ARG)
  12. ENDFUNCTION(ua_include_directories)
  13. #Add a new header file to the architecture group
  14. FUNCTION(ua_add_architecture_header)
  15. FOREACH(ARG ${ARGV})
  16. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_HEADERS ${ARG})
  17. ENDFOREACH(ARG)
  18. ENDFUNCTION(ua_add_architecture_header)
  19. #Add a new header file to the architecture group at the beginning of it
  20. FUNCTION(ua_add_architecture_header_beginning)
  21. FOREACH(ARG ${ARGV})
  22. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_HEADERS_BEGINNING ${ARG})
  23. ENDFOREACH(ARG)
  24. ENDFUNCTION(ua_add_architecture_header_beginning)
  25. #Add a new source file to the architecture group
  26. FUNCTION(ua_add_architecture_file)
  27. FOREACH(ARG ${ARGV})
  28. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_SOURCES ${ARG})
  29. ENDFOREACH(ARG)
  30. ENDFUNCTION(ua_add_architecture_file)
  31. #Add definitions to the compilations that are exclusive for the selected architecture
  32. FUNCTION(ua_architecture_add_definitions)
  33. FOREACH(ARG ${ARGV})
  34. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_ADD_DEFINITIONS ${ARG})
  35. ENDFOREACH(ARG)
  36. ENDFUNCTION(ua_architecture_add_definitions)
  37. #Remove definitions from the compilations that are exclusive for the selected architecture
  38. FUNCTION(ua_architecture_remove_definitions)
  39. FOREACH(ARG ${ARGV})
  40. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_REMOVE_DEFINITIONS ${ARG})
  41. ENDFOREACH(ARG)
  42. ENDFUNCTION(ua_architecture_remove_definitions)
  43. #Add libraries to be linked to the comnpilation that are exclusive for the selected architecture
  44. FUNCTION(ua_architecture_append_to_library)
  45. FOREACH(ARG ${ARGV})
  46. set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_APPEND_TO_LIBRARY ${ARG})
  47. ENDFOREACH(ARG)
  48. ENDFUNCTION(ua_architecture_append_to_library)
  49. # --------------- Generate Datatypes ---------------------
  50. #
  51. # Generates Datatype definition based on the .csv and .bsd files of a nodeset.
  52. # The result of the generation will be C Code which can be compiled with the rest of the stack.
  53. # Some nodesets come with custom datatypes. These datatype structures first need to be
  54. # generated so that the nodeset can use these types.
  55. #
  56. # The resulting files will be put into OUTPUT_DIR with the names:
  57. # - NAME_generated.c
  58. # - NAME_generated.h
  59. # - NAME_generated_encoding_binary.h
  60. # - NAME_generated_handling.h
  61. #
  62. # The cmake resulting cmake target will be named like this:
  63. # open62541-generator-${TARGET_SUFFIX}
  64. #
  65. # The following arguments are accepted:
  66. # Options:
  67. #
  68. # [BUILTIN] Optional argument. If given, then builtin types will be generated.
  69. #
  70. # Arguments taking one value:
  71. #
  72. # NAME Full name of the generated files, e.g. ua_types_di
  73. # TARGET_SUFFIX Suffix for the resulting target. e.g. types-di
  74. # NAMESPACE_IDX Namespace index of the nodeset, when it is loaded into the server. This index
  75. # is used for the node ids withing the types array and is currently not determined automatically.
  76. # Make sure that it matches the namespace index in the server.
  77. # [OUTPUT_DIR] Optional target directory for the generated files. Default is '${PROJECT_BINARY_DIR}/src_generated'
  78. # FILE_CSV Path to the .csv file containing the node ids, e.g. 'OpcUaDiModel.csv'
  79. #
  80. # Arguments taking multiple values:
  81. #
  82. # FILES_BSD Path to the .bsd file containing the type definitions, e.g. 'Opc.Ua.Di.Types.bsd'. Multiple files can be
  83. # passed which will all combined to one resulting code.
  84. # [FILES_SELECTED] Optional path to a simple text file which contains a list of types which should be included in the generation.
  85. # The file should contain one type per line. Multiple files can be passed to this argument.
  86. #
  87. #
  88. function(ua_generate_datatypes)
  89. set(options BUILTIN)
  90. set(oneValueArgs NAME TARGET_SUFFIX NAMESPACE_IDX OUTPUT_DIR FILE_CSV)
  91. set(multiValueArgs FILES_BSD FILES_SELECTED)
  92. cmake_parse_arguments(UA_GEN_DT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  93. # ------ Argument checking -----
  94. if(NOT DEFINED UA_GEN_DT_NAMESPACE_IDX AND NOT "${UA_GEN_DT_NAMESPACE_IDX}" STREQUAL "0")
  95. message(FATAL_ERROR "ua_generate_datatype function requires a value for the NAMESPACE_IDX argument")
  96. endif()
  97. if(NOT UA_GEN_DT_NAME OR "${UA_GEN_DT_NAME}" STREQUAL "")
  98. message(FATAL_ERROR "ua_generate_datatype function requires a value for the NAME argument")
  99. endif()
  100. if(NOT UA_GEN_DT_TARGET_SUFFIX OR "${UA_GEN_DT_TARGET_SUFFIX}" STREQUAL "")
  101. message(FATAL_ERROR "ua_generate_datatype function requires a value for the TARGET_SUFFIX argument")
  102. endif()
  103. if(NOT UA_GEN_DT_FILE_CSV OR "${UA_GEN_DT_FILE_CSV}" STREQUAL "")
  104. message(FATAL_ERROR "ua_generate_datatype function requires a value for the FILE_CSV argument")
  105. endif()
  106. if(NOT UA_GEN_DT_FILES_BSD OR "${UA_GEN_DT_FILES_BSD}" STREQUAL "")
  107. message(FATAL_ERROR "ua_generate_datatype function requires a value for the FILES_BSD argument")
  108. endif()
  109. # Set default value for output dir
  110. if(NOT UA_GEN_DT_OUTPUT_DIR)
  111. set(UA_GEN_DT_OUTPUT_DIR ${PROJECT_BINARY_DIR}/src_generated)
  112. endif()
  113. # ------ Add custom command and target -----
  114. set(UA_GEN_DT_NO_BUILTIN "--no-builtin")
  115. if (UA_GEN_DT_BUILTIN)
  116. set(UA_GEN_DT_NO_BUILTIN "")
  117. endif()
  118. set(SELECTED_TYPES_TMP "")
  119. foreach(f ${UA_GEN_DT_FILES_SELECTED})
  120. set(SELECTED_TYPES_TMP ${SELECTED_TYPES_TMP} "--selected-types=${f}")
  121. endforeach()
  122. set(BSD_FILES_TMP "")
  123. foreach(f ${UA_GEN_DT_FILES_BSD})
  124. set(BSD_FILES_TMP ${BSD_FILES_TMP} "--type-bsd=${f}")
  125. endforeach()
  126. add_custom_command(OUTPUT ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.c
  127. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.h
  128. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated_handling.h
  129. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated_encoding_binary.h
  130. PRE_BUILD
  131. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  132. --namespace=${UA_GEN_DT_NAMESPACE_IDX}
  133. ${SELECTED_TYPES_TMP}
  134. ${BSD_FILES_TMP}
  135. --type-csv=${UA_GEN_DT_FILE_CSV}
  136. ${UA_GEN_DT_NO_BUILTIN}
  137. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}
  138. DEPENDS ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  139. ${UA_GEN_DT_FILES_BSD}
  140. ${UA_GEN_DT_FILE_CSV}
  141. ${UA_GEN_DT_FILES_SELECTED})
  142. add_custom_target(open62541-generator-${UA_GEN_DT_TARGET_SUFFIX} DEPENDS
  143. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.c
  144. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.h
  145. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated_handling.h
  146. ${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated_encoding_binary.h
  147. )
  148. string(TOUPPER "${UA_GEN_DT_NAME}" GEN_NAME_UPPER)
  149. set(${GEN_NAME_UPPER}_SOURCES "${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.c" CACHE INTERNAL "${UA_GEN_DT_NAME} source files")
  150. set(${GEN_NAME_UPPER}_HEADERS "${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.h;${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated_handling.h;${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated_encoding_binary.h"
  151. CACHE INTERNAL "${UA_GEN_DT_NAME} header files")
  152. if(UA_COMPILE_AS_CXX)
  153. set_source_files_properties(${UA_GEN_DT_OUTPUT_DIR}/${UA_GEN_DT_NAME}_generated.c PROPERTIES LANGUAGE CXX)
  154. endif()
  155. endfunction()
  156. # --------------- Generate Nodeset ---------------------
  157. #
  158. # Generates C code for the given NodeSet2.xml file.
  159. # This C code can be used to initialize the server.
  160. #
  161. # The resulting files will be put into OUTPUT_DIR with the names:
  162. # - ua_namespace_NAME.c
  163. # - ua_namespace_NAME.h
  164. #
  165. # The resulting cmake target will be named like this:
  166. # open62541-generator-ns-${NAME}
  167. #
  168. # The following arguments are accepted:
  169. # Options:
  170. #
  171. # [INTERNAL] Optional argument. If given, then the generated node set code will use internal headers.
  172. #
  173. # Arguments taking one value:
  174. #
  175. # NAME Name of the nodeset, e.g. 'di'
  176. # [TYPES_ARRAY] Optional name of the types array containing the custom datatypes of this node set.
  177. # [OUTPUT_DIR] Optional target directory for the generated files. Default is '${PROJECT_BINARY_DIR}/src_generated'
  178. # [ENCODE_BINARY_SIZE] Optional array size for binary encoding extension objects.
  179. # [IGNORE] Optional file containing a list of node ids which should be ignored. The file should have one id per line.
  180. #
  181. # Arguments taking multiple values:
  182. #
  183. # FILE Path to the NodeSet2.xml file. Multiple values can be passed. These nodesets will be combined into one output.
  184. # [DEPENDS_TYPES] Optional list of types array which match with the DEPENDS_NS node sets. e.g. 'UA_TYPES;UA_TYPES_DI'
  185. # [DEPENDS_NS] Optional list of NodeSet2.xml files which are a dependency of this node set.
  186. # [DEPENDS_TARGET] Optional list of CMake targets this nodeset depends on.
  187. #
  188. #
  189. function(ua_generate_nodeset)
  190. set(options INTERNAL )
  191. set(oneValueArgs NAME TYPES_ARRAY OUTPUT_DIR ENCODE_BINARY_SIZE IGNORE)
  192. set(multiValueArgs FILE DEPENDS_TYPES DEPENDS_NS DEPENDS_TARGET)
  193. cmake_parse_arguments(UA_GEN_NS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  194. # ------ Argument checking -----
  195. if(NOT UA_GEN_NS_NAME OR "${UA_GEN_NS_NAME}" STREQUAL "")
  196. message(FATAL_ERROR "ua_generate_nodeset function requires a value for the NAME argument")
  197. endif()
  198. if(NOT UA_GEN_NS_FILE OR "${UA_GEN_NS_FILE}" STREQUAL "")
  199. message(FATAL_ERROR "ua_generate_nodeset function requires a value for the FILE argument")
  200. endif()
  201. # Set default value for output dir
  202. if(NOT UA_GEN_NS_OUTPUT_DIR)
  203. set(UA_GEN_NS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/src_generated)
  204. endif()
  205. list(LENGTH UA_GEN_NS_DEPENDS_TYPES DEPENDS_TYPES_LEN)
  206. list(LENGTH UA_GEN_NS_DEPENDS_NS DEPENDS_NS_LEN)
  207. if(NOT DEPENDS_TYPES_LEN EQUAL DEPENDS_NS_LEN)
  208. message(FATAL_ERROR "ua_generate_nodeset parameters DEPENDS_NS and DEPENDS_TYPES must have the same number of list elements")
  209. endif()
  210. # ------ Add custom command and target -----
  211. set(GEN_INTERNAL_HEADERS "")
  212. if (UA_GEN_NS_INTERNAL)
  213. set(GEN_INTERNAL_HEADERS "--internal-headers")
  214. endif()
  215. set(GEN_NS0 "")
  216. set(TARGET_SUFFIX "ns-${UA_GEN_NS_NAME}")
  217. set(FILE_SUFFIX "_${UA_GEN_NS_NAME}")
  218. string(REPLACE "-" "_" FILE_SUFFIX ${FILE_SUFFIX})
  219. if ("${UA_GEN_NS_NAME}" STREQUAL "ns0")
  220. set(GEN_NS0 "--generate-ns0")
  221. set(TARGET_SUFFIX "namespace")
  222. set(FILE_SUFFIX "0")
  223. endif()
  224. set(GEN_IGNORE "")
  225. if (UA_GEN_NS_IGNORE)
  226. set(GEN_IGNORE "--ignore=${UA_GEN_NS_IGNORE}")
  227. endif()
  228. set(GEN_BIN_SIZE "")
  229. if (UA_GEN_NS_ENCODE_BINARY_SIZE OR "${UA_GEN_NS_ENCODE_BINARY_SIZE}" STREQUAL "0")
  230. set(GEN_BIN_SIZE "--encode-binary-size=${UA_GEN_NS_ENCODE_BINARY_SIZE}")
  231. endif()
  232. set(TYPES_ARRAY_LIST "")
  233. foreach(f ${UA_GEN_NS_DEPENDS_TYPES})
  234. set(TYPES_ARRAY_LIST ${TYPES_ARRAY_LIST} "--types-array=${f}")
  235. endforeach()
  236. if(UA_GEN_NS_TYPES_ARRAY)
  237. set(TYPES_ARRAY_LIST ${TYPES_ARRAY_LIST} "--types-array=${UA_GEN_NS_TYPES_ARRAY}")
  238. endif()
  239. set(DEPENDS_FILE_LIST "")
  240. foreach(f ${UA_GEN_NS_DEPENDS_NS})
  241. set(DEPENDS_FILE_LIST ${DEPENDS_FILE_LIST} "--existing=${f}")
  242. endforeach()
  243. set(FILE_LIST "")
  244. foreach(f ${UA_GEN_NS_FILE})
  245. set(FILE_LIST ${FILE_LIST} "--xml=${f}")
  246. endforeach()
  247. add_custom_command(OUTPUT ${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.c
  248. ${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.h
  249. PRE_BUILD
  250. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  251. ${GEN_INTERNAL_HEADERS}
  252. ${GEN_NS0}
  253. ${GEN_BIN_SIZE}
  254. ${GEN_IGNORE}
  255. ${TYPES_ARRAY_LIST}
  256. ${DEPENDS_FILE_LIST}
  257. ${FILE_LIST}
  258. ${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}
  259. DEPENDS
  260. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  261. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodes.py
  262. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset.py
  263. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/datatypes.py
  264. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541.py
  265. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_nodes.py
  266. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_datatypes.py
  267. ${UA_GEN_NS_FILE}
  268. ${UA_GEN_NS_DEPENDS_NS}
  269. )
  270. add_custom_target(open62541-generator-${TARGET_SUFFIX}
  271. DEPENDS
  272. ${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.c
  273. ${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.h)
  274. if (UA_GEN_NS_DEPENDS_TARGET)
  275. add_dependencies(open62541-generator-${TARGET_SUFFIX} ${UA_GEN_NS_DEPENDS_TARGET})
  276. endif()
  277. if(UA_COMPILE_AS_CXX)
  278. set_source_files_properties(${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.c PROPERTIES LANGUAGE CXX)
  279. endif()
  280. set_property(GLOBAL PROPERTY "UA_GEN_NS_DEPENDS_FILE_${UA_GEN_NS_NAME}" ${UA_GEN_NS_DEPENDS_NS} ${UA_GEN_NS_FILE})
  281. set_property(GLOBAL PROPERTY "UA_GEN_NS_DEPENDS_TYPES_${UA_GEN_NS_NAME}" ${UA_GEN_NS_DEPENDS_TYPES} ${UA_GEN_NS_TYPES_ARRAY})
  282. string(TOUPPER "${UA_GEN_NS_NAME}" GEN_NAME_UPPER)
  283. set(UA_NODESET_${GEN_NAME_UPPER}_SOURCES "${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.c" CACHE INTERNAL "UA_NODESET_${GEN_NAME_UPPER} source files")
  284. set(UA_NODESET_${GEN_NAME_UPPER}_HEADERS "${UA_GEN_NS_OUTPUT_DIR}/ua_namespace${FILE_SUFFIX}.h" CACHE INTERNAL "UA_NODESET_${GEN_NAME_UPPER} header files")
  285. set(UA_NODESET_${GEN_NAME_UPPER}_TARGET "open62541-generator-${TARGET_SUFFIX}" CACHE INTERNAL "UA_NODESET_${GEN_NAME_UPPER} target")
  286. endfunction()
  287. # --------------- Generate Nodeset and Datatypes ---------------------
  288. #
  289. # Generates C code for the given NodeSet2.xml and Datatype file.
  290. # This C code can be used to initialize the server.
  291. #
  292. # This is a combination of the ua_generate_datatypes and ua_generate_nodeset macros.
  293. # This function can also be used to just create a nodeset without datatypes by
  294. # omitting the CSV, BSD, and NAMESPACE_IDX parameter.
  295. # If only one of the previous parameters is given, all of them are required.
  296. #
  297. # It is possible to define dependencies of nodesets by using the DEPENDS argument.
  298. # E.g. the PLCOpen nodeset depends on the 'di' nodeset. Thus it is enough to just
  299. # pass 'DEPENDS di' to the function. The 'di' nodeset then first needs to be generated
  300. # with this function or with the ua_generate_nodeset function.
  301. #
  302. # The resulting cmake target will be named like this:
  303. # open62541-generator-ns-${NAME}
  304. #
  305. # The following arguments are accepted:
  306. #
  307. # Options:
  308. #
  309. # INTERNAL Include internal headers. Required if custom datatypes are added.
  310. #
  311. # Arguments taking one value:
  312. #
  313. # NAME Short name of the nodeset. E.g. 'di'
  314. # FILE_NS Path to the NodeSet2.xml file. Multiple values can be passed. These nodesets will be combined into one output.
  315. #
  316. # [FILE_CSV] Optional path to the .csv file containing the node ids, e.g. 'OpcUaDiModel.csv'
  317. # [FILE_BSD] Optional path to the .bsd file containing the type definitions, e.g. 'Opc.Ua.Di.Types.bsd'. Multiple files can be
  318. # passed which will all combined to one resulting code.
  319. # [NAMESPACE_IDX] Optional namespace index of the nodeset, when it is loaded into the server. This parameter is mandatory if FILE_CSV
  320. # or FILE_BSD is set. See ua_generate_datatypes function.
  321. #
  322. # Arguments taking multiple values:
  323. # [DEPENDS] Optional list of nodeset names on which this nodeset depends. These names must match any name from a previous
  324. # call to this funtion. E.g. 'di' if you are generating the 'plcopen' nodeset
  325. #
  326. #
  327. function(ua_generate_nodeset_and_datatypes)
  328. set(options INTERNAL)
  329. set(oneValueArgs NAME FILE_NS FILE_CSV FILE_BSD NAMESPACE_IDX)
  330. set(multiValueArgs DEPENDS)
  331. cmake_parse_arguments(UA_GEN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  332. # ------ Argument checking -----
  333. if(NOT UA_GEN_NAME OR "${UA_GEN_NAME}" STREQUAL "")
  334. message(FATAL_ERROR "ua_generate_nodeset_and_datatypes function requires a value for the NAME argument")
  335. endif()
  336. if(NOT UA_GEN_FILE_NS OR "${UA_GEN_FILE_NS}" STREQUAL "")
  337. message(FATAL_ERROR "ua_generate_nodeset_and_datatypes function requires a value for the FILE_NS argument")
  338. endif()
  339. if((NOT UA_GEN_FILE_CSV OR "${UA_GEN_FILE_CSV}" STREQUAL "") AND
  340. (NOT "${UA_GEN_FILE_BSD}" STREQUAL "" OR
  341. NOT "${UA_GEN_NAMESPACE_IDX}" STREQUAL ""))
  342. message(FATAL_ERROR "ua_generate_nodeset_and_datatypes function requires FILE_CSV argument if any of FILE_BSD or NAMESPACE_IDX are set")
  343. endif()
  344. if((NOT UA_GEN_FILE_BSD OR "${UA_GEN_FILE_BSD}" STREQUAL "") AND
  345. (NOT "${UA_GEN_FILE_CSV}" STREQUAL "" OR
  346. NOT "${UA_GEN_NAMESPACE_IDX}" STREQUAL ""))
  347. message(FATAL_ERROR "ua_generate_nodeset_and_datatypes function requires FILE_BSD argument if any of FILE_CSV or NAMESPACE_IDX are set")
  348. endif()
  349. if(NOT UA_GEN_NAMESPACE_IDX OR "${UA_GEN_NAMESPACE_IDX}" STREQUAL "" AND
  350. (NOT "${UA_GEN_FILE_CSV}" STREQUAL "" OR
  351. NOT "${UA_GEN_FILE_BSD}" STREQUAL ""))
  352. message(FATAL_ERROR "ua_generate_nodeset_and_datatypes function requires NAMESPACE_IDX argument if any of FILE_CSV or FILE_BSD are set")
  353. endif()
  354. set(NODESET_DEPENDS_TARGET "")
  355. set(NODESET_TYPES_ARRAY "UA_TYPES")
  356. if(NOT "${UA_GEN_FILE_BSD}" STREQUAL "")
  357. # Generate Datatypes for nodeset
  358. ua_generate_datatypes(
  359. NAME "ua_types_${UA_GEN_NAME}"
  360. TARGET_SUFFIX "types-${UA_GEN_NAME}"
  361. NAMESPACE_IDX ${UA_GEN_NAMESPACE_IDX}
  362. FILE_CSV "${UA_GEN_FILE_CSV}"
  363. FILES_BSD "${UA_GEN_FILE_BSD}"
  364. )
  365. set(NODESET_DEPENDS_TARGET "open62541-generator-types-${UA_GEN_NAME}")
  366. string(TOUPPER "${UA_GEN_NAME}" GEN_UPPER_NAME)
  367. set(NODESET_TYPES_ARRAY "UA_TYPES_${GEN_UPPER_NAME}")
  368. endif()
  369. # Create a list of nodesets on which this nodeset depends on
  370. if (NOT UA_GEN_DEPENDS OR "${UA_GEN_DEPENDS}" STREQUAL "" )
  371. set(NODESET_DEPENDS "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml")
  372. set(TYPES_DEPENDS "UA_TYPES")
  373. else()
  374. foreach(f ${UA_GEN_DEPENDS})
  375. get_property(DEPENDS_FILE GLOBAL PROPERTY "UA_GEN_NS_DEPENDS_FILE_${f}")
  376. if(NOT DEPENDS_FILE OR "${DEPENDS_FILE}" STREQUAL "")
  377. message(FATAL_ERROR "Nodeset dependency ${f} needs to be generated before ${UA_GEN_NAME}")
  378. endif()
  379. set(NODESET_DEPENDS ${NODESET_DEPENDS} "${DEPENDS_FILE}")
  380. get_property(DEPENDS_TYPES GLOBAL PROPERTY "UA_GEN_NS_DEPENDS_TYPES_${f}")
  381. set(TYPES_DEPENDS ${TYPES_DEPENDS} "${DEPENDS_TYPES}")
  382. set(NODESET_DEPENDS_TARGET ${NODESET_DEPENDS_TARGET} "open62541-generator-ns-${f}")
  383. endforeach()
  384. endif()
  385. set(NODESET_INTERNAL "")
  386. if (${UA_GEN_INTERNAL})
  387. set(NODESET_INTERNAL "INTERNAL")
  388. endif()
  389. ua_generate_nodeset(
  390. NAME "${UA_GEN_NAME}"
  391. FILE "${UA_GEN_FILE_NS}"
  392. TYPES_ARRAY "${NODESET_TYPES_ARRAY}"
  393. ${NODESET_INTERNAL}
  394. DEPENDS_TYPES ${TYPES_DEPENDS}
  395. DEPENDS_NS ${NODESET_DEPENDS}
  396. DEPENDS_TARGET ${NODESET_DEPENDS_TARGET}
  397. )
  398. endfunction()