CMakeLists.txt 7.9 KB

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