CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # Define the current source locations
  2. SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/leddevice)
  3. SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/leddevice)
  4. if ( ENABLE_DEV_NETWORK )
  5. find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network REQUIRED)
  6. endif()
  7. if ( ENABLE_DEV_SERIAL )
  8. find_package(Qt${QT_VERSION_MAJOR} COMPONENTS SerialPort REQUIRED)
  9. endif()
  10. include_directories(
  11. dev_hid
  12. dev_net
  13. dev_other
  14. dev_serial
  15. dev_spi
  16. dev_rpi_pwm
  17. dev_tinker
  18. )
  19. FILE ( GLOB Leddevice_SOURCES
  20. "${CURRENT_HEADER_DIR}/*.h"
  21. "${CURRENT_SOURCE_DIR}/*.h"
  22. "${CURRENT_SOURCE_DIR}/*.cpp"
  23. "${CURRENT_SOURCE_DIR}/dev_other/*.h"
  24. "${CURRENT_SOURCE_DIR}/dev_other/*.cpp"
  25. )
  26. if ( ENABLE_OSX OR WIN32 )
  27. list(REMOVE_ITEM Leddevice_SOURCES "${CURRENT_SOURCE_DIR}/dev_other/LedDevicePiBlaster.h")
  28. list(REMOVE_ITEM Leddevice_SOURCES "${CURRENT_SOURCE_DIR}/dev_other/LedDevicePiBlaster.cpp")
  29. endif()
  30. if ( ENABLE_DEV_NETWORK )
  31. FILE ( GLOB Leddevice_NETWORK_SOURCES "${CURRENT_SOURCE_DIR}/dev_net/*.h" "${CURRENT_SOURCE_DIR}/dev_net/*.cpp")
  32. endif()
  33. if ( ENABLE_DEV_SERIAL )
  34. FILE ( GLOB Leddevice_SERIAL_SOURCES "${CURRENT_SOURCE_DIR}/dev_serial/*.h" "${CURRENT_SOURCE_DIR}/dev_serial/*.cpp")
  35. endif()
  36. if ( ENABLE_DEV_SPI )
  37. FILE ( GLOB Leddevice_SPI_SOURCES "${CURRENT_SOURCE_DIR}/dev_spi/*.h" "${CURRENT_SOURCE_DIR}/dev_spi/*.cpp")
  38. endif()
  39. if ( ENABLE_DEV_TINKERFORGE )
  40. FILE ( GLOB Leddevice_TINKER_SOURCES "${CURRENT_SOURCE_DIR}/dev_tinker/*.h" "${CURRENT_SOURCE_DIR}/dev_tinker/*.cpp")
  41. endif()
  42. if ( ENABLE_DEV_USB_HID )
  43. find_package(libusb-1.0 REQUIRED)
  44. include_directories(
  45. ${CMAKE_SOURCE_DIR}/include/hidapi
  46. ${LIBUSB_1_INCLUDE_DIRS}
  47. )
  48. FILE ( GLOB Leddevice_USB_HID_SOURCES "${CURRENT_SOURCE_DIR}/dev_hid/*.h" "${CURRENT_SOURCE_DIR}/dev_hid/*.cpp")
  49. endif()
  50. if ( ENABLE_DEV_WS281XPWM )
  51. include_directories(../../dependencies/external/rpi_ws281x)
  52. FILE ( GLOB Leddevice_PWM_SOURCES "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.h" "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.cpp")
  53. endif()
  54. set(LedDevice_RESOURCES ${CURRENT_SOURCE_DIR}/LedDeviceSchemas.qrc )
  55. SET( Leddevice_SOURCES
  56. ${Leddevice_SOURCES}
  57. ${LedDevice_RESOURCES}
  58. ${Leddevice_NETWORK_SOURCES}
  59. ${Leddevice_PWM_SOURCES}
  60. ${Leddevice_SERIAL_SOURCES}
  61. ${Leddevice_SPI_SOURCES}
  62. ${Leddevice_TINKER_SOURCES}
  63. ${Leddevice_USB_HID_SOURCES}
  64. )
  65. # auto generate header file that include all available leddevice headers
  66. # auto generate cpp file for register() calls
  67. FILE ( WRITE "${CMAKE_BINARY_DIR}/LedDevice_headers.h" "#pragma once\n\n//this file is autogenerated, don't touch it\n\n" )
  68. FILE ( WRITE "${CMAKE_BINARY_DIR}/LedDevice_register.cpp" "//this file is autogenerated, don't touch it\n\n" )
  69. FOREACH( f ${Leddevice_SOURCES} )
  70. # MESSAGE (STATUS "Add led device: ${f}")
  71. if ( "${f}" MATCHES "dev_.*/Led.evice.+h$" )
  72. GET_FILENAME_COMPONENT(fname ${f} NAME)
  73. FILE ( APPEND "${CMAKE_BINARY_DIR}/LedDevice_headers.h" "#include \"${fname}\"\n" )
  74. STRING( SUBSTRING ${fname} 9 -1 dname)
  75. STRING( REPLACE ".h" "" dname "${dname}" )
  76. FILE ( APPEND "${CMAKE_BINARY_DIR}/LedDevice_register.cpp" "REGISTER(${dname});\n" )
  77. endif()
  78. ENDFOREACH()
  79. add_library(leddevice ${CMAKE_BINARY_DIR}/LedDevice_headers.h ${Leddevice_SOURCES} )
  80. target_link_libraries(leddevice
  81. hyperion
  82. hyperion-utils
  83. ${CMAKE_THREAD_LIBS_INIT}
  84. )
  85. if(WIN32)
  86. target_link_libraries(leddevice ws2_32)
  87. endif()
  88. if(ENABLE_DEV_NETWORK)
  89. target_link_libraries(leddevice Qt${QT_VERSION_MAJOR}::Network ssdp)
  90. if (NOT DEFAULT_USE_SYSTEM_MBEDTLS_LIBS)
  91. if (MBEDTLS_LIBRARIES)
  92. include_directories(${MBEDTLS_INCLUDE_DIR})
  93. target_link_libraries(leddevice ${MBEDTLS_LIBRARIES})
  94. target_include_directories(leddevice PRIVATE ${MBEDTLS_INCLUDE_DIR})
  95. endif (MBEDTLS_LIBRARIES)
  96. endif ()
  97. string(REGEX MATCH "[0-9]+|-([A-Za-z0-9_.]+)" MBEDTLS_MAJOR ${MBEDTLS_VERSION})
  98. if (MBEDTLS_MAJOR EQUAL "3")
  99. target_compile_definitions(leddevice PRIVATE USE_MBEDTLS3)
  100. if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  101. target_compile_features(leddevice PRIVATE cxx_std_20)
  102. endif()
  103. endif()
  104. endif()
  105. if(ENABLE_DEV_SERIAL)
  106. target_link_libraries(leddevice Qt${QT_VERSION_MAJOR}::SerialPort)
  107. endif()
  108. if(ENABLE_DEV_TINKERFORGE)
  109. target_link_libraries(leddevice tinkerforge)
  110. endif()
  111. if(ENABLE_DEV_WS281XPWM)
  112. target_link_libraries(leddevice ws281x)
  113. endif()
  114. if (ENABLE_DEV_USB_HID)
  115. if(APPLE)
  116. target_link_libraries(leddevice ${LIBUSB_1_LIBRARIES} hidapi-mac)
  117. else()
  118. target_link_libraries(leddevice ${LIBUSB_1_LIBRARIES} hidapi-libusb)
  119. endif()
  120. if(NOT WIN32)
  121. include(CheckCSourceCompiles)
  122. # Glibc compatibilty check
  123. check_c_source_compiles("
  124. #include <time.h>
  125. #include <sys/time.h>
  126. int main() {
  127. struct timespec t;
  128. return clock_gettime(CLOCK_REALTIME, &t);
  129. }
  130. " GLIBC_HAS_CLOCK_GETTIME)
  131. IF(NOT GLIBC_HAS_CLOCK_GETTIME)
  132. target_link_libraries(leddevice rt)
  133. endif()
  134. endif()
  135. endif()
  136. if(ENABLE_MDNS)
  137. target_link_libraries(leddevice mdns)
  138. endif()