macros_public.cmake 20 KB

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