CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
  9. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
  10. list(APPEND LIBS ${open62541_LIBRARIES})
  11. if(NOT WIN32)
  12. if(QNXNTO)
  13. list(APPEND LIBS socket)
  14. list(APPEND LIBS c)
  15. list(APPEND LIBS stdc++)
  16. else()
  17. list(APPEND LIBS pthread)
  18. if (NOT APPLE)
  19. list(APPEND LIBS rt)
  20. endif()
  21. endif()
  22. else()
  23. list(APPEND LIBS ws2_32)
  24. endif()
  25. if(UA_ENABLE_MULTITHREADING)
  26. list(APPEND LIBS urcu-cds urcu urcu-common)
  27. endif(UA_ENABLE_MULTITHREADING)
  28. set(STATIC_OBJECTS $<TARGET_OBJECTS:open62541-object>)
  29. if(WIN32 AND BUILD_SHARED_LIBS)
  30. # on windows the .dll.a file has to be used for the linker
  31. list(APPEND LIBS open62541)
  32. set(STATIC_OBJECTS "")
  33. endif()
  34. macro(add_example EXAMPLE_NAME EXAMPLE_SOURCE)
  35. add_executable(${EXAMPLE_NAME} ${STATIC_OBJECTS} ${EXAMPLE_SOURCE})
  36. target_link_libraries(${EXAMPLE_NAME} ${LIBS})
  37. assign_source_group(${EXAMPLE_SOURCE})
  38. add_dependencies(${EXAMPLE_NAME} open625451_amalgamation)
  39. set_target_properties(${EXAMPLE_NAME} PROPERTIES FOLDER "open62541/examples")
  40. if(UA_COMPILE_AS_CXX)
  41. set_source_files_properties(${EXAMPLE_SOURCE} PROPERTIES LANGUAGE CXX)
  42. endif()
  43. endmacro()
  44. #############
  45. # Tutorials #
  46. #############
  47. add_example(tutorial_datatypes tutorial_datatypes.c)
  48. add_example(tutorial_server_firststeps tutorial_server_firststeps.c)
  49. add_example(tutorial_server_variable tutorial_server_variable.c)
  50. add_example(tutorial_server_datasource tutorial_server_datasource.c)
  51. add_example(tutorial_server_variabletype tutorial_server_variabletype.c)
  52. add_example(tutorial_server_object tutorial_server_object.c)
  53. if(UA_ENABLE_METHODCALLS)
  54. add_example(tutorial_server_method tutorial_server_method.c)
  55. endif()
  56. add_example(tutorial_client_firststeps tutorial_client_firststeps.c)
  57. ##################
  58. # Example Server #
  59. ##################
  60. add_example(server server.c)
  61. ##################
  62. # Example Client #
  63. ##################
  64. add_example(client client.c)
  65. ####################
  66. # Feature Examples #
  67. ####################
  68. add_example(server_mainloop server_mainloop.c)
  69. add_example(server_instantiation server_instantiation.c)
  70. add_example(server_repeated_job server_repeated_job.c)
  71. if(NOT BUILD_SHARED_LIBS)
  72. # needs internal methods which are not exported in the dynamic lib
  73. add_example(server_readspeed server_readspeed.c)
  74. target_include_directories(server_readspeed PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
  75. endif()
  76. add_example(server_inheritance server_inheritance.c)
  77. if(NOT BUILD_SHARED_LIBS AND UA_BUILD_EXAMPLES_NODESET_COMPILER)
  78. # needs internal methods which are not exported in the dynamic lib
  79. add_example(server_nodeset "server_nodeset.c ${PROJECT_BINARY_DIR}/src_generated/nodeset.c")
  80. target_include_directories(server_nodeset PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
  81. endif()
  82. if(UA_BUILD_SELFSIGNED_CERTIFICATE)
  83. find_package(OpenSSL REQUIRED)
  84. add_custom_command(OUTPUT server_cert.der ca.crt
  85. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${CMAKE_CURRENT_BINARY_DIR}
  86. DEPENDS ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py
  87. ${PROJECT_SOURCE_DIR}/tools/certs/localhost.cnf)
  88. add_custom_target(selfsigned ALL DEPENDS server_cert.der ca.crt)
  89. add_executable(server_certificate server_certificate.c ${STATIC_OBJECTS} server_cert.der ca.crt)
  90. target_link_libraries(server_certificate ${LIBS})
  91. endif()
  92. if(UA_ENABLE_DISCOVERY)
  93. add_example(discovery_server_lds discovery/server_lds.c)
  94. add_example(discovery_server_register discovery/server_register.c)
  95. add_example(discovery_client_find_servers discovery/client_find_servers.c)
  96. if(UA_ENABLE_DISCOVERY_MULTICAST)
  97. add_example(discovery_server_multicast discovery/server_multicast.c)
  98. endif()
  99. endif()