CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. cmake_minimum_required(VERSION 3.0...3.12)
  2. project(open62541-examples)
  3. if(${CMAKE_VERSION} VERSION_LESS 3.12)
  4. cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
  5. endif()
  6. # This examples folder can also be built standalone.
  7. # First install open62541 using `make install` then
  8. # copy this folder to any other location and call CMake directly:
  9. #
  10. # cp -r open62541/examples $HOME/open62541_examples
  11. # cd $HOME/open62541_examples
  12. # mkdir build && cd build
  13. # cmake -DUA_NAMESPACE_ZERO=FULL ..
  14. # make -j
  15. if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  16. # Examples are built standalone. Find installed open62541
  17. if(UA_NAMESPACE_ZERO STREQUAL "FULL")
  18. find_package(open62541 REQUIRED COMPONENTS FullNamespace)
  19. else()
  20. find_package(open62541 REQUIRED)
  21. endif()
  22. if(NOT UA_TOOLS_DIR)
  23. set(UA_TOOLS_DIR ${open62541_TOOLS_DIR})
  24. endif()
  25. if(NOT UA_NODESET_DIR)
  26. set(UA_NODESET_DIR ${open62541_NODESET_DIR})
  27. endif()
  28. function(assign_source_group)
  29. # define empty function. We don't need it in standalone
  30. endfunction(assign_source_group)
  31. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  32. endif()
  33. # Required for common.h header file used in examples
  34. include_directories(${CMAKE_CURRENT_LIST_DIR})
  35. if(UA_ENABLE_AMALGAMATION)
  36. add_definitions(-DUA_ENABLE_AMALGAMATION)
  37. endif()
  38. #############################
  39. # Compiled binaries folders #
  40. #############################
  41. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
  42. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/examples)
  43. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/examples)
  44. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/bin/examples)
  45. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/bin/examples)
  46. macro(add_example EXAMPLE_NAME EXAMPLE_SOURCE)
  47. add_executable(${EXAMPLE_NAME} ${STATIC_OBJECTS} ${EXAMPLE_SOURCE} ${ARGN} ${PROJECT_SOURCE_DIR}/common.h)
  48. target_link_libraries(${EXAMPLE_NAME} open62541::open62541)
  49. assign_source_group(${EXAMPLE_SOURCE})
  50. set_target_properties(${EXAMPLE_NAME} PROPERTIES FOLDER "open62541/examples")
  51. set_target_properties(${EXAMPLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  52. if(UA_COMPILE_AS_CXX)
  53. set_source_files_properties(${EXAMPLE_SOURCE} PROPERTIES LANGUAGE CXX)
  54. endif()
  55. endmacro()
  56. #############
  57. # Tutorials #
  58. #############
  59. add_example(tutorial_datatypes tutorial_datatypes.c)
  60. add_example(tutorial_server_firststeps tutorial_server_firststeps.c)
  61. add_example(tutorial_server_variable tutorial_server_variable.c)
  62. add_example(tutorial_server_datasource tutorial_server_datasource.c)
  63. if(UA_ENABLE_SUBSCRIPTIONS)
  64. add_example(tutorial_server_monitoreditems tutorial_server_monitoreditems.c)
  65. endif()
  66. add_example(tutorial_server_variabletype tutorial_server_variabletype.c)
  67. add_example(tutorial_server_object tutorial_server_object.c)
  68. if(UA_ENABLE_METHODCALLS)
  69. add_example(tutorial_server_method tutorial_server_method.c)
  70. endif()
  71. add_example(tutorial_client_firststeps tutorial_client_firststeps.c)
  72. add_example(tutorial_client_events tutorial_client_events.c)
  73. if(UA_ENABLE_SUBSCRIPTIONS_EVENTS)
  74. add_example(tutorial_server_events tutorial_server_events.c)
  75. endif()
  76. ##################
  77. # Example Server #
  78. ##################
  79. add_example(server_ctt server_ctt.c)
  80. install(PROGRAMS $<TARGET_FILE:server_ctt>
  81. DESTINATION bin
  82. RENAME ua_server_ctt.exe)
  83. ##################
  84. # Example Client #
  85. ##################
  86. add_example(client client.c)
  87. if(UA_ENABLE_HISTORIZING)
  88. add_example(client_historical client_historical.c)
  89. endif()
  90. install(PROGRAMS $<TARGET_FILE:client>
  91. DESTINATION bin
  92. RENAME ua_client)
  93. add_example(client_async client_async.c)
  94. add_example(client_connect_loop client_connect_loop.c)
  95. add_example(client_connectivitycheck_loop client_connectivitycheck_loop.c)
  96. if(UA_ENABLE_SUBSCRIPTIONS)
  97. add_example(client_subscription_loop client_subscription_loop.c)
  98. endif()
  99. ####################
  100. # Feature Examples #
  101. ####################
  102. add_example(server_mainloop server_mainloop.c)
  103. add_example(server_instantiation server_instantiation.c)
  104. add_example(server_repeated_job server_repeated_job.c)
  105. add_example(server_inheritance server_inheritance.c)
  106. if(UA_ENABLE_HISTORIZING)
  107. add_example(tutorial_server_historicaldata tutorial_server_historicaldata.c)
  108. endif()
  109. if(UA_ENABLE_ENCRYPTION)
  110. add_example(server_encryption encryption/server_encryption.c)
  111. add_example(client_encryption encryption/client_encryption.c)
  112. target_include_directories(server_encryption PRIVATE "${PROJECT_SOURCE_DIR}/examples")
  113. target_include_directories(client_encryption PRIVATE "${PROJECT_SOURCE_DIR}/examples")
  114. endif()
  115. add_example(custom_datatype_client custom_datatype/client_types_custom.c)
  116. add_example(custom_datatype_server custom_datatype/server_types_custom.c)
  117. if(UA_ENABLE_NODEMANAGEMENT)
  118. add_example(access_control_server access_control/server_access_control.c)
  119. add_example(access_control_client access_control/client_access_control.c)
  120. endif()
  121. if(UA_ENABLE_DISCOVERY_MULTICAST)
  122. add_example(discovery_server_lds discovery/server_lds.c)
  123. add_example(discovery_server_register discovery/server_register.c)
  124. add_example(discovery_client_find_servers discovery/client_find_servers.c)
  125. add_example(discovery_server_multicast discovery/server_multicast.c)
  126. endif()
  127. add_subdirectory(nodeset)
  128. ####################
  129. # Example PubSub #
  130. ####################
  131. if(UA_ENABLE_PUBSUB)
  132. add_example(tutorial_pubsub_connection pubsub/tutorial_pubsub_connection.c)
  133. add_example(tutorial_pubsub_publish pubsub/tutorial_pubsub_publish.c)
  134. if(UA_ENABLE_AMALGAMATION)
  135. message(WARNING "PubSub subscriber tutorial (preview) can not be used with AMALGAMATION. Skipping tutorial_pubsub_subscribe.")
  136. else(NOT UA_ENABLE_AMALGAMATION)
  137. add_example(tutorial_pubsub_subscribe pubsub/tutorial_pubsub_subscribe.c)
  138. add_example(pubsub_subscribe_standalone pubsub/pubsub_subscribe_standalone.c)
  139. endif()
  140. endif()