CMakeLists.txt 2.8 KB

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