CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. cmake_minimum_required(VERSION 3.5)
  2. project(PLCRegistrationTool VERSION 0.1 LANGUAGES CXX)
  3. set(CMAKE_AUTOUIC ON)
  4. set(CMAKE_AUTOMOC ON)
  5. set(CMAKE_AUTORCC ON)
  6. set(CMAKE_CXX_STANDARD 17)
  7. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  8. execute_process(COMMAND bash ${PROJECT_SOURCE_DIR}/proto.sh ${PROJECT_SOURCE_DIR})
  9. add_definitions(-DETC_PATH="${PROJECT_SOURCE_DIR}")
  10. find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
  11. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
  12. find_package(Protobuf REQUIRED)
  13. include_directories(
  14. /usr/local/include/snap7
  15. ${PROJECT_SOURCE_DIR}/include
  16. ${PROJECT_SOURCE_DIR}/include/plc
  17. )
  18. # Don't search with REQUIRED as we can continue without gflags.
  19. find_package(gflags 2.2.0)
  20. if (gflags_FOUND)
  21. if (TARGET gflags)
  22. message("-- Found Google Flags (gflags) version ${gflags_VERSION}: ${gflags_DIR}")
  23. message("-- Found Google Flags (gflags) version ${gflags_VERSION}: ${GFLAGS_LIBRARIES}")
  24. else()
  25. message("-- Detected version of gflags: ${gflags_VERSION} does not define "
  26. "expected gflags CMake target which should be exported by gflags 2.2+. "
  27. "Building without gflags.")
  28. update_cache_variable(GFLAGS OFF)
  29. endif()
  30. else (gflags_FOUND)
  31. message("-- Did not find Google Flags (gflags), Building without gflags.")
  32. update_cache_variable(GFLAGS OFF)
  33. endif (gflags_FOUND)
  34. find_package(glog REQUIRED)
  35. aux_source_directory(${PROJECT_SOURCE_DIR}/include/plc PLC_SRC)
  36. aux_source_directory(${PROJECT_SOURCE_DIR}/include/tool TOOL_SRC)
  37. aux_source_directory(${PROJECT_SOURCE_DIR}/include/json JSON_SRC)
  38. set(PROJECT_SOURCES
  39. main.cpp
  40. mainwindow.cpp
  41. mainwindow.h
  42. mainwindow.ui
  43. proto_tool.cpp
  44. proto_tool.h
  45. velodyne_config.pb.h
  46. velodyne_config.pb.cc
  47. ${TOOL_SRC}
  48. ${PLC_SRC}
  49. ${JSON_SRC}
  50. )
  51. if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
  52. qt_add_executable(PLCRegistrationTool
  53. MANUAL_FINALIZATION
  54. ${PROJECT_SOURCES}
  55. )
  56. # Define target properties for Android with Qt 6 as:
  57. # set_property(TARGET PLCRegistrationTool APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
  58. # ${CMAKE_CURRENT_SOURCE_DIR}/android)
  59. # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
  60. else()
  61. if(ANDROID)
  62. add_library(PLCRegistrationTool SHARED
  63. ${PROJECT_SOURCES}
  64. )
  65. # Define properties for Android with Qt 5 after find_package() calls as:
  66. # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
  67. else()
  68. add_executable(PLCRegistrationTool
  69. ${PROJECT_SOURCES}
  70. )
  71. endif()
  72. endif()
  73. target_link_libraries(PLCRegistrationTool PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
  74. ${PROTOBUF_LIBRARIES}
  75. -lgflags
  76. glog::glog
  77. snap7
  78. )
  79. set_target_properties(PLCRegistrationTool PROPERTIES
  80. MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
  81. MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
  82. MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
  83. MACOSX_BUNDLE TRUE
  84. WIN32_EXECUTABLE TRUE
  85. )
  86. install(TARGETS PLCRegistrationTool
  87. BUNDLE DESTINATION .
  88. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  89. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  90. )
  91. if(QT_VERSION_MAJOR EQUAL 6)
  92. qt_finalize_executable(PCLRegistrationTool)
  93. endif()