CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. cmake_minimum_required(VERSION 3.5)
  2. project(gsd CXX)
  3. include(CheckIncludeFileCXX)
  4. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  5. # add_compile_options(-DRELEASE)
  6. check_include_file_cxx(any HAS_ANY)
  7. check_include_file_cxx(string_view HAS_STRING_VIEW)
  8. check_include_file_cxx(coroutine HAS_COROUTINE)
  9. if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
  10. # Do nothing
  11. elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
  12. set(CMAKE_CXX_STANDARD 20)
  13. elseif (HAS_ANY AND HAS_STRING_VIEW)
  14. set(CMAKE_CXX_STANDARD 17)
  15. else ()
  16. set(CMAKE_CXX_STANDARD 14)
  17. endif ()
  18. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. set(CMAKE_CXX_EXTENSIONS OFF)
  20. set(LINK_LIB_LIST "")
  21. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  22. #查找mysql是否安装
  23. find_package(MYSQL QUIET)
  24. if(MYSQL_FOUND AND ENABLE_MYSQL)
  25. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  26. include_directories(${MYSQL_INCLUDE_DIR})
  27. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  28. add_definitions(-DENABLE_MYSQL)
  29. list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
  30. endif()
  31. link_directories(/usr/local/lib)
  32. include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/)
  33. include_directories(${PROJECT_SOURCE_DIR}/3rdparty/CSerialPort/)
  34. include_directories(/usr/local/include/)
  35. include_directories(${PROJECT_SOURCE_DIR}/3rdparty/)
  36. include_directories(${PROJECT_SOURCE_DIR}/include/)
  37. include_directories(${PROJECT_SOURCE_DIR}/modules/)
  38. include_directories(${PROJECT_SOURCE_DIR}/plugins/)
  39. add_executable(${PROJECT_NAME} main.cc)
  40. # ##############################################################################
  41. # If you include the drogon source code locally in your project, use this method
  42. # to add drogon
  43. # add_subdirectory(drogon)
  44. # target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
  45. #
  46. # and comment out the following lines
  47. find_package(Drogon CONFIG REQUIRED)
  48. target_link_libraries(${PROJECT_NAME} Drogon::Drogon ZLToolKit ${LINK_LIB_LIST})
  49. # ##############################################################################
  50. if (CMAKE_CXX_STANDARD LESS 17)
  51. # With C++14, use boost to support any, string_view and filesystem
  52. message(STATUS "use c++14")
  53. find_package(Boost 1.61.0 REQUIRED)
  54. target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
  55. elseif (CMAKE_CXX_STANDARD LESS 20)
  56. message(STATUS "use c++17")
  57. else ()
  58. message(STATUS "use c++20")
  59. endif ()
  60. aux_source_directory(controllers CTL_SRC)
  61. aux_source_directory(filters FILTER_SRC)
  62. aux_source_directory(plugins PLUGIN_SRC)
  63. aux_source_directory(models MODEL_SRC)
  64. aux_source_directory(modules MODULE_SRC)
  65. drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
  66. ${CMAKE_CURRENT_BINARY_DIR})
  67. # use the following line to create views with namespaces.
  68. # drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
  69. # ${CMAKE_CURRENT_BINARY_DIR} TRUE)
  70. # use the following line to create views with namespace CHANGE_ME prefixed
  71. # and path namespaces.
  72. # drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views
  73. # ${CMAKE_CURRENT_BINARY_DIR} TRUE CHANGE_ME)
  74. target_include_directories(${PROJECT_NAME}
  75. PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
  76. ${CMAKE_CURRENT_SOURCE_DIR}/models /usr/local/lib/)
  77. target_sources(${PROJECT_NAME}
  78. PRIVATE
  79. ${SRC_DIR}
  80. ${CTL_SRC}
  81. ${FILTER_SRC}
  82. ${PLUGIN_SRC}
  83. ${MODEL_SRC}
  84. ${MODULE_SRC})
  85. # ##############################################################################
  86. # uncomment the following line for dynamically loading views
  87. # set_property(TARGET ${PROJECT_NAME} PROPERTY ENABLE_EXPORTS ON)
  88. # ##############################################################################
  89. add_subdirectory(test)