CMakeLists.txt 7.8 KB

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