CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. include_directories(${PROJECT_SOURCE_DIR}/include)
  2. include_directories(${PROJECT_SOURCE_DIR}/plugins)
  3. #############################
  4. # Compiled binaries folders #
  5. #############################
  6. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/examples)
  7. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/examples)
  8. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/examples)
  9. #######
  10. if(UA_ENABLE_AMALGAMATION)
  11. include_directories(${PROJECT_BINARY_DIR}) # contain open62541.h
  12. else()
  13. add_definitions(-DUA_NO_AMALGAMATION)
  14. endif()
  15. list(APPEND LIBS ${open62541_LIBRARIES})
  16. if(NOT WIN32)
  17. list(APPEND LIBS pthread)
  18. if (NOT APPLE)
  19. list(APPEND LIBS rt)
  20. endif()
  21. else()
  22. list(APPEND LIBS ws2_32)
  23. endif()
  24. if(UA_ENABLE_MULTITHREADING)
  25. list(APPEND LIBS urcu-cds urcu urcu-common)
  26. endif(UA_ENABLE_MULTITHREADING)
  27. macro(add_example EXAMPLE_NAME EXAMPLE_SOURCE)
  28. add_executable(${EXAMPLE_NAME} $<TARGET_OBJECTS:open62541-object> ${EXAMPLE_SOURCE})
  29. target_link_libraries(${EXAMPLE_NAME} ${LIBS})
  30. assign_source_group(${EXAMPLE_SOURCE})
  31. set_target_properties(${EXAMPLE_NAME} PROPERTIES FOLDER "open62541/examples")
  32. if(UA_COMPILE_AS_CXX)
  33. set_source_files_properties(${EXAMPLE_SOURCE} PROPERTIES LANGUAGE CXX)
  34. endif()
  35. endmacro()
  36. ##################
  37. # Example Server #
  38. ##################
  39. add_example(server server.c)
  40. ##################
  41. # Example Client #
  42. ##################
  43. add_example(client client.c)
  44. ####################
  45. # Feature Examples #
  46. ####################
  47. add_example(server_variable server_variable.c)
  48. add_example(server_mainloop server_mainloop.c)
  49. add_example(server_datasource server_datasource.c)
  50. add_example(server_firstSteps server_firstSteps.c)
  51. add_example(server_instantiation server_instantiation.c)
  52. add_example(server_repeated_job server_repeated_job.c)
  53. add_example(server_readspeed server_readspeed.c)
  54. target_include_directories(server_readspeed PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
  55. add_example(server_inheritance server_inheritance.c)
  56. if(UA_BUILD_EXAMPLES_NODESET_COMPILER)
  57. add_executable(server_nodeset "server_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/nodeset.c")
  58. target_include_directories(server_nodeset PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
  59. endif()
  60. if(UA_ENABLE_METHODCALLS)
  61. add_example(server_method server_method.c)
  62. endif()
  63. if(UA_BUILD_SELFSIGNED_CERTIFICATE)
  64. find_package(OpenSSL REQUIRED)
  65. add_custom_command(OUTPUT server_cert.der ca.crt
  66. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${CMAKE_CURRENT_BINARY_DIR}
  67. DEPENDS ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py
  68. ${PROJECT_SOURCE_DIR}/tools/certs/localhost.cnf)
  69. add_custom_target(selfsigned ALL DEPENDS server_cert.der ca.crt)
  70. add_executable(server_certificate server_certificate.c $<TARGET_OBJECTS:open62541-object> server_cert.der ca.crt)
  71. target_link_libraries(server_certificate ${LIBS})
  72. endif()
  73. if(UA_ENABLE_DISCOVERY)
  74. add_example(discovery_server_discovery discovery/server_discovery.c)
  75. add_example(discovery_server_register discovery/server_register.c)
  76. add_example(discovery_client_find_servers discovery/client_find_servers.c)
  77. endif()
  78. add_example(client_firstSteps client_firstSteps.c)