CMakeLists.txt 9.1 KB

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