CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. include_directories(${PROJECT_SOURCE_DIR}/include)
  2. include_directories(${PROJECT_SOURCE_DIR}/plugins)
  3. include_directories(${PROJECT_BINARY_DIR})
  4. #############################
  5. # Compiled binaries folders #
  6. #############################
  7. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
  8. macro(add_example EXAMPLE_NAME EXAMPLE_SOURCE)
  9. add_executable(${EXAMPLE_NAME} ${STATIC_OBJECTS} ${EXAMPLE_SOURCE} ${ARGN})
  10. target_link_libraries(${EXAMPLE_NAME} open62541 ${open62541_LIBRARIES})
  11. assign_source_group(${EXAMPLE_SOURCE})
  12. add_dependencies(${EXAMPLE_NAME} open62541-amalgamation-header open62541-amalgamation-source)
  13. set_target_properties(${EXAMPLE_NAME} PROPERTIES FOLDER "open62541/examples")
  14. set_target_properties(${EXAMPLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/examples")
  15. if(UA_COMPILE_AS_CXX)
  16. set_source_files_properties(${EXAMPLE_SOURCE} PROPERTIES LANGUAGE CXX)
  17. endif()
  18. endmacro()
  19. #############
  20. # Tutorials #
  21. #############
  22. add_example(tutorial_datatypes tutorial_datatypes.c)
  23. add_example(tutorial_server_firststeps tutorial_server_firststeps.c)
  24. add_example(tutorial_server_variable tutorial_server_variable.c)
  25. add_example(tutorial_server_datasource tutorial_server_datasource.c)
  26. add_example(tutorial_server_variabletype tutorial_server_variabletype.c)
  27. add_example(tutorial_server_object tutorial_server_object.c)
  28. if(UA_ENABLE_METHODCALLS)
  29. add_example(tutorial_server_method tutorial_server_method.c)
  30. endif()
  31. add_example(tutorial_client_firststeps tutorial_client_firststeps.c)
  32. ##################
  33. # Example Server #
  34. ##################
  35. add_example(server server.c)
  36. ##################
  37. # Example Client #
  38. ##################
  39. add_example(client client.c)
  40. ####################
  41. # Feature Examples #
  42. ####################
  43. add_example(server_mainloop server_mainloop.c)
  44. add_example(server_instantiation server_instantiation.c)
  45. add_example(server_repeated_job server_repeated_job.c)
  46. add_example(server_inheritance server_inheritance.c)
  47. if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
  48. if(BUILD_SHARED_LIBS)
  49. message(FATAL_ERROR "The nodeset compiler currently requires static linking to access internal API")
  50. endif()
  51. # example information model from nodeset xml
  52. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
  53. PRE_BUILD
  54. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  55. -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  56. ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml
  57. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml
  58. ${PROJECT_BINARY_DIR}/src_generated/nodeset
  59. DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
  60. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
  61. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
  62. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
  63. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
  64. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
  65. ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
  66. ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
  67. # needs internal methods which are not exported in the dynamic lib
  68. add_example(server_nodeset ${PROJECT_BINARY_DIR}/src_generated/nodeset.c server_nodeset.c)
  69. target_include_directories(server_nodeset PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
  70. set_target_properties(server_nodeset PROPERTIES COMPILE_FLAGS "-Wno-pedantic -Wno-sign-conversion")
  71. endif()
  72. if(UA_BUILD_SELFSIGNED_CERTIFICATE)
  73. find_package(OpenSSL REQUIRED)
  74. add_custom_command(OUTPUT server_cert.der ca.crt
  75. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${CMAKE_CURRENT_BINARY_DIR}
  76. DEPENDS ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py
  77. ${PROJECT_SOURCE_DIR}/tools/certs/localhost.cnf)
  78. add_custom_target(selfsigned ALL DEPENDS server_cert.der ca.crt)
  79. add_executable(server_certificate server_certificate.c ${STATIC_OBJECTS} server_cert.der ca.crt)
  80. target_link_libraries(server_certificate open62541 ${open62541_LIBRARIES})
  81. endif()
  82. if(UA_ENABLE_DISCOVERY)
  83. add_example(discovery_server_lds discovery/server_lds.c)
  84. add_example(discovery_server_register discovery/server_register.c)
  85. add_example(discovery_client_find_servers discovery/client_find_servers.c)
  86. if(UA_ENABLE_DISCOVERY_MULTICAST)
  87. add_example(discovery_server_multicast discovery/server_multicast.c)
  88. endif()
  89. endif()