CMakeLists.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. ## self-signed certificates
  51. option(ENABLE_SELFSIGNED "Enable self-signed certificates" OFF)
  52. if(ENABLE_SELFSIGNED)
  53. message(STATUS "Enabling self-signed certificates")
  54. SET(lib_sources ${lib_sources} ${PROJECT_BINARY_DIR}/localhost.der ${PROJECT_BINARY_DIR}/ca.crt)
  55. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/localhost.der
  56. ${PROJECT_BINARY_DIR}/ca.crt
  57. COMMAND python ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${PROJECT_BINARY_DIR}
  58. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/create_self-signed.py
  59. ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/localhost.cnf)
  60. endif(ENABLE_SELFSIGNED)
  61. ## auto-generate all types or only the relevant subset?
  62. option(TYPES_ONLY_NEEDED "Include only compile-needed types" OFF)
  63. if(TYPES_ONLY_NEEDED)
  64. list(APPEND generate_src_options "--only-needed")
  65. endif(TYPES_ONLY_NEEDED)
  66. ## encodings
  67. set(UA_ENCODING_AMOUNT 1) # binary encoding
  68. ### xml
  69. option(ENABLE_XML_ENCODING "Enable XML-encoding of the UA types" OFF)
  70. if(ENABLE_XML_ENCODING)
  71. MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
  72. find_package(EXPAT REQUIRED)
  73. if(EXPAT_FOUND)
  74. include_directories(${EXPAT_INCLUDE_DIRS})
  75. else(EXPAT_FOUND)
  76. message(FATAL_ERROR "Expat library not found.")
  77. endif(EXPAT_FOUND)
  78. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/ongoing")
  79. list(APPEND lib_sources src/ongoing/ua_types_encoding_xml.c
  80. src/ongoing/ua_namespace_xml.c
  81. src/ongoing/ua_xml.c)
  82. list(APPEND generate_src_options "--with-xml")
  83. endif(ENABLE_XML_ENCODING)
  84. ### json
  85. option(ENABLE_JSON_ENCODING "Enable JSON-encoding of the UA types" OFF)
  86. if(ENABLE_JSON_ENCODING)
  87. MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
  88. include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/ongoing")
  89. list(APPEND lib_sources src/ongoing/ua_types_encoding_json.c)
  90. list(APPEND generate_src_options "--with-json")
  91. endif(ENABLE_JSON_ENCODING)
  92. ## multithreading
  93. option(ENABLE_MULTITHREADING "Enable multithreading" OFF)
  94. if(ENABLE_MULTITHREADING)
  95. find_package(Threads REQUIRED)
  96. list(APPEND lib_sources src/server/ua_nodestore_concurrent.c)
  97. else()
  98. list(APPEND lib_sources src/server/ua_nodestore.c)
  99. endif(ENABLE_MULTITHREADING)
  100. add_library(open62541 ${lib_sources}) # we can add more files to lib_sources later on
  101. ## logging
  102. set(UA_LOGLEVEL 400 CACHE STRING "Level at which logs shall be reported")
  103. ## coverage
  104. option(ENABLE_COVERAGE "Enable gcov coverage" OFF)
  105. if(ENABLE_COVERAGE)
  106. message(STATUS "Enabling gcov support")
  107. set(CMAKE_BUILD_TYPE DEBUG)
  108. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  109. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  110. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
  111. endif(ENABLE_COVERAGE)
  112. configure_file("src/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
  113. # build generated code
  114. file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/src_generated")
  115. include_directories("${PROJECT_BINARY_DIR}/src_generated")
  116. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
  117. ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
  118. 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
  119. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_builtin.py
  120. ${CMAKE_CURRENT_SOURCE_DIR}/schema/Opc.Ua.Types.bsd)
  121. add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.c
  122. ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.h
  123. 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
  124. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_namespace.py
  125. ${CMAKE_CURRENT_SOURCE_DIR}/schema/NodeIds.csv)
  126. # build example server
  127. add_executable(exampleServer examples/opcuaServer.c
  128. examples/logger_stdout.c
  129. examples/networklayer_tcp.c)
  130. target_link_libraries(exampleServer open62541)
  131. if(WIN32)
  132. target_link_libraries(exampleServer ws2_32)
  133. endif(WIN32)
  134. if(ENABLE_MULTITHREADING)
  135. target_link_libraries(exampleServer urcu-cds urcu)
  136. endif(ENABLE_MULTITHREADING)
  137. # build unit tests
  138. option(ENABLE_UNIT_TESTS "Run unit tests after building" OFF)
  139. if(ENABLE_UNIT_TESTS)
  140. enable_testing()
  141. add_subdirectory(tests)
  142. endif(ENABLE_UNIT_TESTS)
  143. # build documentation
  144. option(GENERATE_DOCUMENTATION "Generate doxygen documentation" OFF)
  145. if(GENERATE_DOCUMENTATION)
  146. find_package(Doxygen)
  147. if(NOT DOXYGEN_FOUND)
  148. message(FATAL_ERROR "Doxygen is not installed or not properly configured")
  149. endif(NOT DOXYGEN_FOUND)
  150. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  151. add_custom_target(doc
  152. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  153. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  154. COMMENT "Generating API documentation with Doxygen")
  155. endif(GENERATE_DOCUMENTATION)
  156. # download queue.h if required
  157. if(WIN32)
  158. if(NOT EXISTS "${PROJECT_BINARY_DIR}/src_generated/queue.h")
  159. 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)
  160. list(GET result 0 download_ok)
  161. if(NOT ${download_ok} MATCHES 0)
  162. file(REMOVE "${PROJECT_BINARY_DIR}/src_generated/queue.h") # remove empty file if created
  163. message(FATAL_ERROR "queue.h could not be downloaded")
  164. endif()
  165. endif()
  166. endif(WIN32)
  167. # build api server specificaion
  168. #add_executable(api-design examples/api-design/server.c)
  169. #target_link_libraries(api-design open62541)
  170. #if(WIN32)
  171. # target_link_libraries(api-design ws2_32)
  172. #endif(WIN32)
  173. #if(MULTITHREADING)
  174. # target_link_libraries(api-design urcu-cds urcu)
  175. #endif(MULTITHREADING)