CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. include_directories(${PROJECT_SOURCE_DIR}/include)
  2. include_directories(${PROJECT_SOURCE_DIR}/plugins)
  3. include_directories(${PROJECT_BINARY_DIR})
  4. include_directories(${PROJECT_SOURCE_DIR}/examples)
  5. include_directories(${PROJECT_SOURCE_DIR}/arch)
  6. set(examples_headers
  7. ${examples_headers}
  8. ${PROJECT_SOURCE_DIR}/examples/common.h
  9. )
  10. #############################
  11. # Compiled binaries folders #
  12. #############################
  13. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
  14. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/examples)
  15. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/examples)
  16. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/bin/examples)
  17. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/bin/examples)
  18. macro(add_example EXAMPLE_NAME EXAMPLE_SOURCE)
  19. add_executable(${EXAMPLE_NAME} ${STATIC_OBJECTS} ${EXAMPLE_SOURCE} ${ARGN} ${examples_headers})
  20. target_link_libraries(${EXAMPLE_NAME} open62541 ${open62541_LIBRARIES})
  21. assign_source_group(${EXAMPLE_SOURCE})
  22. add_dependencies(${EXAMPLE_NAME} open62541-object)
  23. set_target_properties(${EXAMPLE_NAME} PROPERTIES FOLDER "open62541/examples")
  24. set_target_properties(${EXAMPLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  25. if(UA_COMPILE_AS_CXX)
  26. set_source_files_properties(${EXAMPLE_SOURCE} PROPERTIES LANGUAGE CXX)
  27. endif()
  28. endmacro()
  29. #############
  30. # Tutorials #
  31. #############
  32. add_example(tutorial_datatypes tutorial_datatypes.c)
  33. add_example(tutorial_server_firststeps tutorial_server_firststeps.c)
  34. add_example(tutorial_server_variable tutorial_server_variable.c)
  35. add_example(tutorial_server_datasource tutorial_server_datasource.c)
  36. if(UA_ENABLE_SUBSCRIPTIONS)
  37. add_example(tutorial_server_monitoreditems tutorial_server_monitoreditems.c)
  38. endif()
  39. add_example(tutorial_server_variabletype tutorial_server_variabletype.c)
  40. add_example(tutorial_server_object tutorial_server_object.c)
  41. if(UA_ENABLE_METHODCALLS)
  42. add_example(tutorial_server_method tutorial_server_method.c)
  43. endif()
  44. add_example(tutorial_client_firststeps tutorial_client_firststeps.c)
  45. add_example(tutorial_client_events tutorial_client_events.c)
  46. if(UA_ENABLE_SUBSCRIPTIONS_EVENTS)
  47. add_example(tutorial_server_events tutorial_server_events.c)
  48. endif()
  49. ##################
  50. # Example Server #
  51. ##################
  52. add_example(server_ctt server_ctt.c)
  53. if (WIN32)
  54. install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/server_ctt.exe
  55. DESTINATION bin
  56. RENAME ua_server_ctt.exe)
  57. else()
  58. install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/server_ctt
  59. DESTINATION bin
  60. RENAME ua_server_ctt)
  61. endif()
  62. ##################
  63. # Example Client #
  64. ##################
  65. add_example(client client.c)
  66. if (WIN32)
  67. install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/client.exe
  68. DESTINATION bin
  69. RENAME ua_client.exe)
  70. else()
  71. install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/client
  72. DESTINATION bin
  73. RENAME ua_client)
  74. endif()
  75. add_example(client_async client_async.c)
  76. add_example(client_connect_loop client_connect_loop.c)
  77. add_example(client_connectivitycheck_loop client_connectivitycheck_loop.c)
  78. if(UA_ENABLE_SUBSCRIPTIONS)
  79. add_example(client_subscription_loop client_subscription_loop.c)
  80. endif()
  81. ####################
  82. # Feature Examples #
  83. ####################
  84. add_example(server_mainloop server_mainloop.c)
  85. add_example(server_instantiation server_instantiation.c)
  86. add_example(server_repeated_job server_repeated_job.c)
  87. add_example(server_inheritance server_inheritance.c)
  88. if(UA_ENABLE_ENCRYPTION)
  89. add_example(server_basic128rsa15 encryption/server_basic128rsa15.c)
  90. add_example(server_basic256sha256 encryption/server_basic256sha256.c)
  91. # Add secure client example application
  92. add_example(client_basic128rsa15 encryption/client_basic128rsa15.c)
  93. add_example(client_basic256sha256 encryption/client_basic256sha256.c)
  94. endif()
  95. add_example(custom_datatype_client custom_datatype/client_types_custom.c)
  96. add_example(custom_datatype_server custom_datatype/server_types_custom.c)
  97. if(UA_ENABLE_NODEMANAGEMENT)
  98. add_example(access_control_server access_control/server_access_control.c)
  99. add_example(access_control_client access_control/client_access_control.c)
  100. endif()
  101. if(UA_BUILD_SELFSIGNED_CERTIFICATE)
  102. find_package(OpenSSL REQUIRED)
  103. add_custom_command(OUTPUT server_cert.der
  104. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${CMAKE_CURRENT_BINARY_DIR}
  105. DEPENDS ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py
  106. ${PROJECT_SOURCE_DIR}/tools/certs/localhost.cnf)
  107. add_custom_target(selfsigned ALL DEPENDS server_cert.der)
  108. add_executable(server_certificate server_certificate.c ${STATIC_OBJECTS} server_cert.der)
  109. target_link_libraries(server_certificate open62541 ${open62541_LIBRARIES})
  110. endif()
  111. if(UA_ENABLE_DISCOVERY)
  112. add_example(discovery_server_lds discovery/server_lds.c)
  113. add_example(discovery_server_register discovery/server_register.c)
  114. add_example(discovery_client_find_servers discovery/client_find_servers.c)
  115. if(UA_ENABLE_DISCOVERY_MULTICAST)
  116. add_example(discovery_server_multicast discovery/server_multicast.c)
  117. endif()
  118. endif()
  119. add_subdirectory(nodeset)
  120. ####################
  121. # Example PubSub #
  122. ####################
  123. if(UA_ENABLE_PUBSUB)
  124. add_example(tutorial_pubsub_connection pubsub/tutorial_pubsub_connection.c)
  125. add_example(tutorial_pubsub_publish pubsub/tutorial_pubsub_publish.c)
  126. if(UA_ENABLE_AMALGAMATION)
  127. message(WARNING "PubSub subscriber tutorial (preview) can not be used with AMALGAMATION. Skipping tutorial_pubsub_subscribe.")
  128. else(NOT UA_ENABLE_AMALGAMATION)
  129. add_example(tutorial_pubsub_subscribe pubsub/tutorial_pubsub_subscribe.c)
  130. endif()
  131. endif()