CMakeLists.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ####################
  2. # Nodeset Examples #
  3. ####################
  4. ###################
  5. # Custom XML #
  6. ###################
  7. # generate namespace from XML file
  8. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/example_nodeset.c
  9. ${PROJECT_BINARY_DIR}/src_generated/example_nodeset.h
  10. PRE_BUILD
  11. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  12. --types-array=UA_TYPES
  13. --existing ${UA_FILE_NS0}
  14. --xml ${PROJECT_SOURCE_DIR}/examples/nodeset/server_nodeset.xml
  15. ${PROJECT_BINARY_DIR}/src_generated/example_nodeset
  16. DEPENDS ${UA_FILE_NS0}
  17. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  18. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodes.py
  19. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset.py
  20. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/datatypes.py
  21. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541.py
  22. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_nodes.py
  23. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_datatypes.py
  24. ${PROJECT_SOURCE_DIR}/examples/nodeset/server_nodeset.xml)
  25. # The .csv file can be created from within UaModeler or manually
  26. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/example_nodeset_ids.h
  27. PRE_BUILD
  28. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_nodeid_header.py
  29. ${PROJECT_SOURCE_DIR}/examples/nodeset/server_nodeset.csv ${PROJECT_BINARY_DIR}/src_generated/example_nodeset_ids EXAMPLE_NS
  30. DEPENDS ${PROJECT_SOURCE_DIR}/tools/generate_nodeid_header.py
  31. ${PROJECT_SOURCE_DIR}/examples/nodeset/server_nodeset.csv)
  32. add_example(server_nodeset server_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/example_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/example_nodeset_ids.h)
  33. if(UA_COMPILE_AS_CXX)
  34. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/example_nodeset.c PROPERTIES LANGUAGE CXX)
  35. endif()
  36. ###################
  37. # PLCopen Nodeset #
  38. ###################
  39. # PLCopen requires the full ns0 as basis
  40. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  41. # Generate types for DI namespace
  42. set(UA_TYPES_OUT "ua_types_di")
  43. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/${UA_TYPES_OUT}_generated.c
  44. ${PROJECT_BINARY_DIR}/src_generated/${UA_TYPES_OUT}_generated.h
  45. ${PROJECT_BINARY_DIR}/src_generated/${UA_TYPES_OUT}_generated_handling.h
  46. ${PROJECT_BINARY_DIR}/src_generated/${UA_TYPES_OUT}_generated_encoding_binary.h
  47. PRE_BUILD
  48. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  49. --namespace=2
  50. --type-csv=${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/OpcUaDiModel.csv
  51. --type-bsd=${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.Types.bsd
  52. --no-builtin
  53. ${PROJECT_BINARY_DIR}/src_generated/${UA_TYPES_OUT}
  54. DEPENDS ${PROJECT_SOURCE_DIR}/tools/generate_datatypes.py
  55. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/OpcUaDiModel.csv
  56. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.Types.bsd)
  57. add_custom_target(open62541-generator-types-di DEPENDS ${PROJECT_BINARY_DIR}/src_generated/${UA_TYPES_OUT}_generated.c)
  58. # generate DI namespace
  59. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c
  60. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.h
  61. PRE_BUILD
  62. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  63. --internal-headers
  64. --types-array=UA_TYPES
  65. --types-array=UA_TYPES_DI
  66. --existing ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
  67. --xml ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml
  68. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di
  69. DEPENDS ${UA_FILE_NS0}
  70. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  71. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodes.py
  72. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset.py
  73. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/datatypes.py
  74. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541.py
  75. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_nodes.py
  76. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_datatypes.py
  77. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
  78. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml
  79. )
  80. add_custom_target(open62541-generator-ns-di DEPENDS ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c)
  81. add_dependencies(open62541-generator-ns-di open62541-generator-types-di)
  82. # generate PLCopen namespace which is using DI
  83. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc.c
  84. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc.h
  85. PRE_BUILD
  86. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  87. --internal-headers
  88. --types-array=UA_TYPES
  89. --types-array=UA_TYPES_DI
  90. # PLCopen has no specific type definition, thus use the default UA_TYPES to ignore it
  91. --types-array=UA_TYPES
  92. --existing ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
  93. --existing ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml
  94. --xml ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/PLCopen/Opc.Ua.Plc.NodeSet2.xml
  95. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc
  96. DEPENDS ${UA_FILE_NS0}
  97. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset_compiler.py
  98. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodes.py
  99. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/nodeset.py
  100. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/datatypes.py
  101. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541.py
  102. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_nodes.py
  103. ${PROJECT_SOURCE_DIR}/tools/nodeset_compiler/backend_open62541_datatypes.py
  104. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
  105. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml
  106. ${PROJECT_SOURCE_DIR}/deps/ua-nodeset/PLCopen/Opc.Ua.Plc.NodeSet2.xml
  107. )
  108. add_custom_target(open62541-generator-ns-plc DEPENDS ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc.c)
  109. add_dependencies(open62541-generator-ns-plc open62541-generator-ns-di)
  110. add_example(server_nodeset_plcopen server_nodeset_plcopen.c
  111. ${PROJECT_BINARY_DIR}/src_generated/ua_types_di_generated.c
  112. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c
  113. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc.c)
  114. add_dependencies(server_nodeset_plcopen open62541-generator-ns-plc)
  115. target_include_directories(server_nodeset_plcopen PRIVATE ${PROJECT_SOURCE_DIR}/src) # needs an internal header
  116. if(UA_COMPILE_AS_CXX)
  117. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/ua_types_di_generated.c PROPERTIES LANGUAGE CXX)
  118. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c PROPERTIES LANGUAGE CXX)
  119. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc.c PROPERTIES LANGUAGE CXX)
  120. endif()
  121. endif()