CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ####################
  2. # Nodeset Examples #
  3. ####################
  4. ###################
  5. # Custom XML #
  6. ###################
  7. set(FILE_CSV_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  8. set(FILE_BSD_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  9. set(FILE_NS_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  10. if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  11. # needed or cmake doesn't recognize dependencies of generated files
  12. set(PROJECT_BINARY_DIR ${CMAKE_BINARY_DIR})
  13. endif()
  14. # generate namespace from XML file
  15. if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  16. ua_generate_nodeset_and_datatypes(
  17. NAME "example"
  18. FILE_NS "${FILE_NS_DIRPREFIX}/server_nodeset.xml"
  19. DEPENDS "${CMAKE_SOURCE_DIR}/tools/schema/Opc.Ua.NodeSet2.Minimal.xml"
  20. )
  21. else()
  22. # standalone examples build expects already installed Opc.Ua.NodeSet2.Minimal.xml
  23. ua_generate_nodeset_and_datatypes(
  24. NAME "example"
  25. FILE_NS "${FILE_NS_DIRPREFIX}/server_nodeset.xml"
  26. )
  27. endif()
  28. # The .csv file can be created from within UaModeler or manually
  29. ua_generate_nodeid_header(
  30. NAME "example_nodeids"
  31. ID_PREFIX "EXAMPLE_NS"
  32. TARGET_SUFFIX "ids_example"
  33. FILE_CSV "${FILE_CSV_DIRPREFIX}/server_nodeset.csv"
  34. )
  35. add_example(server_nodeset server_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_example.c ${PROJECT_BINARY_DIR}/src_generated/example_nodeids.h)
  36. if(UA_COMPILE_AS_CXX)
  37. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/ua_namespace_example.c PROPERTIES LANGUAGE CXX)
  38. endif()
  39. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  40. ua_generate_nodeset_and_datatypes(
  41. NAME "testnodeset"
  42. FILE_CSV "${FILE_CSV_DIRPREFIX}/testnodeset.csv"
  43. FILE_BSD "${FILE_BSD_DIRPREFIX}/testtypes.bsd"
  44. NAMESPACE_IDX 2
  45. FILE_NS "${FILE_NS_DIRPREFIX}/testnodeset.xml"
  46. INTERNAL
  47. )
  48. add_example(server_testnodeset server_testnodeset.c
  49. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_testnodeset.c
  50. ${PROJECT_BINARY_DIR}/src_generated/ua_types_testnodeset_generated.c)
  51. add_dependencies(server_testnodeset open62541-generator-ns-testnodeset)
  52. endif()
  53. ###################
  54. # PLCopen Nodeset #
  55. ###################
  56. if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  57. set(FILE_CSV_DIRPREFIX ${CMAKE_SOURCE_DIR}/deps/ua-nodeset)
  58. set(FILE_BSD_PLCOPEN_DIRPREFIX ${CMAKE_SOURCE_DIR}/deps/ua-nodeset)
  59. set(FILE_BSD_POWERLINK_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  60. set(FILE_NS_DIRPREFIX ${CMAKE_SOURCE_DIR}/deps/ua-nodeset)
  61. else()
  62. set(FILE_CSV_DIRPREFIX ${UA_TOOLS_DIR}/ua-nodeset)
  63. set(FILE_BSD_PLCOPEN_DIRPREFIX ${UA_TOOLS_DIR}/ua-nodeset)
  64. set(FILE_BSD_POWERLINK_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  65. set(FILE_NS_DIRPREFIX ${UA_TOOLS_DIR}/ua-nodeset)
  66. endif()
  67. # PLCopen requires the full ns0 as basis
  68. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  69. # Generate types and namespace for DI
  70. ua_generate_nodeset_and_datatypes(
  71. NAME "di"
  72. FILE_CSV "${FILE_CSV_DIRPREFIX}/DI/OpcUaDiModel.csv"
  73. FILE_BSD "${FILE_BSD_PLCOPEN_DIRPREFIX}/DI/Opc.Ua.Di.Types.bsd"
  74. NAMESPACE_IDX 2
  75. FILE_NS "${FILE_NS_DIRPREFIX}/DI/Opc.Ua.Di.NodeSet2.xml"
  76. INTERNAL
  77. )
  78. # generate PLCopen namespace which is using DI
  79. ua_generate_nodeset_and_datatypes(
  80. NAME "plc"
  81. # PLCopen does not define custom types. Only generate the nodeset
  82. FILE_NS "${FILE_NS_DIRPREFIX}/PLCopen/Opc.Ua.Plc.NodeSet2.xml"
  83. # PLCopen depends on the di nodeset, which must be generated before
  84. DEPENDS "di"
  85. INTERNAL
  86. )
  87. add_example(server_nodeset_plcopen server_nodeset_plcopen.c
  88. ${PROJECT_BINARY_DIR}/src_generated/ua_types_di_generated.c
  89. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c
  90. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_plc.c)
  91. add_dependencies(server_nodeset_plcopen open62541-generator-ns-plc)
  92. endif()
  93. # POWERLINK requires the full ns0 as basis
  94. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  95. # generate powerlink namespace which is using DI
  96. ua_generate_nodeset_and_datatypes(
  97. NAME "powerlink"
  98. FILE_CSV "${FILE_CSV_DIRPREFIX}/POWERLINK/Opc.Ua.POWERLINK.NodeIds.csv"
  99. FILE_BSD "${FILE_BSD_POWERLINK_DIRPREFIX}/Opc.Ua.POWERLINK.NodeSet2.bsd"
  100. NAMESPACE_IDX 3
  101. FILE_NS "${FILE_NS_DIRPREFIX}/POWERLINK/Opc.Ua.POWERLINK.NodeSet2.xml"
  102. # POWERLINK depends on the di nodeset, which must be generated before
  103. DEPENDS "di"
  104. INTERNAL
  105. )
  106. add_example(server_nodeset_powerlink server_nodeset_powerlink.c
  107. ${PROJECT_BINARY_DIR}/src_generated/ua_types_di_generated.c
  108. ${PROJECT_BINARY_DIR}/src_generated/ua_types_powerlink_generated.c
  109. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c
  110. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_powerlink.c)
  111. add_dependencies(server_nodeset_powerlink open62541-generator-ns-powerlink)
  112. endif()