CMakeLists.txt 3.0 KB

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