CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. cmake_minimum_required(VERSION 2.6)
  2. project(open62541)
  3. set(open62541_VERSION_MAJOR 0)
  4. set(open62541_VERSION_MINOR 1)
  5. set(CMAKE_VERBOSE_MAKEFILE on )
  6. if(CMAKE_COMPILER_IS_GNUCC)
  7. add_definitions(-std=c99 -pedantic -pipe -fstack-protector -Wall -Wextra
  8. -Wno-unused-parameter -Wno-unused-function -Wno-unused-label
  9. -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar
  10. -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated
  11. -Wformat-security -Werror -ffunction-sections -fdata-sections
  12. -Wl,--gc-sections)
  13. endif(CMAKE_COMPILER_IS_GNUCC)
  14. # multithreading
  15. set(MULTITHREADING OFF CACHE BOOL "Enable multithreading")
  16. if(MULTITHREADING)
  17. find_package(Threads REQUIRED)
  18. endif(MULTITHREADING)
  19. # encodings
  20. set(UA_ENCODING_AMOUNT 1) # binary encoding
  21. set(UA_ENCODING_XML OFF CACHE BOOL "Enable XML-encoding of the UA types")
  22. if(UA_ENCODING_XML)
  23. MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
  24. find_package(EXPAT REQUIRED)
  25. if(EXPAT_FOUND)
  26. include_directories(${EXPAT_INCLUDE_DIRS})
  27. else(EXPAT_FOUND)
  28. message(FATAL_ERROR "Expat library not found.")
  29. endif(EXPAT_FOUND)
  30. endif(UA_ENCODING_XML)
  31. set(UA_ENCODING_JSON OFF CACHE BOOL "Enable JSON-encoding of the UA types")
  32. if(UA_ENCODING_JSON)
  33. MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
  34. endif(UA_ENCODING_JSON)
  35. # gcov
  36. option(USE_GCOV "Enable gcov support" OFF)
  37. if(USE_GCOV)
  38. message(STATUS "Enabling gcov support")
  39. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
  40. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
  41. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
  42. endif()
  43. # directory for generated source files
  44. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  45. include_directories("${PROJECT_BINARY_DIR}/src_generated")
  46. # build the library
  47. configure_file("src/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  48. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
  49. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/util")
  50. set(lib_sources src/ua_types.c
  51. src/ua_types_encoding_binary.c
  52. src/ua_application.c
  53. src/ua_transport.c
  54. src/ua_transport_binary.c
  55. src/ua_transport_binary_secure.c
  56. src/ua_services_attribute.c
  57. src/ua_services_session.c
  58. src/ua_services_discovery.c
  59. src/ua_services_securechannel.c
  60. src/ua_services_nodemanagement.c
  61. src/ua_services_view.c
  62. src/ua_services_subscription.c
  63. src/ua_services_monitoreditems.c
  64. src/util/ua_util.c
  65. src/util/ua_list.c
  66. src/util/ua_indexedList.c
  67. src/util/ua_base64.c
  68. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  69. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.c)
  70. if(MULTITHREADING)
  71. list(APPEND lib_sources src/ua_namespace_concurrent.c)
  72. else()
  73. list(APPEND lib_sources src/ua_namespace.c)
  74. endif(MULTITHREADING)
  75. set(generate_src_options "")
  76. if(UA_ENCODING_XML)
  77. list(APPEND lib_sources src/ua_types_encoding_xml.c
  78. src/ua_namespace_xml.c
  79. src/ua_xml.c)
  80. set(generate_src_options "${generate_src_options}--with-xml")
  81. endif(UA_ENCODING_XML)
  82. if(UA_ENCODING_JSON)
  83. list(APPEND lib_sources src/ua_types_encoding_json.c)
  84. set(generate_src_options "${generate_src_options}--with-json")
  85. endif(UA_ENCODING_JSON)
  86. add_library(open62541 ${lib_sources})
  87. # generate data structures
  88. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  89. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  90. COMMAND python ${PROJECT_SOURCE_DIR}/tools/generate_builtin.py ${generate_src_options} ${PROJECT_SOURCE_DIR}/schema/Opc.Ua.Types.bsd ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated
  91. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_builtin.py
  92. ${CMAKE_CURRENT_SOURCE_DIR}/schema/Opc.Ua.Types.bsd)
  93. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.c
  94. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.h
  95. COMMAND python ${PROJECT_SOURCE_DIR}/tools/generate_namespace.py ${generate_src_options} ${PROJECT_SOURCE_DIR}/schema/NodeIds.csv ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0
  96. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_namespace.py
  97. ${CMAKE_CURRENT_SOURCE_DIR}/schema/NodeIds.csv)
  98. # download queue.h if required
  99. if(WIN32)
  100. if(NOT EXISTS "${PROJECT_BINARY_DIR}/src_generated/queue.h")
  101. file(DOWNLOAD "http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/~checkout~/src/sys/sys/queue.h" "${PROJECT_BINARY_DIR}/src_generated/queue.h" STATUS result)
  102. list(GET result 0 download_ok)
  103. if(NOT ${download_ok} MATCHES 0)
  104. file(REMOVE "${PROJECT_BINARY_DIR}/src_generated/queue.h") # remove empty file if created
  105. message(FATAL_ERROR "queue.h could not be downloaded")
  106. endif()
  107. endif()
  108. endif(WIN32)
  109. # build example implementations
  110. add_executable(exampleServer examples/src/opcuaServer.c
  111. examples/src/networklayer.c)
  112. target_link_libraries(exampleServer open62541)
  113. # generate documentation
  114. option(GENERATE_DOCUMENTATION "Generate doxygen documentation" OFF)
  115. if(GENERATE_DOCUMENTATION)
  116. find_package(Doxygen)
  117. if(NOT DOXYGEN_FOUND)
  118. message(FATAL_ERROR "Doxygen is not installed or not properly configured")
  119. endif(NOT DOXYGEN_FOUND)
  120. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  121. add_custom_target(doc
  122. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  123. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  124. COMMENT "Generating API documentation with Doxygen")
  125. endif(GENERATE_DOCUMENTATION)