CMakeLists.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ocv_install_example_src(cpp *.cpp *.hpp CMakeLists.txt)
  2. set(OPENCV_CPP_SAMPLES_REQUIRED_DEPS
  3. opencv_core
  4. opencv_imgproc
  5. opencv_flann
  6. opencv_imgcodecs
  7. opencv_videoio
  8. opencv_highgui
  9. opencv_ml
  10. opencv_video
  11. opencv_objdetect
  12. opencv_photo
  13. opencv_features2d
  14. opencv_calib3d
  15. opencv_stitching
  16. opencv_dnn
  17. opencv_gapi
  18. ${OPENCV_MODULES_PUBLIC}
  19. ${OpenCV_LIB_COMPONENTS})
  20. ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
  21. if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND)
  22. return()
  23. endif()
  24. set(DEPS_example_snippet_imgproc_segmentation opencv_core opencv_imgproc)
  25. set(DEPS_example_cpp_intelligent_scissors opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui)
  26. project(cpp_samples)
  27. ocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
  28. file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
  29. if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters)
  30. ocv_list_filterout(cpp_samples "/gpu/")
  31. endif()
  32. ocv_list_filterout(cpp_samples "real_time_pose_estimation/")
  33. ocv_list_filterout(cpp_samples "parallel_backend/")
  34. foreach(sample_filename ${cpp_samples})
  35. set(package "cpp")
  36. if(sample_filename MATCHES "tutorial_code/snippet")
  37. set(package "snippet")
  38. elseif(sample_filename MATCHES "tutorial_code")
  39. set(package "tutorial")
  40. endif()
  41. ocv_define_sample(tgt ${sample_filename} ${package})
  42. set(deps ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
  43. if(DEFINED DEPS_${tgt})
  44. set(deps ${DEPS_${tgt}})
  45. endif()
  46. ocv_target_link_libraries(${tgt} PRIVATE ${OPENCV_LINKER_LIBS} ${deps})
  47. if(sample_filename MATCHES "/gpu/" AND HAVE_opencv_cudaarithm AND HAVE_opencv_cuda_filters)
  48. ocv_target_link_libraries(${tgt} PRIVATE opencv_cudaarithm opencv_cudafilters)
  49. endif()
  50. if(sample_filename MATCHES "/viz/")
  51. ocv_target_link_libraries(${tgt} PRIVATE ${VTK_LIBRARIES})
  52. target_compile_definitions(${tgt} PRIVATE -DUSE_VTK)
  53. endif()
  54. if(HAVE_OPENGL AND sample_filename MATCHES "detect_mser")
  55. target_compile_definitions(${tgt} PRIVATE HAVE_OPENGL)
  56. ocv_target_link_libraries(${tgt} PRIVATE "${OPENGL_LIBRARIES}")
  57. endif()
  58. if(sample_filename MATCHES "simd_")
  59. # disabled intentionally - demonstration purposes only
  60. #target_include_directories(${tgt} PRIVATE "${CMAKE_CURRENT_LIST_DIR}")
  61. #target_compile_definitions(${tgt} PRIVATE OPENCV_SIMD_CONFIG_HEADER=opencv_simd_config_custom.hpp)
  62. #target_compile_definitions(${tgt} PRIVATE OPENCV_SIMD_CONFIG_INCLUDE_DIR=1)
  63. #target_compile_options(${tgt} PRIVATE -mavx2)
  64. endif()
  65. endforeach()
  66. include("tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt" OPTIONAL)
  67. # Standalone samples only
  68. if(OpenCV_FOUND AND NOT CMAKE_VERSION VERSION_LESS "3.1")
  69. add_subdirectory("example_cmake")
  70. endif()
  71. if(OpenCV_FOUND AND NOT CMAKE_VERSION VERSION_LESS "3.9"
  72. AND NOT OPENCV_EXAMPLES_SKIP_PARALLEL_BACKEND
  73. )
  74. add_subdirectory("tutorial_code/core/parallel_backend")
  75. endif()