CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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
  36. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_namespace_example.c
  37. ${PROJECT_BINARY_DIR}/src_generated/open62541/example_nodeids.h)
  38. if(UA_COMPILE_AS_CXX)
  39. set_source_files_properties(${PROJECT_BINARY_DIR}/src_generated/open62541/namespace_example.c PROPERTIES LANGUAGE CXX)
  40. endif()
  41. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  42. ua_generate_nodeset_and_datatypes(
  43. NAME "testnodeset"
  44. FILE_CSV "${FILE_CSV_DIRPREFIX}/testnodeset.csv"
  45. FILE_BSD "${FILE_BSD_DIRPREFIX}/testtypes.bsd"
  46. NAMESPACE_IDX 2
  47. FILE_NS "${FILE_NS_DIRPREFIX}/testnodeset.xml"
  48. INTERNAL
  49. )
  50. add_example(server_testnodeset server_testnodeset.c
  51. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_namespace_testnodeset.c
  52. ${PROJECT_BINARY_DIR}/src_generated/open62541/types_testnodeset_generated.c)
  53. add_dependencies(server_testnodeset open62541-generator-ns-testnodeset)
  54. endif()
  55. ###################
  56. # PLCopen Nodeset #
  57. ###################
  58. if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  59. set(FILE_CSV_DIRPREFIX ${CMAKE_SOURCE_DIR}/deps/ua-nodeset)
  60. set(FILE_BSD_PLCOPEN_DIRPREFIX ${CMAKE_SOURCE_DIR}/deps/ua-nodeset)
  61. set(FILE_BSD_POWERLINK_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  62. set(FILE_NS_DIRPREFIX ${CMAKE_SOURCE_DIR}/deps/ua-nodeset)
  63. else()
  64. set(FILE_CSV_DIRPREFIX ${UA_TOOLS_DIR}/ua-nodeset)
  65. set(FILE_BSD_PLCOPEN_DIRPREFIX ${UA_TOOLS_DIR}/ua-nodeset)
  66. set(FILE_BSD_POWERLINK_DIRPREFIX ${PROJECT_SOURCE_DIR}/nodeset)
  67. set(FILE_NS_DIRPREFIX ${UA_TOOLS_DIR}/ua-nodeset)
  68. endif()
  69. # PLCopen requires the full ns0 as basis
  70. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  71. # Generate types and namespace for DI
  72. ua_generate_nodeset_and_datatypes(
  73. NAME "di"
  74. FILE_CSV "${FILE_CSV_DIRPREFIX}/DI/OpcUaDiModel.csv"
  75. FILE_BSD "${FILE_BSD_PLCOPEN_DIRPREFIX}/DI/Opc.Ua.Di.Types.bsd"
  76. NAMESPACE_IDX 2
  77. FILE_NS "${FILE_NS_DIRPREFIX}/DI/Opc.Ua.Di.NodeSet2.xml"
  78. INTERNAL
  79. )
  80. # generate PLCopen namespace which is using DI
  81. ua_generate_nodeset_and_datatypes(
  82. NAME "plc"
  83. # PLCopen does not define custom types. Only generate the nodeset
  84. FILE_NS "${FILE_NS_DIRPREFIX}/PLCopen/Opc.Ua.Plc.NodeSet2.xml"
  85. # PLCopen depends on the di nodeset, which must be generated before
  86. DEPENDS "di"
  87. INTERNAL
  88. )
  89. add_example(server_nodeset_plcopen server_nodeset_plcopen.c
  90. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_types_di_generated.c
  91. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_namespace_di.c
  92. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_namespace_plc.c)
  93. add_dependencies(server_nodeset_plcopen open62541-generator-ns-plc)
  94. endif()
  95. # POWERLINK requires the full ns0 as basis
  96. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  97. # generate powerlink namespace which is using DI
  98. ua_generate_nodeset_and_datatypes(
  99. NAME "powerlink"
  100. FILE_CSV "${FILE_CSV_DIRPREFIX}/POWERLINK/Opc.Ua.POWERLINK.NodeIds.csv"
  101. FILE_BSD "${FILE_BSD_POWERLINK_DIRPREFIX}/Opc.Ua.POWERLINK.NodeSet2.bsd"
  102. NAMESPACE_IDX 3
  103. FILE_NS "${FILE_NS_DIRPREFIX}/POWERLINK/Opc.Ua.POWERLINK.NodeSet2.xml"
  104. # POWERLINK depends on the di nodeset, which must be generated before
  105. DEPENDS "di"
  106. INTERNAL
  107. )
  108. add_example(server_nodeset_powerlink server_nodeset_powerlink.c
  109. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_types_di_generated.c
  110. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_types_powerlink_generated.c
  111. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_namespace_di.c
  112. ${PROJECT_BINARY_DIR}/src_generated/open62541/ua_namespace_powerlink.c)
  113. add_dependencies(server_nodeset_powerlink open62541-generator-ns-powerlink)
  114. endif()