CMakeLists.txt 6.5 KB

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