CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
  2. message(FATAL_ERROR "Please create a separate directory for build files.")
  3. endif()
  4. cmake_minimum_required(VERSION 3.6)
  5. project(INS C CXX)
  6. set(CMAKE_VERBOSE_MAKEFILE OFF)
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  8. # ---[ Options
  9. option(build_modules "build modules" ON)
  10. # set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/source/bin/)
  11. if(build_modules)
  12. add_subdirectory(modules)
  13. endif()
  14. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  15. ##OpenCV
  16. if(WITH_OPENCV)
  17. if(CMAKE_TOOLCHAIN_FILE)
  18. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv)
  19. set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_flann)
  20. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/imgcodecs)
  21. list(APPEND OpenCV_LIBS opencv_imgcodecs)
  22. endif()
  23. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/videoio)
  24. list(APPEND OpenCV_LIBS opencv_videoio)
  25. endif()
  26. message(STATUS "HAVE_OPENCV enabled")
  27. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  28. set(HAVE_OPENCV true)
  29. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  30. else()
  31. set (HAVE_OPENCV false)
  32. endif()
  33. else()
  34. set(OpenCV_FIND_QUIETLY true)
  35. #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  36. find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
  37. find_package(OpenCV OPTIONAL_COMPONENTS videoio)
  38. set(optional_opencv_libs ${OpenCV_LIBS})
  39. find_package(OpenCV REQUIRED core imgproc highgui features2d)
  40. if(OpenCV_FOUND)
  41. if(imgcodecs_FOUND)
  42. list(APPEND OpenCV_LIBS optional_opencv_libs)
  43. endif()
  44. message(STATUS "HAVE_OPENCV enabled")
  45. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  46. set(HAVE_OPENCV true)
  47. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  48. else()
  49. set (HAVE_OPENCV false)
  50. endif()
  51. endif()
  52. else()
  53. set (HAVE_OPENCV false)
  54. endif()
  55. #查找mysql是否安装
  56. find_package(MYSQL QUIET)
  57. if(MYSQL_FOUND AND ENABLE_MYSQL)
  58. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  59. include_directories(${MYSQL_INCLUDE_DIR})
  60. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  61. add_definitions(-DENABLE_MYSQL)
  62. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  63. endif()
  64. include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/)
  65. include_directories(/usr/local/include/hv)
  66. include_directories(${PROJECT_SOURCE_DIR}/modules/ProcessingIt/include/)
  67. include_directories(${PROJECT_SOURCE_DIR}/modules/GetCenter/include/)
  68. include_directories(${PROJECT_SOURCE_DIR}/modules/TaskCenter/include/)
  69. include_directories(${PROJECT_SOURCE_DIR}/modules/Disposition/include/)
  70. include_directories(${PROJECT_SOURCE_DIR}/framework/core/include/)
  71. include_directories(${PROJECT_SOURCE_DIR}/framework/dataType/include/)
  72. add_subdirectory(${PROJECT_SOURCE_DIR}/framework)
  73. # 寻找当前目录下所有源文件
  74. aux_source_directory(./source/src DIR_SRCS)
  75. add_compile_options(-Wall -std=c++11 -O2 -g)
  76. link_directories(${PROJECT_SOURCE_DIR}/lib)
  77. link_directories(/usr/local/lib)
  78. list(APPEND ALL_LINKER_LIBS mk_api ZLToolKit dl ${3RDPARTY_LIBS} ${OpenCV_LIBS} pthread hv ins_core ins_va)
  79. # 指定生成的目标
  80. add_executable(main ${DIR_SRCS})
  81. # 链接
  82. target_link_libraries(main ${ALL_LINKER_LIBS})