CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. cmake_minimum_required(VERSION 2.6)
  2. # set(CMAKE_VERBOSE_MAKEFILE on )
  3. project(open62541)
  4. set(open62541_VERSION_MAJOR 0)
  5. set(open62541_VERSION_MINOR 1)
  6. # main sources of libopen62541
  7. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
  8. file(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
  9. file(GLOB generated_headers "${PROJECT_BINARY_DIR}/src_generated/*.h")
  10. set(lib_sources src/ua_types.c
  11. src/ua_types_encoding_binary.c
  12. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  13. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.c
  14. src/ua_transport.c
  15. src/ua_connection.c
  16. src/ua_securechannel.c
  17. src/ua_session.c
  18. src/util/ua_util.c
  19. src/util/ua_list.c
  20. src/util/ua_base64.c
  21. src/server/ua_server.c
  22. src/server/ua_securechannel_manager.c
  23. src/server/ua_session_manager.c
  24. src/server/ua_server_binary.c
  25. src/server/ua_services_attribute.c
  26. src/server/ua_services_session.c
  27. src/server/ua_services_discovery.c
  28. src/server/ua_services_securechannel.c
  29. src/server/ua_services_nodemanagement.c
  30. src/server/ua_services_view.c
  31. src/server/ua_services_subscription.c
  32. src/server/ua_services_monitoreditems.c
  33. ${headers}
  34. ${generated_headers})
  35. # compiler flags
  36. if(CMAKE_COMPILER_IS_GNUCC)
  37. add_definitions(-std=c99 -pedantic -pipe -fstack-protector -Wall -Wextra
  38. -Wno-unused-parameter -Wno-unused-function -Wno-unused-label
  39. -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar
  40. -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated
  41. -Wformat-security -Werror -ffunction-sections -fdata-sections
  42. -Wl,--gc-sections)
  43. if(WIN32)
  44. add_definitions(-fno-stack-protector)
  45. endif(WIN32)
  46. endif(CMAKE_COMPILER_IS_GNUCC)
  47. # build settings
  48. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules")
  49. set(generate_src_options) # the options for the tools that generate code from xml-schema definitions
  50. ## auto-generate all types or only the relevant subset?
  51. option(TYPES_ONLY_NEEDED "Include only compile-needed types" OFF)
  52. if(TYPES_ONLY_NEEDED)
  53. list(APPEND generate_src_options "--only-needed")
  54. endif(TYPES_ONLY_NEEDED)
  55. ## encodings
  56. set(UA_ENCODING_AMOUNT 1) # binary encoding
  57. ### xml
  58. option(ENABLE_XML_ENCODING "Enable XML-encoding of the UA types" OFF)
  59. if(ENABLE_XML_ENCODING)
  60. MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
  61. find_package(EXPAT REQUIRED)
  62. if(EXPAT_FOUND)
  63. include_directories(${EXPAT_INCLUDE_DIRS})
  64. else(EXPAT_FOUND)
  65. message(FATAL_ERROR "Expat library not found.")
  66. endif(EXPAT_FOUND)
  67. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/ongoing")
  68. list(APPEND lib_sources src/ongoing/ua_types_encoding_xml.c
  69. src/ongoing/ua_namespace_xml.c
  70. src/ongoing/ua_xml.c)
  71. list(APPEND generate_src_options "--with-xml")
  72. endif(ENABLE_XML_ENCODING)
  73. ### json
  74. option(ENABLE_JSON_ENCODING "Enable JSON-encoding of the UA types" OFF)
  75. if(ENABLE_JSON_ENCODING)
  76. MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
  77. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/ongoing")
  78. list(APPEND lib_sources src/ongoing/ua_types_encoding_json.c)
  79. list(APPEND generate_src_options "--with-json")
  80. endif(ENABLE_JSON_ENCODING)
  81. configure_file("src/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  82. ## multithreading
  83. option(ENABLE_MULTITHREADING "Enable multithreading" OFF)
  84. if(ENABLE_MULTITHREADING)
  85. find_package(Threads REQUIRED)
  86. list(APPEND lib_sources src/server/ua_nodestore_concurrent.c)
  87. else()
  88. list(APPEND lib_sources src/server/ua_nodestore.c)
  89. endif(ENABLE_MULTITHREADING)
  90. add_library(open62541 ${lib_sources}) # we can add more files to lib_sources later on
  91. ## logging
  92. set(UA_LOGLEVEL 400 CACHE STRING "Level at which logs shall be reported")
  93. ## coverage
  94. option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
  95. if(ENABLE_COVERAGE)
  96. message(STATUS "Enabling gcov support")
  97. set(CMAKE_BUILD_TYPE DEBUG)
  98. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  99. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  100. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  101. endif(ENABLE_COVERAGE)
  102. # build generated code
  103. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  104. include_directories("${PROJECT_BINARY_DIR}/src_generated")
  105. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  106. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  107. 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
  108. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_builtin.py
  109. ${CMAKE_CURRENT_SOURCE_DIR}/schema/Opc.Ua.Types.bsd)
  110. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.c
  111. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.h
  112. 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
  113. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_namespace.py
  114. ${CMAKE_CURRENT_SOURCE_DIR}/schema/NodeIds.csv)
  115. # build example server
  116. add_executable(exampleServer examples/opcuaServer.c
  117. examples/logger_stdout.c
  118. examples/networklayer_tcp.c)
  119. target_link_libraries(exampleServer open62541)
  120. if(WIN32)
  121. target_link_libraries(exampleServer ws2_32)
  122. endif(WIN32)
  123. if(ENABLE_MULTITHREADING)
  124. target_link_libraries(exampleServer urcu-cds urcu)
  125. endif(ENABLE_MULTITHREADING)
  126. # build unit tests
  127. option(ENABLE_UNIT_TESTS "Run unit tests after building" OFF)
  128. if(ENABLE_UNIT_TESTS)
  129. enable_testing()
  130. add_subdirectory(tests)
  131. endif(ENABLE_UNIT_TESTS)
  132. # build documentation
  133. option(GENERATE_DOCUMENTATION "Generate doxygen documentation" OFF)
  134. if(GENERATE_DOCUMENTATION)
  135. find_package(Doxygen)
  136. if(NOT DOXYGEN_FOUND)
  137. message(FATAL_ERROR "Doxygen is not installed or not properly configured")
  138. endif(NOT DOXYGEN_FOUND)
  139. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  140. add_custom_target(doc
  141. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  142. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  143. COMMENT "Generating API documentation with Doxygen")
  144. endif(GENERATE_DOCUMENTATION)
  145. # download queue.h if required
  146. if(WIN32)
  147. if(NOT EXISTS "${PROJECT_BINARY_DIR}/src_generated/queue.h")
  148. 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)
  149. list(GET result 0 download_ok)
  150. if(NOT ${download_ok} MATCHES 0)
  151. file(REMOVE "${PROJECT_BINARY_DIR}/src_generated/queue.h") # remove empty file if created
  152. message(FATAL_ERROR "queue.h could not be downloaded")
  153. endif()
  154. endif()
  155. endif(WIN32)
  156. # build api server specificaion
  157. #add_executable(api-design examples/api-design/server.c)
  158. #target_link_libraries(api-design open62541)
  159. #if(WIN32)
  160. # target_link_libraries(api-design ws2_32)
  161. #endif(WIN32)
  162. #if(MULTITHREADING)
  163. # target_link_libraries(api-design urcu-cds urcu)
  164. #endif(MULTITHREADING)