CMakeLists.txt 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if(build_modules)
  11. add_subdirectory(modules)
  12. endif()
  13. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  14. ##OpenCV
  15. if(WITH_OPENCV)
  16. if(CMAKE_TOOLCHAIN_FILE)
  17. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv)
  18. set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_flann)
  19. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/imgcodecs)
  20. list(APPEND OpenCV_LIBS opencv_imgcodecs)
  21. endif()
  22. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/videoio)
  23. list(APPEND OpenCV_LIBS opencv_videoio)
  24. endif()
  25. message(STATUS "HAVE_OPENCV enabled")
  26. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  27. set(HAVE_OPENCV true)
  28. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  29. else()
  30. set (HAVE_OPENCV false)
  31. endif()
  32. else()
  33. set(OpenCV_FIND_QUIETLY true)
  34. #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  35. find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
  36. find_package(OpenCV OPTIONAL_COMPONENTS videoio)
  37. set(optional_opencv_libs ${OpenCV_LIBS})
  38. find_package(OpenCV REQUIRED core imgproc highgui features2d)
  39. if(OpenCV_FOUND)
  40. if(imgcodecs_FOUND)
  41. list(APPEND OpenCV_LIBS optional_opencv_libs)
  42. endif()
  43. message(STATUS "HAVE_OPENCV enabled")
  44. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  45. set(HAVE_OPENCV true)
  46. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  47. else()
  48. set (HAVE_OPENCV false)
  49. endif()
  50. endif()
  51. else()
  52. set (HAVE_OPENCV false)
  53. endif()
  54. #查找mysql是否安装
  55. find_package(MYSQL QUIET)
  56. if(MYSQL_FOUND AND ENABLE_MYSQL)
  57. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  58. include_directories(${MYSQL_INCLUDE_DIR})
  59. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  60. add_definitions(-DENABLE_MYSQL)
  61. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  62. endif()
  63. add_subdirectory(${PROJECT_SOURCE_DIR}/framework)
  64. add_subdirectory(${PROJECT_SOURCE_DIR}/source/)
  65. # # 寻找当前目录下所有源文件
  66. # aux_source_directory(./source/src DIR_SRCS)
  67. # add_compile_options(-Wall -std=c++11 -O2 -g)
  68. # link_directories(${PROJECT_SOURCE_DIR}/lib)
  69. # link_directories(/usr/local/lib)
  70. # list(APPEND ALL_LINKER_LIBS mk_api ZLToolKit dl ${3RDPARTY_LIBS} ${OpenCV_LIBS} pthread hv ins_core ins_va)
  71. # # 指定生成的目标
  72. # add_executable(main ${DIR_SRCS})
  73. # # 链接
  74. # target_link_libraries(main ${ALL_LINKER_LIBS})