CMakeLists.txt 8.6 KB

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