CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. cmake_minimum_required(VERSION 3.0)
  2. # automagically detect if we should cross-compile
  3. if(DEFINED ENV{TOOLCHAIN})
  4. set(CMAKE_C_COMPILER $ENV{TOOLCHAIN}gcc)
  5. set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN}g++)
  6. set(CMAKE_AR "$ENV{TOOLCHAIN}ar" CACHE FILEPATH "CW archiver" FORCE)
  7. endif()
  8. project(lib60870-C)
  9. ENABLE_TESTING()
  10. set(LIB_VERSION_MAJOR "2")
  11. set(LIB_VERSION_MINOR "3")
  12. set(LIB_VERSION_PATCH "2")
  13. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/third_party/cmake/modules/")
  14. macro(ADD_C_FLAGS flags)
  15. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flags}")
  16. endmacro()
  17. # feature checks
  18. include(CheckLibraryExists)
  19. check_library_exists(rt clock_gettime "time.h" CONFIG_SYSTEM_HAS_CLOCK_GETTIME)
  20. # check if we are on a little or a big endian
  21. include (TestBigEndian)
  22. test_big_endian(PLATFORM_IS_BIGENDIAN)
  23. option(BUILD_HAL "Build the platform abstraction layer (HAL)" ON)
  24. option(BUILD_COMMON "Build common code (shared with other libraries - e.g. libiec61850)" ON)
  25. option(BUILD_EXAMPLES "Build the examples" ON)
  26. option(BUILD_TESTS "Build the tests" ON)
  27. if(BUILD_HAL)
  28. if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28)
  29. set(WITH_MBEDTLS 1)
  30. else()
  31. message("NOTE: mbedtls 2.28 is required for TLS support!")
  32. endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28)
  33. endif(BUILD_HAL)
  34. include_directories(
  35. ${CMAKE_CURRENT_LIST_DIR}/config
  36. ${CMAKE_CURRENT_LIST_DIR}/src/file-service
  37. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api
  38. ${CMAKE_CURRENT_LIST_DIR}/src/inc/internal
  39. ${CMAKE_CURRENT_LIST_DIR}/src/common/inc
  40. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc
  41. )
  42. if(WITH_MBEDTLS)
  43. include_directories(
  44. ${CMAKE_CURRENT_LIST_DIR}/src/hal/tls/mbedtls
  45. ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28/include
  46. )
  47. file(GLOB tls_SRCS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28/library/*.c)
  48. add_definitions(-DCONFIG_CS104_SUPPORT_TLS=1)
  49. add_definitions(-DMBEDTLS_CONFIG_FILE="mbedtls_config.h")
  50. endif(WITH_MBEDTLS)
  51. set(API_HEADERS
  52. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_time.h
  53. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_thread.h
  54. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_socket.h
  55. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_serial.h
  56. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_base.h
  57. ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/tls_config.h
  58. ${CMAKE_CURRENT_LIST_DIR}/src/common/inc/linked_list.h
  59. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_master.h
  60. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_slave.h
  61. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs104_slave.h
  62. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/iec60870_master.h
  63. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/iec60870_slave.h
  64. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/iec60870_common.h
  65. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_information_objects.h
  66. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs104_connection.h
  67. ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/link_layer_parameters.h
  68. ${CMAKE_CURRENT_LIST_DIR}/src/file-service/cs101_file_service.h
  69. )
  70. include(CheckCCompilerFlag)
  71. check_c_compiler_flag("-Wredundant-decls" SUPPORT_REDUNDANT_DECLS)
  72. if (SUPPORT_REDUNDANT_DECLS)
  73. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls")
  74. endif(SUPPORT_REDUNDANT_DECLS)
  75. # write the detected stuff to this file
  76. # configure_file(config/lib60870_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config/lib60870_config.h)
  77. if(BUILD_EXAMPLES)
  78. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples)
  79. endif(BUILD_EXAMPLES)
  80. if(BUILD_TESTS)
  81. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests)
  82. endif(BUILD_TESTS)
  83. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src)
  84. INSTALL(FILES ${API_HEADERS} DESTINATION include/lib60870 COMPONENT Development)
  85. IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
  86. INCLUDE(InstallRequiredSystemLibraries)
  87. SET(CPACK_PACKAGE_DESCRIPTION "IEC 60870-5-101/104 master/slave library")
  88. SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IEC 60870-5-101/104 master/slave library")
  89. SET(CPACK_PACKAGE_VENDOR "MZ Automation GmbH")
  90. SET(CPACK_PACKAGE_CONTACT "info@mz-automation.de")
  91. SET(CPACK_PACKAGE_VERSION_MAJOR "${LIB_VERSION_MAJOR}")
  92. SET(CPACK_PACKAGE_VERSION_MINOR "${LIB_VERSION_MINOR}")
  93. SET(CPACK_PACKAGE_VERSION_PATCH "${LIB_VERSION_PATCH}")
  94. SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}_${CMAKE_SYSTEM_PROCESSOR}")
  95. SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
  96. SET(CPACK_COMPONENTS_ALL Libraries Development Applications)
  97. #set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_PROJECT_NAME}")
  98. INCLUDE(CPack)
  99. ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")